This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol LocalizedText { | |
func asLocalizedText() -> String | |
} | |
protocol TextKey : LocalizedText { | |
var key: String { get } | |
} | |
extension TextKey { | |
func asLocalizedText() -> String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T> Any.takeAs(): T? = this as? T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |