Skip to content

Commit

Permalink
Merge pull request #272 from cyb3rko/fix-splashscreen
Browse files Browse the repository at this point in the history
Native splashscreen
  • Loading branch information
jmattheis authored Feb 2, 2023
2 parents 11a7453 + f49d8fb commit b69d352
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -49,6 +49,8 @@ internal class InitializationActivity : AppCompatActivity() {
settings = Settings(this)
Log.i("Entering ${javaClass.simpleName}")

installSplashScreen().setKeepOnScreenCondition { splashScreenActive }

if (settings.tokenExists()) {
runWithNeededPermissions {
tryAuthenticate()
Expand All @@ -59,6 +61,7 @@ internal class InitializationActivity : AppCompatActivity() {
}

private fun showLogin() {
splashScreenActive = false
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
Expand All @@ -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))
Expand All @@ -98,6 +103,7 @@ internal class InitializationActivity : AppCompatActivity() {
.setMessage(message)
.setPositiveButton(R.string.retry) { _, _ -> tryAuthenticate() }
.setNegativeButton(R.string.logout) { _, _ -> showLogin() }
.setCancelable(false)
.show()
}

Expand All @@ -106,6 +112,7 @@ internal class InitializationActivity : AppCompatActivity() {

settings.setUser(user.name, user.isAdmin)
requestVersion {
splashScreenActive = false
startActivity(Intent(this, MessagesActivity::class.java))
finish()
}
Expand Down
Binary file added app/src/main/res/drawable/gotify_splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down

0 comments on commit b69d352

Please sign in to comment.