Add offline mode (forced download filters; closes #2902)

This commit is contained in:
arkon 2020-04-19 15:30:55 -04:00
parent 9c820fcca1
commit 5bc77fc6e8
10 changed files with 59 additions and 26 deletions

View File

@ -99,6 +99,8 @@ object PreferenceKeys {
const val libraryUpdatePrioritization = "library_update_prioritization" const val libraryUpdatePrioritization = "library_update_prioritization"
const val offlineMode = "pref_offline_mode"
const val filterDownloaded = "pref_filter_downloaded_key" const val filterDownloaded = "pref_filter_downloaded_key"
const val filterUnread = "pref_filter_unread_key" const val filterUnread = "pref_filter_unread_key"

View File

@ -183,6 +183,8 @@ class PreferencesHelper(val context: Context) {
fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false) fun downloadBadge() = rxPrefs.getBoolean(Keys.downloadBadge, false)
fun offlineMode() = flowPrefs.getBoolean(Keys.offlineMode, false)
fun filterDownloaded() = rxPrefs.getBoolean(Keys.filterDownloaded, false) fun filterDownloaded() = rxPrefs.getBoolean(Keys.filterDownloaded, false)
fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false) fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false)

View File

@ -111,10 +111,8 @@ class LibraryPresenter(
* @param map the map to filter. * @param map the map to filter.
*/ */
private fun applyFilters(map: LibraryMap): LibraryMap { 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 filterUnread = preferences.filterUnread().getOrDefault()
val filterCompleted = preferences.filterCompleted().getOrDefault() val filterCompleted = preferences.filterCompleted().getOrDefault()
val filterFn: (LibraryItem) -> Boolean = f@{ item -> val filterFn: (LibraryItem) -> Boolean = f@{ item ->

View File

@ -96,7 +96,8 @@ class LibrarySettingsSheet(
override val footer = Item.Separator() override val footer = Item.Separator()
override fun initModels() { 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() unread.checked = preferences.filterUnread().getOrDefault()
completed.checked = preferences.filterCompleted().getOrDefault() completed.checked = preferences.filterCompleted().getOrDefault()
} }

View File

@ -155,6 +155,7 @@ class ChaptersController : NucleusController<ChaptersControllerBinding, Chapters
menuFilterRead.isChecked = presenter.onlyRead() menuFilterRead.isChecked = presenter.onlyRead()
menuFilterUnread.isChecked = presenter.onlyUnread() menuFilterUnread.isChecked = presenter.onlyUnread()
menuFilterDownloaded.isChecked = presenter.onlyDownloaded() menuFilterDownloaded.isChecked = presenter.onlyDownloaded()
menuFilterDownloaded.isEnabled = !presenter.isOfflineMode()
menuFilterBookmarked.isChecked = presenter.onlyBookmarked() menuFilterBookmarked.isChecked = presenter.onlyBookmarked()
val filterSet = presenter.onlyRead() || presenter.onlyUnread() || presenter.onlyDownloaded() || presenter.onlyBookmarked() val filterSet = presenter.onlyRead() || presenter.onlyUnread() || presenter.onlyDownloaded() || presenter.onlyBookmarked()

View File

@ -366,11 +366,18 @@ class ChaptersPresenter(
refreshChapters() refreshChapters()
} }
/**
* Whether offline mode is enabled (i.e. force only downloaded content).
*/
fun isOfflineMode(): Boolean {
return preferences.offlineMode().get()
}
/** /**
* Whether the display only downloaded filter is enabled. * Whether the display only downloaded filter is enabled.
*/ */
fun onlyDownloaded(): Boolean { fun onlyDownloaded(): Boolean {
return manga.downloadedFilter == Manga.SHOW_DOWNLOADED return isOfflineMode() || manga.downloadedFilter == Manga.SHOW_DOWNLOADED
} }
/** /**

View File

@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.more
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.RootController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
@ -16,6 +17,7 @@ import eu.kanade.tachiyomi.util.preference.iconTint
import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.onClick
import eu.kanade.tachiyomi.util.preference.preference import eu.kanade.tachiyomi.util.preference.preference
import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.preferenceCategory
import eu.kanade.tachiyomi.util.preference.switchPreference
import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.preference.titleRes
import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.openInBrowser
@ -29,6 +31,14 @@ class MoreController : SettingsController(), RootController {
val tintColor = context.getResourceColor(R.attr.colorAccent) val tintColor = context.getResourceColor(R.attr.colorAccent)
switchPreference {
key = Keys.offlineMode
titleRes = R.string.label_offline_mode
iconRes = R.drawable.ic_cloud_off_24dp
iconTint = tintColor
}
preferenceCategory {
badgePreference { badgePreference {
titleRes = R.string.label_extensions titleRes = R.string.label_extensions
iconRes = R.drawable.ic_extension_24dp iconRes = R.drawable.ic_extension_24dp
@ -54,6 +64,7 @@ class MoreController : SettingsController(), RootController {
router.pushController(MigrationController().withFadeTransaction()) router.pushController(MigrationController().withFadeTransaction())
} }
} }
}
preferenceCategory { preferenceCategory {
preference { preference {

View File

@ -40,7 +40,7 @@ open class ExtendedNavigationView @JvmOverloads constructor(
/** /**
* A checkbox. * 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. * 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 val item = items[position] as Item.CheckboxGroup
holder.check.setText(item.resTitle) holder.check.setText(item.resTitle)
holder.check.isChecked = item.checked holder.check.isChecked = item.checked
holder.check.isEnabled = item.enabled
} }
is MultiStateHolder -> { is MultiStateHolder -> {
val item = items[position] as Item.MultiStateGroup val item = items[position] as Item.MultiStateGroup

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4c-1.48,0 -2.85,0.43 -4.01,1.17l1.46,1.46C10.21,6.23 11.08,6 12,6c3.04,0 5.5,2.46 5.5,5.5v0.5H19c1.66,0 3,1.34 3,3 0,1.13 -0.64,2.11 -1.56,2.62l1.45,1.45C23.16,18.16 24,16.68 24,15c0,-2.64 -2.05,-4.78 -4.65,-4.96zM3,5.27l2.75,2.74C2.56,8.15 0,10.77 0,14c0,3.31 2.69,6 6,6h11.73l2,2L21,20.73 4.27,4 3,5.27zM7.73,10l8,8H6c-2.21,0 -4,-1.79 -4,-4s1.79,-4 4,-4h1.73z"
android:fillColor="#000000"/>
</vector>

View File

@ -12,6 +12,7 @@
<!-- Activities and fragments labels (toolbar title) --> <!-- Activities and fragments labels (toolbar title) -->
<string name="label_more">More</string> <string name="label_more">More</string>
<string name="label_offline_mode">Offline mode</string>
<string name="label_settings">Settings</string> <string name="label_settings">Settings</string>
<string name="label_download_queue">Download queue</string> <string name="label_download_queue">Download queue</string>
<string name="label_library">Library</string> <string name="label_library">Library</string>