Last active
May 30, 2018 12:25
-
-
Save tinsukE/bfdb96ad381e65f9bc1a94e0b90ffae2 to your computer and use it in GitHub Desktop.
Simple Splash
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 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