Created
April 29, 2020 06:06
-
-
Save BalazsErik/a6f7efbff9689eeabd0a233f937e4b5c to your computer and use it in GitHub Desktop.
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
class LifecycleEventDispatcher( | |
lifecycleOwner: LifecycleOwner, | |
val onCreate: () -> Unit = {}, | |
val onStart: () -> Unit = {}, | |
val onResume: () -> Unit = {}, | |
val onPause: () -> Unit = {}, | |
val onStop: () -> Unit = {}, | |
val onDestroy: () -> Unit = {} | |
) : DefaultLifecycleObserver { | |
init { lifecycleOwner.lifecycle.addObserver(this) } | |
override fun onCreate(owner: LifecycleOwner) = onCreate() | |
override fun onStart(owner: LifecycleOwner) = onStart() | |
override fun onResume(owner: LifecycleOwner) = onResume() | |
override fun onPause(owner: LifecycleOwner) = onPause() | |
override fun onStop(owner: LifecycleOwner) = onStop() | |
override fun onDestroy(owner: LifecycleOwner) = onDestroy() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment