mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Use singleton app state to track splashscreen state
This is the most elegant solution I could think of
This commit is contained in:
parent
8fb9efc19a
commit
07a988157d
4 changed files with 23 additions and 18 deletions
5
app/src/main/java/dev/yokai/domain/AppState.kt
Normal file
5
app/src/main/java/dev/yokai/domain/AppState.kt
Normal file
|
@ -0,0 +1,5 @@
|
|||
package dev.yokai.domain
|
||||
|
||||
class AppState {
|
||||
var isSplashShown = false
|
||||
}
|
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.di
|
|||
|
||||
import android.app.Application
|
||||
import androidx.core.content.ContextCompat
|
||||
import dev.yokai.domain.AppState
|
||||
import dev.yokai.domain.extension.TrustExtension
|
||||
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
|
@ -58,6 +59,8 @@ class AppModule(val app: Application) : InjektModule {
|
|||
|
||||
addSingletonFactory { TrustExtension() }
|
||||
|
||||
addSingletonFactory { AppState() }
|
||||
|
||||
// Asynchronously init expensive components for a faster cold start
|
||||
|
||||
ContextCompat.getMainExecutor(app).execute {
|
||||
|
|
|
@ -74,6 +74,7 @@ import com.google.android.material.snackbar.Snackbar
|
|||
import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback
|
||||
import com.google.common.primitives.Floats.max
|
||||
import com.google.common.primitives.Ints.max
|
||||
import dev.yokai.domain.AppState
|
||||
import dev.yokai.presentation.extension.repo.ExtensionRepoController
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.Migrations
|
||||
|
@ -240,23 +241,11 @@ open class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
var skipSplashInstall = false
|
||||
private val appState: AppState by injectLazy()
|
||||
var ready = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
if (this !is SearchActivity) skipSplashInstall = intent.action !in listOf(Intent.ACTION_MAIN, Intent.ACTION_VIEW)
|
||||
skipSplashInstall = intent.getBooleanExtra(SPLASH_SKIP, skipSplashInstall)
|
||||
|
||||
val splashScreen = if (skipSplashInstall) {
|
||||
null
|
||||
} else {
|
||||
if (savedInstanceState == null) installSplashScreen() else null
|
||||
}
|
||||
|
||||
if (skipSplashInstall && splashScreen == null) {
|
||||
setTheme(R.style.Theme_Tachiyomi)
|
||||
ready = true
|
||||
}
|
||||
val splashScreen = maybeInstallSplashScreen(savedInstanceState)
|
||||
|
||||
// Set up shared element transition and disable overlay so views don't show above system bars
|
||||
window.requestFeature(Window.FEATURE_ACTIVITY_TRANSITIONS)
|
||||
|
@ -715,6 +704,18 @@ open class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun maybeInstallSplashScreen(savedInstanceState: Bundle?): SplashScreen? {
|
||||
if (appState.isSplashShown || savedInstanceState != null) {
|
||||
setTheme(R.style.Theme_Tachiyomi)
|
||||
ready = true
|
||||
return null
|
||||
} else {
|
||||
appState.isSplashShown = true
|
||||
}
|
||||
|
||||
return installSplashScreen()
|
||||
}
|
||||
|
||||
private fun setSplashScreenExitAnimation(splashScreen: SplashScreen?) {
|
||||
val root = findViewById<View>(android.R.id.content)
|
||||
|
||||
|
@ -1639,7 +1640,6 @@ open class MainActivity : BaseActivity<MainActivityBinding>() {
|
|||
private const val SPLASH_MIN_DURATION = 500 // ms
|
||||
private const val SPLASH_MAX_DURATION = 5000 // ms
|
||||
private const val SPLASH_EXIT_ANIM_DURATION = 400L // ms
|
||||
const val SPLASH_SKIP = "${BuildConfig.APPLICATION_ID}.SHOULD_SKIP_SPLASH"
|
||||
|
||||
var chapterIdToExitTo = 0L
|
||||
var backVelocity = 0f
|
||||
|
|
|
@ -33,8 +33,6 @@ class SearchActivity : MainActivity() {
|
|||
private var backToMain = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
skipSplashInstall = intentShouldGoBack()
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
binding.toolbar.navigationIcon = backDrawable
|
||||
binding.toolbar.setNavigationOnClickListener { popToRoot() }
|
||||
|
@ -75,7 +73,6 @@ class SearchActivity : MainActivity() {
|
|||
} else if (!router.handleBack()) {
|
||||
val intent = Intent(this, MainActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
putExtra(SPLASH_SKIP, true)
|
||||
}
|
||||
backToMain = true
|
||||
startActivity(intent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue