From d4588570e6aea42d61217425edaa2c35b212ef9f Mon Sep 17 00:00:00 2001 From: Koitharu Date: Thu, 12 Oct 2023 13:34:35 +0300 Subject: [PATCH] Add option to disable new sources tip --- .../kotatsu/core/prefs/AppSettings.kt | 4 +++ .../explore/data/MangaSourcesRepository.kt | 35 ++++++++++++------- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_appearance.xml | 6 ++++ 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index dbee8c95c..8681d4cb5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -201,6 +201,9 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { get() = prefs.getBoolean(KEY_SOURCES_GRID, false) set(value) = prefs.edit { putBoolean(KEY_SOURCES_GRID, value) } + val isNewSourcesTipEnabled: Boolean + get() = prefs.getBoolean(KEY_SOURCES_NEW, true) + val isPagesNumbersEnabled: Boolean get() = prefs.getBoolean(KEY_PAGES_NUMBERS, false) @@ -477,6 +480,7 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { const val KEY_LOGGING_ENABLED = "logging" const val KEY_LOGS_SHARE = "logs_share" const val KEY_SOURCES_GRID = "sources_grid" + const val KEY_SOURCES_NEW = "sources_new" const val KEY_UPDATES_UNSTABLE = "updates_unstable" const val KEY_TIPS_CLOSED = "tips_closed" const val KEY_SSL_BYPASS = "ssl_bypass" diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt index 711cad065..fc677c35c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/explore/data/MangaSourcesRepository.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.core.db.MangaDatabase @@ -92,19 +93,25 @@ class MangaSourcesRepository @Inject constructor( } } - fun observeNewSources(): Flow> = combine( - dao.observeAll(), - observeIsNsfwDisabled(), - ) { entities, skipNsfw -> - val result = EnumSet.copyOf(remoteSources) - for (e in entities) { - result.remove(MangaSource(e.source)) + fun observeNewSources(): Flow> = observeIsNewSourcesEnabled().flatMapLatest { + if (it) { + combine( + dao.observeAll(), + observeIsNsfwDisabled(), + ) { entities, skipNsfw -> + val result = EnumSet.copyOf(remoteSources) + for (e in entities) { + result.remove(MangaSource(e.source)) + } + if (skipNsfw) { + result.removeAll { x -> x.isNsfw() } + } + result + }.distinctUntilChanged() + } else { + flowOf(emptySet()) } - if (skipNsfw) { - result.removeAll { x -> x.isNsfw() } - } - result - }.distinctUntilChanged() + } suspend fun assimilateNewSources(): Set { val new = getNewSources() @@ -156,4 +163,8 @@ class MangaSourcesRepository @Inject constructor( private fun observeIsNsfwDisabled() = settings.observeAsFlow(AppSettings.KEY_DISABLE_NSFW) { isNsfwContentDisabled } + + private fun observeIsNewSourcesEnabled() = settings.observeAsFlow(AppSettings.KEY_SOURCES_NEW) { + isNewSourcesTipEnabled + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49eed5c50..a73782c20 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -494,4 +494,6 @@ Dropped Reduces banding, but may impact performance 32-bit color mode + Suggest new sources after app update + Prompt to enable newly added sources after updating the application diff --git a/app/src/main/res/xml/pref_appearance.xml b/app/src/main/res/xml/pref_appearance.xml index e5dc6b4c0..e43a5ddbf 100644 --- a/app/src/main/res/xml/pref_appearance.xml +++ b/app/src/main/res/xml/pref_appearance.xml @@ -53,6 +53,12 @@ android:key="sources_grid" android:title="@string/show_in_grid_view" /> + +