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 <T> LifecycleOwner.lifecycleAwareLazy(initializer: () -> T): Lazy<T> = LifecycleAwareLazy(this, initializer) | |
| private object UninitializedValue | |
| class LifecycleAwareLazy<out T>( | |
| private val owner: LifecycleOwner, | |
| initializer: () -> T | |
| ) : Lazy<T>, Serializable, LifecycleObserver { | |
| private var initializer: (() -> T)? = initializer |
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 MainActivity { | |
| // ... | |
| private val viewModel by viewModels { viewModelFactory } | |
| private lateinit var adapter: DataBindingAdapter | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) |
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 debugSubscribeOn(): Disposable = | |
| Observable.just(1) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } | |
| .subscribeOn(Schedulers.io()) | |
| .flatMap { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| Observable.just(it) | |
| .doOnNext { |
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 debugSubscribeOn(): Disposable = | |
| Observable.just(1) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } | |
| .subscribeOn(Schedulers.io()) | |
| .flatMap { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| Observable.just(it) | |
| .subscribeOn(Schedulers.computation()) |
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 debugSubscribeOn(): Disposable = | |
| Observable.just(1, 2, 3) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } | |
| .subscribeOn(Schedulers.io()) | |
| .subscribeOn(Schedulers.computation()) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } |
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 debugSubscribeOn(): Disposable = | |
| Observable.just(1, 2, 3) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } | |
| .subscribeOn(Schedulers.io()) | |
| .doOnNext { | |
| println(Thread.currentThread().name) // RxCachedThreadScheduler-1 | |
| } | |
| .subscribe() |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <layout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| xmlns:app="http://schemas.android.com/apk/res-auto"> | |
| <data> | |
| <variable | |
| name="listModel" | |
| type="androidx.lifecycle.LiveData<me.longv.pokedex.databinding.RecyclerViewModel>"/> | |
| </data> |
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
| package me.longv.pokedex.databinding | |
| import androidx.databinding.BindingAdapter | |
| import androidx.recyclerview.widget.RecyclerView | |
| @BindingAdapter(value = ["model"]) | |
| fun setupRecyclerView(view: RecyclerView, model: RecyclerViewModel?) { | |
| model?.apply { | |
| view.adapter = DataBindingAdapter(bindingEntries) | |
| view.layoutManager = layoutManager |
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 DataBindingAdapter(private var bindingEntries: List<DataBindingEntry> = emptyList()) | |
| : RecyclerView.Adapter<DataBindingViewHolder>() { | |
| override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DataBindingViewHolder { | |
| val layoutInflater = LayoutInflater.from(parent.context) | |
| val viewBinding = DataBindingUtil.inflate<ViewDataBinding>(layoutInflater, viewType, parent, false) | |
| return DataBindingViewHolder(viewBinding) | |
| } | |
| override fun onBindViewHolder(holder: DataBindingViewHolder, position: Int) { |
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 DataBindingViewHolder(private val viewBinding: ViewDataBinding): RecyclerView.ViewHolder(viewBinding.root) { | |
| fun bind(bindingEntry: DataBindingEntry) { | |
| viewBinding.apply { | |
| bindingEntry.bindings.forEach { setVariable(it.key, it.value) } | |
| } | |
| } | |
| } |
NewerOlder