Last active
March 18, 2020 23:33
-
-
Save jraska/d0c23d6f64990b85ef7b46aba35a17aa 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
class TopActivityProvider { | |
private val pendingActions = mutableListOf<(Activity) -> Unit>() | |
var topActivity: Activity? = null | |
private set | |
@AnyThread | |
fun onTopActivity(action: (Activity) -> Unit) { | |
val topActivity = this.topActivity | |
if (topActivity == null) { | |
addPendingAction(action) | |
} else { | |
if (isMainThread()) { | |
action(topActivity) | |
} else { | |
addPendingAction(action) | |
topActivity.runOnUiThread { executePendingActions() } | |
} | |
} | |
} | |
@MainThread | |
private fun executePendingActions() { ... } | |
@AnyThread | |
private fun addPendingAction(action: (Activity) -> Unit) { ... } | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment