@@ -7,6 +7,7 @@ import android.os.Build
77import android.os.Bundle
88import androidx.appcompat.app.AlertDialog
99import androidx.appcompat.app.AppCompatActivity
10+ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1011import androidx.preference.PreferenceManager
1112import com.github.gotify.NotificationSupport
1213import com.github.gotify.R
@@ -30,6 +31,7 @@ import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsRequest
3031internal class InitializationActivity : AppCompatActivity () {
3132
3233 private lateinit var settings: Settings
34+ private var splashScreenActive = true
3335
3436 override fun onCreate (savedInstanceState : Bundle ? ) {
3537 super .onCreate(savedInstanceState)
@@ -38,8 +40,6 @@ internal class InitializationActivity : AppCompatActivity() {
3840 .getString(getString(R .string.setting_key_theme), getString(R .string.theme_default))!!
3941 ThemeHelper .setTheme(this , theme)
4042
41- setContentView(R .layout.splash)
42-
4343 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
4444 NotificationSupport .createChannels(
4545 this .getSystemService(NOTIFICATION_SERVICE ) as NotificationManager
@@ -49,6 +49,8 @@ internal class InitializationActivity : AppCompatActivity() {
4949 settings = Settings (this )
5050 Log .i(" Entering ${javaClass.simpleName} " )
5151
52+ installSplashScreen().setKeepOnScreenCondition { splashScreenActive }
53+
5254 if (settings.tokenExists()) {
5355 runWithNeededPermissions {
5456 tryAuthenticate()
@@ -59,6 +61,7 @@ internal class InitializationActivity : AppCompatActivity() {
5961 }
6062
6163 private fun showLogin () {
64+ splashScreenActive = false
6265 startActivity(Intent (this , LoginActivity ::class .java))
6366 finish()
6467 }
@@ -76,6 +79,8 @@ internal class InitializationActivity : AppCompatActivity() {
7679 }
7780
7881 private fun failed (exception : ApiException ) {
82+ splashScreenActive = false
83+ setContentView(R .layout.splash)
7984 when (exception.code) {
8085 0 -> {
8186 dialog(getString(R .string.not_available, settings.url))
@@ -98,6 +103,7 @@ internal class InitializationActivity : AppCompatActivity() {
98103 .setMessage(message)
99104 .setPositiveButton(R .string.retry) { _, _ -> tryAuthenticate() }
100105 .setNegativeButton(R .string.logout) { _, _ -> showLogin() }
106+ .setCancelable(false )
101107 .show()
102108 }
103109
@@ -106,6 +112,7 @@ internal class InitializationActivity : AppCompatActivity() {
106112
107113 settings.setUser(user.name, user.isAdmin)
108114 requestVersion {
115+ splashScreenActive = false
109116 startActivity(Intent (this , MessagesActivity ::class .java))
110117 finish()
111118 }
0 commit comments