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:
parent
f9221b3d75
commit
45d36a6a87
|
@ -21,22 +21,6 @@
|
||||||
android:localeConfig="@xml/locales_config"
|
android:localeConfig="@xml/locales_config"
|
||||||
android:enableOnBackInvokedCallback="true">
|
android:enableOnBackInvokedCallback="true">
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".SplashActivity"
|
|
||||||
android:theme="@style/SplashTheme"
|
|
||||||
android:exported="true">
|
|
||||||
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
|
||||||
</intent-filter>
|
|
||||||
|
|
||||||
<meta-data
|
|
||||||
android:name="android.app.shortcuts"
|
|
||||||
android:resource="@xml/share_shortcuts" />
|
|
||||||
|
|
||||||
</activity>
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".components.login.LoginActivity"
|
android:name=".components.login.LoginActivity"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
|
@ -56,8 +40,14 @@
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
|
android:configChanges="orientation|screenSize|keyboardHidden|screenLayout|smallestScreenSize"
|
||||||
android:exported="true">
|
android:exported="true"
|
||||||
|
android:theme="@style/SplashTheme">
|
||||||
|
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.SEND" />
|
<action android:name="android.intent.action.SEND" />
|
||||||
|
|
||||||
|
@ -101,6 +91,9 @@
|
||||||
<data android:mimeType="audio/*" />
|
<data android:mimeType="audio/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.shortcuts"
|
||||||
|
android:resource="@xml/share_shortcuts" />
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.service.chooser.chooser_target_service"
|
android:name="android.service.chooser.chooser_target_service"
|
||||||
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
|
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
|
||||||
|
|
|
@ -102,6 +102,8 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||||
Log.d("activeTheme", theme);
|
Log.d("activeTheme", theme);
|
||||||
if (ThemeUtils.isBlack(getResources().getConfiguration(), theme)) {
|
if (ThemeUtils.isBlack(getResources().getConfiguration(), theme)) {
|
||||||
setTheme(R.style.TuskyBlackTheme);
|
setTheme(R.style.TuskyBlackTheme);
|
||||||
|
} else {
|
||||||
|
setTheme(R.style.TuskyTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the taskdescription programmatically, the theme would turn it blue */
|
/* set the taskdescription programmatically, the theme would turn it blue */
|
||||||
|
@ -207,9 +209,9 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||||
protected void redirectIfNotLoggedIn() {
|
protected void redirectIfNotLoggedIn() {
|
||||||
AccountEntity account = accountManager.getActiveAccount();
|
AccountEntity account = accountManager.getActiveAccount();
|
||||||
if (account == null) {
|
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);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
ActivityExtensions.startActivityWithSlideInAnimation(this, intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.core.view.MenuProvider
|
import androidx.core.view.MenuProvider
|
||||||
import androidx.core.view.forEach
|
import androidx.core.view.forEach
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
@ -203,10 +204,15 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
val splashScreen = installSplashScreen()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
val activeAccount = accountManager.activeAccount
|
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()) {
|
if (explodeAnimationWasRequested()) {
|
||||||
overrideActivityTransitionCompat(
|
overrideActivityTransitionCompat(
|
||||||
|
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,7 +33,6 @@
|
||||||
<style name="SplashTheme" parent="Theme.SplashScreen">
|
<style name="SplashTheme" parent="Theme.SplashScreen">
|
||||||
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
|
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
|
||||||
<item name="windowSplashScreenBackground">@color/tusky_grey_20</item>
|
<item name="windowSplashScreenBackground">@color/tusky_grey_20</item>
|
||||||
<item name="postSplashScreenTheme">@style/TuskyTheme</item>
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="TuskyTheme" parent="TuskyBaseTheme" />
|
<style name="TuskyTheme" parent="TuskyBaseTheme" />
|
||||||
|
|
|
@ -17,7 +17,7 @@ androidx-paging = "3.2.1"
|
||||||
androidx-preference = "1.2.1"
|
androidx-preference = "1.2.1"
|
||||||
androidx-recyclerview = "1.3.0"
|
androidx-recyclerview = "1.3.0"
|
||||||
androidx-sharetarget = "1.2.0"
|
androidx-sharetarget = "1.2.0"
|
||||||
androidx-splashscreen = "1.0.1"
|
androidx-splashscreen = "1.2.0-alpha01"
|
||||||
androidx-swiperefresh-layout = "1.1.0"
|
androidx-swiperefresh-layout = "1.1.0"
|
||||||
androidx-testing = "2.2.0"
|
androidx-testing = "2.2.0"
|
||||||
androidx-viewpager2 = "1.0.0"
|
androidx-viewpager2 = "1.0.0"
|
||||||
|
|
Loading…
Reference in New Issue