This file contains hidden or 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
class DelegatedPreference<T>(val context: Context, val default: T) : ReadWriteProperty<Any, T> { | |
override fun getValue(thisRef: Any, property: KProperty<*>): T { | |
return context.defaultSharedPreferences.run { | |
when (default) { | |
is String -> getString(property.name, default) | |
is Long -> getLong(property.name, default) | |
is Int -> getInt(property.name, default) | |
is Boolean -> getBoolean(property.name, default) |
This file contains hidden or 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
class LifecycleGetter<T : View>(var lifecycleOwner: LifecycleOwner, var view: T) | |
fun <T : View> T.observe(lifecycleOwner: LifecycleOwner): LifecycleGetter<T> { | |
return LifecycleGetter(lifecycleOwner, this) | |
} | |
fun <T : TextView> LifecycleGetter<T>.liveText(liveData: LiveData<String>): LifecycleGetter<T> { | |
liveData.observe(lifecycleOwner, Observer { | |
this.view.text = it | |
}) |
This file contains hidden or 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 <V : View> V.alpha(alpha: Double): V { | |
this.alpha = alpha.toFloat() | |
return this | |
} | |
inline fun <V : View> V.backgroundColor(color: Int): V { | |
backgroundColor = color | |
return this | |
} |
This file contains hidden or 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
class User : HashMappable() { | |
var name: String by HashMappableProperty("") | |
var age: Int? by HashMappableProperty(null) | |
} | |
fun main() { | |
val harry = User() | |
harry.name = "Harry" |
This file contains hidden or 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
fun test() { | |
class City(var name: String, var location: GeoPoint) | |
var query = FirebaseFirestore.getInstance().collection("city").limit(10) | |
var error : (Exception) -> Unit = { it.printStackTrace() } | |
query.query<City>(callbackWithKey = { keyList, cityList -> }, error = error) | |
query.query(callback = { documentSnapshotList -> }, error = error) | |
query.addChangeListener(isAdded = {}, isRemoved = {}, isModified = {}, error = error) |
This file contains hidden or 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
abstract class AnkoRecyclerViewAdapter<Model : Any, AnkoView : AnkoComponent<ViewGroup>, ViewHolder : RecyclerView.ViewHolder> : RecyclerView.Adapter<ViewHolder>() { | |
abstract val data: List<Model> // Data list | |
abstract val ankoView: AnkoView // Layout as AnkoComponent<ViewGroup> | |
abstract fun ViewHolder.setup(model: Model) // setup model from ViewHolder | |
abstract val onItemClickListenerUnit: (Model) -> Unit // Item Click Listener | |
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | |
holder.setup(data[position]) | |
holder.itemView.setOnClickListener { |
NewerOlder