Skip to content

Instantly share code, notes, and snippets.

@tinsukE
Last active May 30, 2018 12:25
Show Gist options
  • Save tinsukE/bfdb96ad381e65f9bc1a94e0b90ffae2 to your computer and use it in GitHub Desktop.
Save tinsukE/bfdb96ad381e65f9bc1a94e0b90ffae2 to your computer and use it in GitHub Desktop.
Simple Splash
class SplashActivity : Activity() {
private var isUserSessionInitialized = false
private var hasBeenShownForMinTime = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initializeUserSession()
scheduleProgressBar()
}
private fun initializeUserSession() {
userSession.initialize(object : Callback<Unit> {
override fun onSuccess(result: Unit) = onUserSessionInitialized()
override fun onError(error: Error) = onUserSessionError(error)
})
}
private fun onUserSessionInitialized() {
isUserSessionInitialized = true
checkForCompletion()
}
private fun onUserSessionError(error: Error) {
showRetryAlert(error,
onRetry = { initializeUserSession() },
onCancel = { finish() })
}
private fun scheduleProgressBar() {
progressBar.postDelayed({
hasBeenShownForMinTime = true
checkForCompletion()
progressBar.visibility = View.VISIBLE
}, MIN_SHOW_TIME)
}
private fun checkForCompletion() {
if (isUserSessionInitialized && hasBeenShownForMinTime) {
setResult(Activity.RESULT_OK)
finish()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment