Created
September 18, 2018 06:59
-
-
Save markchristopherng/229d9e8b42c6f44e05bc3d5cb98aa673 to your computer and use it in GitHub Desktop.
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 BaseActivity : AppCompatActivity() { | |
fun <T> LiveData<T>.observe(observer: (T?) -> Unit) = observe(this@BaseActivity, Observer { observer(it) }) | |
fun <T> LiveData<T>.observeNonNull(observer: (T) -> Unit) = observe { if (it != null) observer(it) } | |
fun <T> EventLiveData<T>.observeEvent(observer: (T) -> Unit) = observeEvent(this@BaseActivity, Observer { if (it != null) observer(it) }) | |
inline fun <reified T : BaseViewModel> getViewModel(): T = ViewModelProviders.of(this)[T::class.java] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment