From 527a3cbd095fa5ad2b5ed74c43fbc7c5baebd936 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Sat, 20 Nov 2021 16:49:30 +0200 Subject: [PATCH] Option to exclude NSFW content from history --- .../main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt | 3 +++ .../main/java/org/koitharu/kotatsu/history/HistoryModule.kt | 2 +- .../org/koitharu/kotatsu/history/domain/HistoryRepository.kt | 5 +++++ app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_history.xml | 5 +++++ 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 992d656f2..fd09b006f 100644 --- a/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/java/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -79,6 +79,8 @@ class AppSettings private constructor(private val prefs: SharedPreferences) : var historyGrouping by BoolPreferenceDelegate(KEY_HISTORY_GROUPING, true) + var isHistoryExcludeNsfw by BoolPreferenceDelegate(KEY_HISTORY_EXCLUDE_NSFW, false) + var chaptersReverse by BoolPreferenceDelegate(KEY_REVERSE_CHAPTERS, false) val zoomMode by EnumPreferenceDelegate( @@ -192,6 +194,7 @@ class AppSettings private constructor(private val prefs: SharedPreferences) : const val KEY_RESTORE = "restore" const val KEY_HISTORY_GROUPING = "history_grouping" const val KEY_REVERSE_CHAPTERS = "reverse_chapters" + const val KEY_HISTORY_EXCLUDE_NSFW = "history_exclude_nsfw" // About const val KEY_APP_UPDATE = "app_update" diff --git a/app/src/main/java/org/koitharu/kotatsu/history/HistoryModule.kt b/app/src/main/java/org/koitharu/kotatsu/history/HistoryModule.kt index 6ca026947..bf6ea6304 100644 --- a/app/src/main/java/org/koitharu/kotatsu/history/HistoryModule.kt +++ b/app/src/main/java/org/koitharu/kotatsu/history/HistoryModule.kt @@ -8,6 +8,6 @@ import org.koitharu.kotatsu.history.ui.HistoryListViewModel val historyModule get() = module { - single { HistoryRepository(get(), get()) } + single { HistoryRepository(get(), get(), get()) } viewModel { HistoryListViewModel(get(), get(), get()) } } \ No newline at end of file diff --git a/app/src/main/java/org/koitharu/kotatsu/history/domain/HistoryRepository.kt b/app/src/main/java/org/koitharu/kotatsu/history/domain/HistoryRepository.kt index cece71003..220f06dca 100644 --- a/app/src/main/java/org/koitharu/kotatsu/history/domain/HistoryRepository.kt +++ b/app/src/main/java/org/koitharu/kotatsu/history/domain/HistoryRepository.kt @@ -8,6 +8,7 @@ import org.koitharu.kotatsu.core.db.entity.MangaEntity import org.koitharu.kotatsu.core.db.entity.TagEntity import org.koitharu.kotatsu.core.model.Manga import org.koitharu.kotatsu.core.model.MangaHistory +import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.history.data.HistoryEntity import org.koitharu.kotatsu.tracker.domain.TrackingRepository import org.koitharu.kotatsu.utils.ext.mapItems @@ -16,6 +17,7 @@ import org.koitharu.kotatsu.utils.ext.mapToSet class HistoryRepository( private val db: MangaDatabase, private val trackingRepository: TrackingRepository, + private val settings: AppSettings, ) { suspend fun getList(offset: Int, limit: Int = 20): List { @@ -45,6 +47,9 @@ class HistoryRepository( } suspend fun addOrUpdate(manga: Manga, chapterId: Long, page: Int, scroll: Int) { + if (manga.isNsfw && settings.isHistoryExcludeNsfw) { + return + } val tags = manga.tags.map(TagEntity.Companion::fromMangaTag) db.withTransaction { db.tagsDao.upsert(tags) diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 7748d96ac..e0b623ff9 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -243,4 +243,5 @@ Онгоинг Формат даты По умолчанию + Исключить NSFW мангу из истории \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0e16214b..50433214e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -244,4 +244,5 @@ Ongoing Date format Default + Exclude NSFW manga from history \ No newline at end of file diff --git a/app/src/main/res/xml/pref_history.xml b/app/src/main/res/xml/pref_history.xml index e23be0ed6..bde082b45 100644 --- a/app/src/main/res/xml/pref_history.xml +++ b/app/src/main/res/xml/pref_history.xml @@ -15,6 +15,11 @@ android:title="@string/clear_updates_feed" app:iconSpaceReserved="false" /> + +