Add option to disable new sources tip

This commit is contained in:
Koitharu
2023-10-12 13:34:35 +03:00
parent cc2f9d4529
commit d4588570e6
4 changed files with 35 additions and 12 deletions

View File

@@ -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"

View File

@@ -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<Set<MangaSource>> = combine(
dao.observeAll(),
observeIsNsfwDisabled(),
) { entities, skipNsfw ->
val result = EnumSet.copyOf(remoteSources)
for (e in entities) {
result.remove(MangaSource(e.source))
fun observeNewSources(): Flow<Set<MangaSource>> = 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<MangaSource> {
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
}
}

View File

@@ -494,4 +494,6 @@
<string name="state_abandoned">Dropped</string>
<string name="enhanced_colors_summary">Reduces banding, but may impact performance</string>
<string name="enhanced_colors">32-bit color mode</string>
<string name="suggest_new_sources">Suggest new sources after app update</string>
<string name="suggest_new_sources_summary">Prompt to enable newly added sources after updating the application</string>
</resources>

View File

@@ -53,6 +53,12 @@
android:key="sources_grid"
android:title="@string/show_in_grid_view" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="sources_new"
android:summary="@string/suggest_new_sources_summary"
android:title="@string/suggest_new_sources" />
</PreferenceCategory>
<PreferenceScreen