mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Option to clear chapter cache when MainActivity is closed (closes #5651)
This commit is contained in:
parent
a2c830b908
commit
98822a39d9
@ -233,6 +233,8 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val verboseLogging = "verbose_logging"
|
const val verboseLogging = "verbose_logging"
|
||||||
|
|
||||||
|
const val autoClearChapterCache = "auto_clear_chapter_cache"
|
||||||
|
|
||||||
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
|
fun trackUsername(syncId: Int) = "pref_mangasync_username_$syncId"
|
||||||
|
|
||||||
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"
|
fun trackPassword(syncId: Int) = "pref_mangasync_password_$syncId"
|
||||||
|
@ -334,6 +334,8 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun verboseLogging() = prefs.getBoolean(Keys.verboseLogging, false)
|
fun verboseLogging() = prefs.getBoolean(Keys.verboseLogging, false)
|
||||||
|
|
||||||
|
fun autoClearChapterCache() = prefs.getBoolean(Keys.autoClearChapterCache, false)
|
||||||
|
|
||||||
fun setChapterSettingsDefault(manga: Manga) {
|
fun setChapterSettingsDefault(manga: Manga) {
|
||||||
prefs.edit {
|
prefs.edit {
|
||||||
putInt(Keys.defaultChapterFilterByRead, manga.readFilter)
|
putInt(Keys.defaultChapterFilterByRead, manga.readFilter)
|
||||||
|
@ -34,6 +34,7 @@ import dev.chrisbanes.insetter.applyInsetter
|
|||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.Migrations
|
import eu.kanade.tachiyomi.Migrations
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||||
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
|
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.merge
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import logcat.LogPriority
|
import logcat.LogPriority
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||||
|
|
||||||
@ -94,6 +96,8 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
*/
|
*/
|
||||||
private val backstackLiftState = mutableMapOf<String, Boolean>()
|
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.
|
// To be checked by splash screen. If true then splash screen will be removed.
|
||||||
var ready = false
|
var ready = false
|
||||||
|
|
||||||
@ -464,7 +468,10 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
|||||||
// Exit confirmation (resets after 2 seconds)
|
// Exit confirmation (resets after 2 seconds)
|
||||||
lifecycleScope.launchUI { resetExitConfirmation() }
|
lifecycleScope.launchUI { resetExitConfirmation() }
|
||||||
} else if (backstackSize == 1 || !router.handleBack()) {
|
} else if (backstackSize == 1 || !router.handleBack()) {
|
||||||
// Regular back
|
// Regular back (i.e. closing the app)
|
||||||
|
if (preferences.autoClearChapterCache()) {
|
||||||
|
chapterCache.clear()
|
||||||
|
}
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,11 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
|
|
||||||
onClick { clearChapterCache() }
|
onClick { clearChapterCache() }
|
||||||
}
|
}
|
||||||
|
switchPreference {
|
||||||
|
key = Keys.autoClearChapterCache
|
||||||
|
titleRes = R.string.pref_auto_clear_chapter_cache
|
||||||
|
defaultValue = false
|
||||||
|
}
|
||||||
preference {
|
preference {
|
||||||
key = "pref_clear_database"
|
key = "pref_clear_database"
|
||||||
titleRes = R.string.pref_clear_database
|
titleRes = R.string.pref_clear_database
|
||||||
|
@ -458,6 +458,7 @@
|
|||||||
<string name="used_cache">Used: %1$s</string>
|
<string name="used_cache">Used: %1$s</string>
|
||||||
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
|
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
|
||||||
<string name="cache_delete_error">An error occurred while clearing cache</string>
|
<string name="cache_delete_error">An error occurred while clearing cache</string>
|
||||||
|
<string name="pref_auto_clear_chapter_cache">Clear chapter cache on app close</string>
|
||||||
<string name="pref_clear_database">Clear database</string>
|
<string name="pref_clear_database">Clear database</string>
|
||||||
<string name="pref_clear_database_summary">Delete history for manga that are not saved in your library</string>
|
<string name="pref_clear_database_summary">Delete history for manga that are not saved in your library</string>
|
||||||
<string name="clear_database_confirmation">Are you sure? Read chapters and progress of non-library manga will be lost</string>
|
<string name="clear_database_confirmation">Are you sure? Read chapters and progress of non-library manga will be lost</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user