Skip to content

Instantly share code, notes, and snippets.

@thenixan
Created January 12, 2018 15:30
Show Gist options
  • Save thenixan/78144934bc9815b2c840f2999100d764 to your computer and use it in GitHub Desktop.
Save thenixan/78144934bc9815b2c840f2999100d764 to your computer and use it in GitHub Desktop.
private const val ACTIVITY_AUTH = 1000
abstract class SplashedActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
if (!isAuthenticated()) {
startActivityForResult(Intent(this, AuthActivity::class.java), ACTIVITY_AUTH)
}
setTheme(R.style.AppTheme_Base)
super.onCreate(savedInstanceState)
}
private fun isAuthenticated(): Boolean {
return getUser() != null
}
private fun onAuthenticatedCallback(resultCode: Int, data: Intent?) {
when (resultCode) {
Activity.RESULT_CANCELED -> finish()
Activity.RESULT_OK -> recreate()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) {
ACTIVITY_AUTH -> onAuthenticatedCallback(resultCode, data)
}
super.onActivityResult(requestCode, resultCode, data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment