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.
This commit is contained in:
Nik Clayton 2024-06-19 16:27:49 +02:00 committed by GitHub
parent 2f69b20209
commit 4551313bd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 74 deletions

View File

@ -25,22 +25,6 @@
android:networkSecurityConfig="@xml/network_security_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=".feature.login.LoginActivity"
android:windowSoftInputMode="adjustResize"
@ -56,11 +40,20 @@
android:scheme="@string/oauth_scheme" />
</intent-filter>
</activity>
<activity android:name=".feature.login.LoginWebViewActivity" />
<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" />
@ -109,6 +102,9 @@
android:name="android.service.chooser.chooser_target_service"
android:value="androidx.sharetarget.ChooserTargetServiceCompat" />
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/share_shortcuts" />
</activity>
<activity
android:name=".components.compose.ComposeActivity"

View File

@ -48,6 +48,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.app.ActivityCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.view.GravityCompat
import androidx.core.view.MenuProvider
import androidx.core.view.forEach
@ -229,10 +230,13 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
@SuppressLint("RestrictedApi")
override fun onCreate(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
installSplashScreen()
}
super.onCreate(savedInstanceState)
val activeAccount = accountManager.activeAccount
?: return // will be redirected to LoginActivity by BaseActivity
// will be redirected to LoginActivity by BaseActivity
val activeAccount = accountManager.activeAccount ?: return
var showNotificationTab = false

View File

@ -1,52 +0,0 @@
/*
* Copyright 2023 Pachli Association
*
* This file is a part of Pachli.
*
* 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.
*
* Pachli 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 Pachli; if not,
* see <http://www.gnu.org/licenses>.
*/
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()
}
}

View File

@ -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<Int, PermissionRequester> = HashMap()
/** The most recent theme ID set with [setTheme]. */
@get:StyleRes
private var activeThemeId by Delegates.notNull<Int>()
@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

View File

@ -58,7 +58,6 @@
<style name="SplashTheme" parent="Theme.SplashScreen">
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash</item>
<item name="postSplashScreenTheme">@style/Theme.Pachli</item>
</style>
<style name="Theme.Pachli" parent="Base.Theme.Pachli">

View File

@ -18,7 +18,7 @@ androidx-paging = "3.3.0"
androidx-preference = "1.2.1"
androidx-recyclerview = "1.3.2"
androidx-sharetarget = "1.2.0"
androidx-splashscreen = "1.0.1"
androidx-splashscreen = "1.2.0-alpha01"
androidx-startup = "1.1.1"
androidx-swiperefresh-layout = "1.1.0"
androidx-testing = "2.2.0"