Skip to content

Instantly share code, notes, and snippets.

View nullptr2this's full-sized avatar

Jon Cobb nullptr2this

View GitHub Profile
@nullptr2this
nullptr2this / view-binding-holder.txt
Last active May 3, 2022 18:36
View Binding Holder for Fragments
import android.view.View
import androidx.viewbinding.ViewBinding
/**
* Creates a [ViewBindingHolder] with the given [ViewBinding] factory to
* act as an accessor to the [ViewBinding].
*
* ```
* class MyFragment : Fragment(R.layout.fragment_mine) {
*
@nullptr2this
nullptr2this / TextKey.swift
Created August 11, 2020 18:40
Type safe text keys for localizable strings files
protocol LocalizedText {
func asLocalizedText() -> String
}
protocol TextKey : LocalizedText {
var key: String { get }
}
extension TextKey {
func asLocalizedText() -> String {
@nullptr2this
nullptr2this / KotlinExt.kt
Last active July 24, 2020 17:36
Basic Kotlin Extensions
inline fun <reified T> Any.takeAs(): T? = this as? T
@nullptr2this
nullptr2this / MvRxAsyncStateHandling.kt
Last active July 31, 2020 19:39
Simple Async<T> state handling for MvRx
//Any.takeAs() found in KotlinExt.kt gist
inline fun <T> Async<T>.doOnUninitialized(block: () -> Unit): Async<T> =
takeAs<Uninitialized>()?.also { block() } ?: this
inline fun <T> Async<T>.doOnLoading(block: () -> Unit): Async<T> =
takeAs<Loading<T>>()?.also { block() } ?: this
inline fun <T> Async<T>.doOnSuccess(block: (T) -> Unit): Async<T> =
takeAs<Success<T>>()?.also { block(it()) } ?: this