Skip to content

Instantly share code, notes, and snippets.

View Nilzor's full-sized avatar

Frode Nilsen Nilzor

  • Forse.no
  • Oslo, Norway
View GitHub Profile
@Nilzor
Nilzor / GenericFactoryPatternExample.cs
Created June 28, 2012 15:45
Generic Factory Example
using System;
using System.Collections.Generic;
namespace GenericFactoryPatternExample
{
public class MainClass
{
// Example of using a service locator to get the correct factory for
// a given object type.
public static void Main()
@Nilzor
Nilzor / UsefulBindingAdapters.kt
Last active August 29, 2022 19:22
Useful binding adapters
object GeneralBindingAdapters {
/**
* To allow binding image resource Int in addition to Drawable.
* Saves you from depending on Resouces in the ViewModel,
*/
@JvmStatic
@BindingAdapter("android:src")
fun setImageResource(imageView: ImageView, resource: Int) {
imageView.setImageResource(resource)
@Nilzor
Nilzor / GridLayoutSquares.xml
Created January 25, 2013 10:26
Grid Layout 2x2 attempt equal sized, screen-filling attempt
<?xml version="1.0" encoding="utf-8"?>
<!-- REMEMBER TO UPDATE BOTH LANDSCAPE AND PORTRAIT FILES -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Setting up GridLayout support library in IntelliJ: http://stackoverflow.com/questions/12468606/intellij-and-android-support-v7-widget-gridlayout -->
<android.support.v7.widget.GridLayout
android:layout_width="match_parent"
@Nilzor
Nilzor / build.gradle
Created June 19, 2021 06:20
Temp build.gradle matrix plugin
buildscript {
repositories {
mavenCentral()
jcenter()
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
id 'org.jetbrains.intellij' version '1.0'
@Nilzor
Nilzor / attempt_onclick.kt
Created June 16, 2021 13:58
Attempt at bindingconverter
@BindingConversion
@JvmStatic
fun konverto1(action: (() -> Unit)?) : View.OnClickListener? {
return View.OnClickListener { action?.invoke() }
}
@Nilzor
Nilzor / TwoWayBoundString.java
Created January 31, 2016 10:25
Tow-way data bound string, based on Blog by Fabio Colini
import android.databinding.BaseObservable;
import android.databinding.BindingAdapter;
import android.databinding.BindingConversion;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import java.io.Serializable;
@Nilzor
Nilzor / ContentTypeInterceptor.kt
Last active June 19, 2020 12:02
An OkHttp interceptor allowing you to override Content-Type for POST, PUT and PATCH requests
/**
* Overrides the HTTP Header Content-Type for POST, PATCH and PUT calls to the given [contentType]
*/
class ContentTypeInterceptor(private val contentType: String) : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val chainBuilder = request.newBuilder()
request.body()?.let {
val newBody = ForwardingRequestbody(it, contentType)
when (request.method()) {
@Nilzor
Nilzor / ToothpickTest.kt
Created June 3, 2020 19:03
Toothpick overriding and stuff
package no.ruter.sales.utils
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.core.IsInstanceOf
import org.junit.Test
import toothpick.Scope
import toothpick.Toothpick
import toothpick.config.Module
import toothpick.ktp.binding.bind
import toothpick.ktp.binding.module
@Nilzor
Nilzor / databinderror.txt
Last active May 17, 2020 05:12
Databind error
import com.myapp.shared.databinding.FragmentSaleProductBindingImpl;
^
symbol: class FragmentSaleProductBindingImpl
^
warning Binding adapter AK(android.widget.ImageView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBindingAdapter.Companion#setIdleCardImage with com.myapp.shared.bindingadapters.ValidatorBindingAdapter#setIdleCardImage
warning Binding adapter AK(android.widget.ImageView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBindingAdapter.Companion#setIdleCardImage with com.myapp.shared.bindingadapters.ValidatorBindingAdapter#setIdleCardImage
warning Binding adapter AK(android.widget.TextView, com.myapp.shared.model.viewmodel.overview.ConnectivityState) already exists for connectivityState! Overriding com.myapp.shared.bindingadapters.ValidatorBin
@Nilzor
Nilzor / BuyTicketButton.kt
Created April 23, 2020 06:14
DAtabinding to custom prop
class BuyTicketButton(context: Context, attrs: AttributeSet?) : FrameLayout(context, attrs) {
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : this(context, attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : this(context, attrs)
init {
val view = LayoutInflater.from(context)!!.inflate(R.layout.button_ticket, this, true)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.BuyTicketButton)
val imageSrc = attributes.getResourceId(R.styleable.BuyTicketButton_imageSrc, 0)