From 53c6230afebe8e8cddca216f281fdec70e450a33 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 7 Jul 2023 17:46:39 -0400 Subject: [PATCH] Change auto clear cache to occur on app launch instead Fixes #9564 Avoids the issue of clearing the cache when the app is backgrounded despite being in the reader. We could do a job on idle, but we'd still need to be careful around whether the reader is active, so this is just simpler considering it's a separate activity. --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 8 -------- .../kanade/tachiyomi/ui/main/MainActivity.kt | 18 +++++++++++++----- i18n/src/main/res/values/strings.xml | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index dbb6ed6a5e..822c66b81d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -28,7 +28,6 @@ import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.tachiyomi.crash.CrashActivity import eu.kanade.tachiyomi.crash.GlobalExceptionHandler -import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer import eu.kanade.tachiyomi.data.coil.MangaKeyer @@ -54,7 +53,6 @@ import org.acra.ktx.initAcra import org.acra.sender.HttpSender import org.conscrypt.Conscrypt import tachiyomi.core.util.system.logcat -import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.presentation.widget.TachiyomiWidgetManager import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -64,11 +62,9 @@ import java.security.Security class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { private val basePreferences: BasePreferences by injectLazy() - private val libraryPreferences: LibraryPreferences by injectLazy() private val networkPreferences: NetworkPreferences by injectLazy() private val disableIncognitoReceiver = DisableIncognitoReceiver() - private val chapterCache: ChapterCache by injectLazy() @SuppressLint("LaunchActivityFromNotification") override fun onCreate() { @@ -172,10 +168,6 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { override fun onStop(owner: LifecycleOwner) { SecureActivityDelegate.onApplicationStopped() - - if (libraryPreferences.autoClearChapterCache().get()) { - chapterCache.clear() - } } override fun getPackageName(): String { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index d92a60e749..4612eec34f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -63,6 +63,7 @@ import eu.kanade.presentation.util.collectAsState import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.updater.AppUpdateChecker @@ -105,6 +106,7 @@ class MainActivity : BaseActivity() { private val preferences: BasePreferences by injectLazy() private val downloadCache: DownloadCache by injectLazy() + private val chapterCache: ChapterCache by injectLazy() // To be checked by splash screen. If true then splash screen will be removed. var ready = false @@ -112,12 +114,14 @@ class MainActivity : BaseActivity() { private var navigator: Navigator? = null override fun onCreate(savedInstanceState: Bundle?) { + val isLaunch = savedInstanceState == null + // Prevent splash screen showing up on configuration changes - val splashScreen = if (savedInstanceState == null) installSplashScreen() else null + val splashScreen = if (isLaunch) installSplashScreen() else null super.onCreate(savedInstanceState) - val didMigration = if (savedInstanceState == null) { + val didMigration = if (isLaunch) { Migrations.upgrade( context = applicationContext, basePreferences = preferences, @@ -149,7 +153,7 @@ class MainActivity : BaseActivity() { val downloadOnly by preferences.downloadedOnly().collectAsState() val indexing by downloadCache.isInitializing.collectAsState() - // Set statusbar color considering the top app state banner + // Set status bar color considering the top app state banner val systemUiController = rememberSystemUiController() val isSystemInDarkTheme = isSystemInDarkTheme() val statusBarBackgroundColor = when { @@ -189,7 +193,7 @@ class MainActivity : BaseActivity() { LaunchedEffect(navigator) { this@MainActivity.navigator = navigator - if (savedInstanceState == null) { + if (isLaunch) { // Set start screen handleIntentAction(intent, navigator) @@ -267,6 +271,10 @@ class MainActivity : BaseActivity() { elapsed <= SPLASH_MIN_DURATION || (!ready && elapsed <= SPLASH_MAX_DURATION) } setSplashScreenExitAnimation(splashScreen) + + if (isLaunch && libraryPreferences.autoClearChapterCache().get()) { + chapterCache.clear() + } } override fun onProvideAssistContent(outContent: AssistContent) { @@ -279,7 +287,7 @@ class MainActivity : BaseActivity() { } @Composable - fun HandleOnNewIntent(context: Context, navigator: Navigator) { + private fun HandleOnNewIntent(context: Context, navigator: Navigator) { LaunchedEffect(Unit) { callbackFlow { val componentActivity = context as ComponentActivity diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index e037811512..06c68f2337 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -538,7 +538,7 @@ Used: %1$s Cache cleared. %1$d files have been deleted Error occurred while clearing - Clear chapter cache on app close + Clear chapter cache on app launch Invalidate downloads index Force app to recheck downloaded chapters Clear database