From 45d36a6a87d2e68544681d57f15f6b817da308c9 Mon Sep 17 00:00:00 2001 From: Christophe Beyls Date: Sun, 12 May 2024 11:31:47 +0200 Subject: [PATCH] Update splash screen to properly use the Androidx SplashScreen library (#4413) The Androidx SplashScreen library is added as a dependency to the project but isn't properly enabled in the current code. This pull request configures the splash screen properly. - Remove `SplashScreenActivity` which is not needed and use `MainActivity` as main entry point to the application. `MainActivity` inherits from `BaseActivity` which already detects if no account is configured and redirects to `LoginActivity` if needed, just like `SplashScreenActivity`. - Initialize the SplashScreen library in `MainActivity.onCreate()`. - Instead of letting the SplashScreen library set the final theme from the `postSplashScreenTheme` attribute in SplashTheme, let `BaseActivity` set it according to the user settings. - When no account is available in `MainActivity.onCreate()`, keep the splash screen shown until `LoginActivity` appears. - Disable the slide-in animation when launching `LoginActivity` when no account is available because the detection happens in `onCreate()` and an Activity that finishes itself in `onCreate()` will not be drawn, so the slide-in animation will not be visible either and only `LoginActivity` will appear. - Upgrade `core-splashscreen` to 1.2.0-alpha01 which contains a fix for corrupted app theme on API 31+. --- app/src/main/AndroidManifest.xml | 27 ++++------- .../com/keylesspalace/tusky/BaseActivity.java | 6 ++- .../com/keylesspalace/tusky/MainActivity.kt | 8 +++- .../com/keylesspalace/tusky/SplashActivity.kt | 47 ------------------- app/src/main/res/values/styles.xml | 1 - gradle/libs.versions.toml | 2 +- 6 files changed, 22 insertions(+), 69 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/SplashActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 54fbf8d23..d2c9bc440 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,22 +21,6 @@ android:localeConfig="@xml/locales_config" android:enableOnBackInvokedCallback="true"> - - - - - - - - - - - + android:exported="true" + android:theme="@style/SplashTheme"> + + + + + @@ -101,6 +91,9 @@ + diff --git a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java index 52f1dc7a4..dc9c42e35 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/BaseActivity.java @@ -102,6 +102,8 @@ public abstract class BaseActivity extends AppCompatActivity { Log.d("activeTheme", theme); if (ThemeUtils.isBlack(getResources().getConfiguration(), theme)) { setTheme(R.style.TuskyBlackTheme); + } else { + setTheme(R.style.TuskyTheme); } /* set the taskdescription programmatically, the theme would turn it blue */ @@ -207,9 +209,9 @@ public abstract class BaseActivity extends AppCompatActivity { protected void redirectIfNotLoggedIn() { AccountEntity account = accountManager.getActiveAccount(); if (account == null) { - Intent intent = new Intent(this, LoginActivity.class); + Intent intent = LoginActivity.getIntent(this, LoginActivity.MODE_DEFAULT); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); - ActivityExtensions.startActivityWithSlideInAnimation(this, intent); + startActivity(intent); finish(); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt index 36b37967b..305ce07c3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/MainActivity.kt @@ -46,6 +46,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat import androidx.core.content.pm.ShortcutManagerCompat +import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.MenuProvider import androidx.core.view.forEach import androidx.core.view.isVisible @@ -203,10 +204,15 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider { @SuppressLint("RestrictedApi") override fun onCreate(savedInstanceState: Bundle?) { + val splashScreen = installSplashScreen() super.onCreate(savedInstanceState) val activeAccount = accountManager.activeAccount - ?: return // will be redirected to LoginActivity by BaseActivity + if (activeAccount == null) { + splashScreen.setKeepOnScreenCondition { true } + // will be redirected to LoginActivity by BaseActivity + return + } if (explodeAnimationWasRequested()) { overrideActivityTransitionCompat( diff --git a/app/src/main/java/com/keylesspalace/tusky/SplashActivity.kt b/app/src/main/java/com/keylesspalace/tusky/SplashActivity.kt deleted file mode 100644 index 6acabf03f..000000000 --- a/app/src/main/java/com/keylesspalace/tusky/SplashActivity.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright 2018 Conny Duck - * - * This file is a part of Tusky. - * - * This program is free software; you can redistribute it and/or modify it under the terms of the - * GNU General Public License as published by the Free Software Foundation; either version 3 of the - * License, or (at your option) any later version. - * - * Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even - * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - * Public License for more details. - * - * You should have received a copy of the GNU General Public License along with Tusky; if not, - * see . */ - -package com.keylesspalace.tusky - -import android.annotation.SuppressLint -import android.content.Intent -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import com.keylesspalace.tusky.components.login.LoginActivity -import com.keylesspalace.tusky.db.AccountManager -import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject - -@SuppressLint("CustomSplashScreen") -@AndroidEntryPoint -class SplashActivity : AppCompatActivity() { - - @Inject - lateinit var accountManager: AccountManager - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - /** Determine whether the user is currently logged in, and if so go ahead and load the - * timeline. Otherwise, start the activity_login screen. */ - val intent = if (accountManager.activeAccount != null) { - Intent(this, MainActivity::class.java) - } else { - LoginActivity.getIntent(this, LoginActivity.MODE_DEFAULT) - } - startActivity(intent) - finish() - } -} diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index db118da3f..8b061dcb9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -33,7 +33,6 @@