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+.
This commit is contained in:
Christophe Beyls 2024-05-12 11:31:47 +02:00 committed by GitHub
commit 45d36a6a87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 22 additions and 69 deletions

View file

@ -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();
}
}

View file

@ -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(

View file

@ -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 <http://www.gnu.org/licenses>. */
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()
}
}