From 5bc77fc6e81815296941399831819584fc3e1ce3 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 19 Apr 2020 15:30:55 -0400 Subject: [PATCH] Add offline mode (forced download filters; closes #2902) --- .../data/preference/PreferenceKeys.kt | 2 + .../data/preference/PreferencesHelper.kt | 2 + .../tachiyomi/ui/library/LibraryPresenter.kt | 4 +- .../ui/library/LibrarySettingsSheet.kt | 3 +- .../ui/manga/chapter/ChaptersController.kt | 1 + .../ui/manga/chapter/ChaptersPresenter.kt | 9 +++- .../tachiyomi/ui/more/MoreController.kt | 51 +++++++++++-------- .../widget/ExtendedNavigationView.kt | 3 +- .../main/res/drawable/ic_cloud_off_24dp.xml | 9 ++++ app/src/main/res/values/strings.xml | 1 + 10 files changed, 59 insertions(+), 26 deletions(-) create mode 100644 app/src/main/res/drawable/ic_cloud_off_24dp.xml 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 5b267c2590..c7299157a2 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 @@ -99,6 +99,8 @@ object PreferenceKeys { const val libraryUpdatePrioritization = "library_update_prioritization" + const val offlineMode = "pref_offline_mode" + const val filterDownloaded = "pref_filter_downloaded_key" const val filterUnread = "pref_filter_unread_key" 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 2e94ed2bde..4eff9eb6eb 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 @@ -183,6 +183,8 @@ class PreferencesHelper(val context: Context) { fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false) + fun offlineMode() = flowPrefs.getBoolean(Keys.offlineMode, false) + fun filterDownloaded() = rxPrefs.getBoolean(Keys.filterDownloaded, false) fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false) 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 e4934d14ed..e11d382513 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 @@ -111,10 +111,8 @@ class LibraryPresenter( * @param map the map to filter. */ private fun applyFilters(map: LibraryMap): LibraryMap { - val filterDownloaded = preferences.filterDownloaded().getOrDefault() - + val filterDownloaded = preferences.offlineMode().get() || preferences.filterDownloaded().getOrDefault() val filterUnread = preferences.filterUnread().getOrDefault() - val filterCompleted = preferences.filterCompleted().getOrDefault() val filterFn: (LibraryItem) -> Boolean = f@{ item -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt index 5b035b87af..e7d04c58c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibrarySettingsSheet.kt @@ -96,7 +96,8 @@ class LibrarySettingsSheet( override val footer = Item.Separator() override fun initModels() { - downloaded.checked = preferences.filterDownloaded().getOrDefault() + downloaded.checked = preferences.offlineMode().get() || preferences.filterDownloaded().getOrDefault() + downloaded.enabled = !preferences.offlineMode().get() unread.checked = preferences.filterUnread().getOrDefault() completed.checked = preferences.filterCompleted().getOrDefault() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 575e3170fb..bb2640d1b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -155,6 +155,7 @@ class ChaptersController : NucleusController().extensionUpdatesCount().get()) - onClick { - router.pushController(ExtensionController().withFadeTransaction()) - } } - preference { - titleRes = R.string.label_download_queue - iconRes = R.drawable.ic_file_download_black_24dp - iconTint = tintColor - onClick { - router.pushController(DownloadController().withFadeTransaction()) + + preferenceCategory { + badgePreference { + titleRes = R.string.label_extensions + iconRes = R.drawable.ic_extension_24dp + iconTint = tintColor + setBadge(Injekt.get().extensionUpdatesCount().get()) + onClick { + router.pushController(ExtensionController().withFadeTransaction()) + } } - } - preference { - titleRes = R.string.label_migration - iconRes = R.drawable.ic_compare_arrows_black_24dp - iconTint = tintColor - onClick { - router.pushController(MigrationController().withFadeTransaction()) + preference { + titleRes = R.string.label_download_queue + iconRes = R.drawable.ic_file_download_black_24dp + iconTint = tintColor + onClick { + router.pushController(DownloadController().withFadeTransaction()) + } + } + preference { + titleRes = R.string.label_migration + iconRes = R.drawable.ic_compare_arrows_black_24dp + iconTint = tintColor + onClick { + router.pushController(MigrationController().withFadeTransaction()) + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt index 3559ce1b86..27a48a3365 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/ExtendedNavigationView.kt @@ -40,7 +40,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( /** * A checkbox. */ - open class Checkbox(val resTitle: Int, var checked: Boolean = false) : Item() + open class Checkbox(val resTitle: Int, var checked: Boolean = false, var enabled: Boolean = true) : Item() /** * A checkbox belonging to a group. The group must handle selections and restrictions. @@ -218,6 +218,7 @@ open class ExtendedNavigationView @JvmOverloads constructor( val item = items[position] as Item.CheckboxGroup holder.check.setText(item.resTitle) holder.check.isChecked = item.checked + holder.check.isEnabled = item.enabled } is MultiStateHolder -> { val item = items[position] as Item.MultiStateGroup diff --git a/app/src/main/res/drawable/ic_cloud_off_24dp.xml b/app/src/main/res/drawable/ic_cloud_off_24dp.xml new file mode 100644 index 0000000000..a71185fb78 --- /dev/null +++ b/app/src/main/res/drawable/ic_cloud_off_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dcfc4e3f4c..9f3fb74d6b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,6 +12,7 @@ More + Offline mode Settings Download queue Library