Skip to content

Commit

Permalink
Update splash screen to properly use the Androidx SplashScreen library (
Browse files Browse the repository at this point in the history
#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+.
  • Loading branch information
cbeyls authored May 12, 2024
1 parent f9221b3 commit 45d36a6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 69 deletions.
27 changes: 10 additions & 17 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@
android:localeConfig="@xml/locales_config"
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
android:name=".components.login.LoginActivity"
android:windowSoftInputMode="adjustResize"
Expand All @@ -56,8 +40,14 @@
<activity
android:name=".MainActivity"
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>
<action android:name="android.intent.action.SEND" />

Expand Down Expand Up @@ -101,6 +91,9 @@
<data android:mimeType="audio/*" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/share_shortcuts" />
<meta-data
android:name="android.service.chooser.chooser_target_service"
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/keylesspalace/tusky/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
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 */
Expand Down Expand Up @@ -207,9 +209,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
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();
}
}
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
47 changes: 0 additions & 47 deletions app/src/main/java/com/keylesspalace/tusky/SplashActivity.kt

This file was deleted.

1 change: 0 additions & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<style name="SplashTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
<item name="windowSplashScreenBackground">@color/tusky_grey_20</item>
<item name="postSplashScreenTheme">@style/TuskyTheme</item>
</style>

<style name="TuskyTheme" parent="TuskyBaseTheme" />
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ androidx-paging = "3.2.1"
androidx-preference = "1.2.1"
androidx-recyclerview = "1.3.0"
androidx-sharetarget = "1.2.0"
androidx-splashscreen = "1.0.1"
androidx-splashscreen = "1.2.0-alpha01"
androidx-swiperefresh-layout = "1.1.0"
androidx-testing = "2.2.0"
androidx-viewpager2 = "1.0.0"
Expand Down

0 comments on commit 45d36a6

Please sign in to comment.