Created
January 12, 2018 15:30
-
-
Save thenixan/78144934bc9815b2c840f2999100d764 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
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