Last active
August 6, 2019 15:52
-
-
Save SeongUgJung/406e3270e1b556426c43e2cdcf224a42 to your computer and use it in GitHub Desktop.
lifecycle callback managers
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
// lifecycle observers manager | |
class LifecycleController { | |
private val observers = mutableListOf<LifecycleObserver>() | |
private var state: LifecycleState = Unknown | |
fun onInit() { | |
observers.forEach { it.onInit() } | |
state = Init | |
} | |
fun onVisible() { | |
observers.forEach { it.onVisible() } | |
state = Visible | |
} | |
fun onInvisible() { | |
observers.forEach { it.onInvisible() } | |
state = Invisible | |
} | |
fun onDeinit() { | |
observers.forEach { it.onDeinit() } | |
state = Deinit | |
} | |
} | |
// lifecycle observer | |
interface LifecycleObserver { | |
fun onInit() = Unit | |
fun onVisible() = Unit | |
fun onInvisible() = Unit | |
fun onDeinit() = Unit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment