From c7dabb9d6388902773900daaaf4e8effb284b93e Mon Sep 17 00:00:00 2001 From: Jay Date: Fri, 3 Jan 2020 14:03:34 -0800 Subject: [PATCH] Setting to optionally sort by ignoring articles --- .../tachiyomi/data/preference/PreferenceKeys.kt | 2 ++ .../tachiyomi/data/preference/PreferencesHelper.kt | 2 ++ .../kanade/tachiyomi/ui/library/LibraryPresenter.kt | 13 +++++++------ .../ui/setting/SettingsGeneralController.kt | 8 ++++++++ app/src/main/res/values/strings.xml | 3 +++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index 63ffd7898e..0b63390243 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -125,6 +125,8 @@ object PreferenceKeys { const val lastUnlock = "last_unlock" + const val removeArticles = "remove_articles" + @Deprecated("Use the preferences of the source") fun sourceUsername(sourceId: Long) = "pref_source_username_$sourceId" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 63e99e6377..ad6758d0b0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -184,6 +184,8 @@ class PreferencesHelper(val context: Context) { fun lastUnlock() = rxPrefs.getLong(Keys.lastUnlock, 0) + fun removeArticles() = rxPrefs.getBoolean(Keys.removeArticles, false) + fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE) fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 0585da4ba9..2454c6f02f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -5,7 +5,6 @@ import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Category -import eu.kanade.tachiyomi.data.database.models.LibraryManga import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory import eu.kanade.tachiyomi.data.download.DownloadManager @@ -17,14 +16,14 @@ import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_EXCLUDE -import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_INCLUDE import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.migration.MigrationFlags import eu.kanade.tachiyomi.util.combineLatest import eu.kanade.tachiyomi.util.isNullOrUnsubscribed import eu.kanade.tachiyomi.util.syncChaptersWithSource +import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_EXCLUDE import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_IGNORE +import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.Companion.STATE_INCLUDE import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers @@ -223,11 +222,13 @@ class LibraryPresenter( return map.mapValues { entry -> entry.value.sortedWith(comparator) } } - fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int { - return i1.manga.title.removeArticles().compareTo(i2.manga.title.removeArticles(), true) + private fun sortAlphabetical(i1: LibraryItem, i2: LibraryItem): Int { + return if (preferences.removeArticles().getOrDefault()) + i1.manga.title.removeArticles().compareTo(i2.manga.title.removeArticles(), true) + else i1.manga.title.compareTo(i2.manga.title, true) } - fun String.removeArticles(): String { + private fun String.removeArticles(): String { return this.replace(Regex("^(an|a|the) ", RegexOption.IGNORE_CASE), "") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index a3828bb25f..840f05596f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -199,6 +199,14 @@ class SettingsGeneralController : SettingsController() { true } } + + switchPreference { + key = Keys.removeArticles + titleRes = R.string.pref_remove_articles + summaryRes = R.string.pref_remove_articles_summary + defaultValue = false + } + val biometricManager = BiometricManager.from(context) if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { var preference:IntListPreference? = null diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 45bed46bc4..e20c5e529e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -150,6 +150,9 @@ Charging Only update ongoing manga Sync chapters after reading + Sort by ignoring articles + When sorting alphabetically, sort ignoring + articles (a, an, the) at the start of manga titles Application theme Main theme Dark theme