Skip to content

Commit b69d352

Browse files
authored
Merge pull request #272 from cyb3rko/fix-splashscreen
Native splashscreen
2 parents 11a7453 + f49d8fb commit b69d352

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ if (project.hasProperty('sign')) {
6565
dependencies {
6666
implementation project(':client')
6767
implementation 'androidx.appcompat:appcompat:1.5.1'
68+
implementation 'androidx.core:core-splashscreen:1.0.0'
6869
implementation 'com.google.android.material:material:1.4.0'
6970
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
7071
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
android:supportsRtl="true"
1818
android:usesCleartextTraffic="true"
1919
android:networkSecurityConfig="@xml/network_security_config"
20-
android:theme="@style/AppTheme">
20+
android:theme="@style/AppTheme.SplashScreen">
2121
<activity
2222
android:name=".init.InitializationActivity"
2323
android:exported="true"
2424
android:label="@string/app_name"
25-
android:theme="@style/AppTheme.NoActionBar"
25+
android:theme="@style/AppTheme.SplashScreen"
2626
android:windowSoftInputMode="adjustResize">
2727
<intent-filter>
2828
<action android:name="android.intent.action.MAIN" />

app/src/main/kotlin/com/github/gotify/init/InitializationActivity.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.os.Build
77
import android.os.Bundle
88
import androidx.appcompat.app.AlertDialog
99
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1011
import androidx.preference.PreferenceManager
1112
import com.github.gotify.NotificationSupport
1213
import com.github.gotify.R
@@ -30,6 +31,7 @@ import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsRequest
3031
internal 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
}
95.4 KB
Loading

app/src/main/res/values/styles.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
<item name="windowActionBar">false</item>
1616
<item name="windowNoTitle">true</item>
1717
</style>
18+
19+
<style name="AppTheme.SplashScreen" parent="Theme.SplashScreen">
20+
<item name="windowSplashScreenAnimatedIcon">@drawable/gotify_splash</item>
21+
<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>
22+
</style>
1823

1924
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
2025

0 commit comments

Comments
 (0)