diff --git a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.android.kt b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.android.kt index 0fc4827dd..db30cade2 100644 --- a/composeApp/src/androidMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.android.kt +++ b/composeApp/src/androidMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.android.kt @@ -21,4 +21,11 @@ actual object ContinueWatchingEnrichmentStorage { ?.putString(key, payload) ?.apply() } + + actual fun removePayload(key: String) { + preferences + ?.edit() + ?.remove(key) + ?.apply() + } } diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index f95746135..efbfeaf66 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -445,8 +445,12 @@ Search settings... RESULTS STARTUP + CACHE Remember Last Profile Remember last selected profile at startup + Clear Continue Watching Cache + Remove cached thumbnails, titles, and enrichment data for Continue Watching + Cache cleared APP LICENSE DATA & SERVICES PLAYBACK LICENSE diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/AdvancedSettingsPage.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/AdvancedSettingsPage.kt index 57af823ae..fc9f77cc1 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/AdvancedSettingsPage.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/AdvancedSettingsPage.kt @@ -1,10 +1,19 @@ package com.nuvio.app.features.settings import androidx.compose.foundation.lazy.LazyListScope +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue import com.nuvio.app.features.profiles.ProfileRepository +import com.nuvio.app.features.watchprogress.ContinueWatchingEnrichmentCache import nuvio.composeapp.generated.resources.Res +import nuvio.composeapp.generated.resources.settings_advanced_clear_cw_cache +import nuvio.composeapp.generated.resources.settings_advanced_clear_cw_cache_done +import nuvio.composeapp.generated.resources.settings_advanced_clear_cw_cache_subtitle import nuvio.composeapp.generated.resources.settings_advanced_remember_last_profile import nuvio.composeapp.generated.resources.settings_advanced_remember_last_profile_description +import nuvio.composeapp.generated.resources.settings_advanced_section_cache import nuvio.composeapp.generated.resources.settings_advanced_section_startup import org.jetbrains.compose.resources.stringResource @@ -28,4 +37,29 @@ internal fun LazyListScope.advancedSettingsContent( } } } + item { + SettingsSection( + title = stringResource(Res.string.settings_advanced_section_cache), + isTablet = isTablet, + ) { + SettingsGroup(isTablet = isTablet) { + var cleared by rememberSaveable { mutableStateOf(false) } + SettingsNavigationRow( + title = stringResource(Res.string.settings_advanced_clear_cw_cache), + description = if (cleared) { + stringResource(Res.string.settings_advanced_clear_cw_cache_done) + } else { + stringResource(Res.string.settings_advanced_clear_cw_cache_subtitle) + }, + isTablet = isTablet, + onClick = { + if (!cleared) { + ContinueWatchingEnrichmentCache.clearAll() + cleared = true + } + }, + ) + } + } + } } diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/SettingsSearch.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/SettingsSearch.kt index 045d6522b..d98da5120 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/SettingsSearch.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/settings/SettingsSearch.kt @@ -388,6 +388,16 @@ internal fun settingsSearchEntries( category = advancedCategory, icon = Icons.Rounded.Tune, ) + addRow( + page = SettingsPage.Advanced, + key = "clear-cw-cache", + title = stringResource(Res.string.settings_advanced_clear_cw_cache), + description = stringResource(Res.string.settings_advanced_clear_cw_cache_subtitle), + pageLabel = advancedPage, + section = stringResource(Res.string.settings_advanced_section_cache), + category = advancedCategory, + icon = Icons.Rounded.Tune, + ) addPage( page = SettingsPage.ContinueWatching, key = "continue-watching", diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentCache.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentCache.kt index fbdf59c00..00226f24f 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentCache.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentCache.kt @@ -95,6 +95,11 @@ internal object ContinueWatchingEnrichmentCache { lastPayloadHash = payloadHash } + fun clearAll() { + ContinueWatchingEnrichmentStorage.removePayload(ProfileScopedKey.of(storageKey)) + lastPayloadHash = null + } + private fun loadPayload(): CachedEnrichmentPayload? { val raw = ContinueWatchingEnrichmentStorage.loadPayload(ProfileScopedKey.of(storageKey)) ?: return null diff --git a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.kt b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.kt index 24d6791df..42a6df4b4 100644 --- a/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.kt +++ b/composeApp/src/commonMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.kt @@ -3,4 +3,5 @@ package com.nuvio.app.features.watchprogress internal expect object ContinueWatchingEnrichmentStorage { fun loadPayload(key: String): String? fun savePayload(key: String, payload: String) + fun removePayload(key: String) } diff --git a/composeApp/src/iosMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.ios.kt b/composeApp/src/iosMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.ios.kt index 7ce272e4c..9677d507b 100644 --- a/composeApp/src/iosMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.ios.kt +++ b/composeApp/src/iosMain/kotlin/com/nuvio/app/features/watchprogress/ContinueWatchingEnrichmentStorage.ios.kt @@ -9,4 +9,8 @@ actual object ContinueWatchingEnrichmentStorage { actual fun savePayload(key: String, payload: String) { NSUserDefaults.standardUserDefaults.setObject(payload, forKey = key) } + + actual fun removePayload(key: String) { + NSUserDefaults.standardUserDefaults.removeObjectForKey(key) + } }