From 4551313bd291bc33da735f61ee73b574cf078244 Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Wed, 19 Jun 2024 16:27:49 +0200 Subject: [PATCH] refactor: Use androidx.core:core-splashscreen library (#766) Previous code depended on, but did not initialise, the androidx splashscreen library. Fix that, using the library on API < 31, or the platform implementation otherwise. `SplashActivity` is no longer needed, launching goes straight in to `MainActivity`. Version 1.2.0-alpha01 is needed to fix some theme corruption bugs in earlier versions of the library. --- app/src/main/AndroidManifest.xml | 30 +++++------ app/src/main/java/app/pachli/MainActivity.kt | 8 ++- .../main/java/app/pachli/SplashActivity.kt | 52 ------------------- .../app/pachli/core/activity/BaseActivity.kt | 10 +++- .../src/main/res/values/styles.xml | 1 - gradle/libs.versions.toml | 2 +- 6 files changed, 29 insertions(+), 74 deletions(-) delete mode 100644 app/src/main/java/app/pachli/SplashActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index eea144fc7..fe1ee2ffb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,22 +25,6 @@ android:networkSecurityConfig="@xml/network_security_config" android:enableOnBackInvokedCallback="true"> - - - - - - - - - - - + + + android:exported="true" + android:theme="@style/SplashTheme"> + + + + + + @@ -109,6 +102,9 @@ android:name="android.service.chooser.chooser_target_service" android:value="androidx.sharetarget.ChooserTargetServiceCompat" /> + . - */ - -package app.pachli - -import android.annotation.SuppressLint -import android.os.Bundle -import androidx.appcompat.app.AppCompatActivity -import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import app.pachli.core.accounts.AccountManager -import app.pachli.core.navigation.LoginActivityIntent -import app.pachli.core.navigation.LoginActivityIntent.LoginMode -import app.pachli.core.navigation.MainActivityIntent -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?) { - installSplashScreen() - 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) { - MainActivityIntent(this) - } else { - LoginActivityIntent(this, LoginMode.DEFAULT) - } - startActivity(intent) - finish() - } -} diff --git a/core/activity/src/main/kotlin/app/pachli/core/activity/BaseActivity.kt b/core/activity/src/main/kotlin/app/pachli/core/activity/BaseActivity.kt index 23b0e553b..16de7f288 100644 --- a/core/activity/src/main/kotlin/app/pachli/core/activity/BaseActivity.kt +++ b/core/activity/src/main/kotlin/app/pachli/core/activity/BaseActivity.kt @@ -56,6 +56,7 @@ import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.EntryPointAccessors.fromApplication import dagger.hilt.components.SingletonComponent import javax.inject.Inject +import kotlin.properties.Delegates import timber.log.Timber @AndroidEntryPoint @@ -68,13 +69,18 @@ abstract class BaseActivity : AppCompatActivity(), MenuProvider { private var requesters: HashMap = HashMap() + /** The most recent theme ID set with [setTheme]. */ + @get:StyleRes + private var activeThemeId by Delegates.notNull() + @EntryPoint @InstallIn(SingletonComponent::class) interface SharedPreferencesRepositoryEntryPoint { fun sharedPreferencesRepository(): SharedPreferencesRepository } - override fun setTheme(themeId: Int) { + override fun setTheme(@StyleRes themeId: Int) { + activeThemeId = themeId super.setTheme(themeId) if (BuildConfig.DEBUG) { val name = resources.getResourceEntryName(themeId) @@ -97,6 +103,8 @@ abstract class BaseActivity : AppCompatActivity(), MenuProvider { Timber.d("activeTheme: %s", theme) if (theme == AppTheme.BLACK) { setTheme(DR.style.Theme_Pachli_Black) + } else if (activeThemeId == DR.style.SplashTheme) { + setTheme(DR.style.Theme_Pachli) } // Set the task description, the theme would turn it blue diff --git a/core/designsystem/src/main/res/values/styles.xml b/core/designsystem/src/main/res/values/styles.xml index 662299684..b1522e576 100644 --- a/core/designsystem/src/main/res/values/styles.xml +++ b/core/designsystem/src/main/res/values/styles.xml @@ -58,7 +58,6 @@