Option to clear chapter cache when MainActivity is closed (closes #5651)

This commit is contained in:
arkon
2021-11-19 10:50:52 -05:00
parent a2c830b908
commit 98822a39d9
5 changed files with 18 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ import dev.chrisbanes.insetter.applyInsetter
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.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
@@ -72,6 +73,7 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onEach
import logcat.LogPriority
import uy.kohesive.injekt.injectLazy
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
@@ -94,6 +96,8 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
*/
private val backstackLiftState = mutableMapOf<String, Boolean>()
private val chapterCache: ChapterCache by injectLazy()
// To be checked by splash screen. If true then splash screen will be removed.
var ready = false
@@ -464,7 +468,10 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
// Exit confirmation (resets after 2 seconds)
lifecycleScope.launchUI { resetExitConfirmation() }
} else if (backstackSize == 1 || !router.handleBack()) {
// Regular back
// Regular back (i.e. closing the app)
if (preferences.autoClearChapterCache()) {
chapterCache.clear()
}
super.onBackPressed()
}
}

View File

@@ -132,6 +132,11 @@ class SettingsAdvancedController : SettingsController() {
onClick { clearChapterCache() }
}
switchPreference {
key = Keys.autoClearChapterCache
titleRes = R.string.pref_auto_clear_chapter_cache
defaultValue = false
}
preference {
key = "pref_clear_database"
titleRes = R.string.pref_clear_database