Merge pull request #272 from cyb3rko/fix-splashscreen

Native splashscreen
This commit is contained in:
Jannis Mattheis
2023-02-02 14:31:57 +01:00
committed by GitHub
5 changed files with 17 additions and 4 deletions

View File

@@ -65,6 +65,7 @@ if (project.hasProperty('sign')) {
dependencies {
implementation project(':client')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.core:core-splashscreen:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

View File

@@ -17,12 +17,12 @@
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.SplashScreen">
<activity
android:name=".init.InitializationActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:theme="@style/AppTheme.SplashScreen"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@@ -7,6 +7,7 @@ import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.preference.PreferenceManager
import com.github.gotify.NotificationSupport
import com.github.gotify.R
@@ -30,6 +31,7 @@ import com.livinglifetechway.quickpermissionskotlin.util.QuickPermissionsRequest
internal class InitializationActivity : AppCompatActivity() {
private lateinit var settings: Settings
private var splashScreenActive = true
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -38,8 +40,6 @@ internal class InitializationActivity : AppCompatActivity() {
.getString(getString(R.string.setting_key_theme), getString(R.string.theme_default))!!
ThemeHelper.setTheme(this, theme)
setContentView(R.layout.splash)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationSupport.createChannels(
this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
@@ -49,6 +49,8 @@ internal class InitializationActivity : AppCompatActivity() {
settings = Settings(this)
Log.i("Entering ${javaClass.simpleName}")
installSplashScreen().setKeepOnScreenCondition { splashScreenActive }
if (settings.tokenExists()) {
runWithNeededPermissions {
tryAuthenticate()
@@ -59,6 +61,7 @@ internal class InitializationActivity : AppCompatActivity() {
}
private fun showLogin() {
splashScreenActive = false
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
@@ -76,6 +79,8 @@ internal class InitializationActivity : AppCompatActivity() {
}
private fun failed(exception: ApiException) {
splashScreenActive = false
setContentView(R.layout.splash)
when (exception.code) {
0 -> {
dialog(getString(R.string.not_available, settings.url))
@@ -98,6 +103,7 @@ internal class InitializationActivity : AppCompatActivity() {
.setMessage(message)
.setPositiveButton(R.string.retry) { _, _ -> tryAuthenticate() }
.setNegativeButton(R.string.logout) { _, _ -> showLogin() }
.setCancelable(false)
.show()
}
@@ -106,6 +112,7 @@ internal class InitializationActivity : AppCompatActivity() {
settings.setUser(user.name, user.isAdmin)
requestVersion {
splashScreenActive = false
startActivity(Intent(this, MessagesActivity::class.java))
finish()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

View File

@@ -15,6 +15,11 @@
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.SplashScreen" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/gotify_splash</item>
<item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />