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 offlineMode = "pref_offline_mode"
const val filterDownloaded = "pref_filter_downloaded_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 offlineMode() = flowPrefs.getBoolean(Keys.offlineMode, false)
fun filterDownloaded() = rxPrefs.getBoolean(Keys.filterDownloaded, false)
fun filterUnread() = rxPrefs.getBoolean(Keys.filterUnread, false)

View File

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

View File

@ -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()
}

View File

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

View File

@ -366,11 +366,18 @@ class ChaptersPresenter(
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.
*/
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 eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.RootController
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.preference
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.system.getResourceColor
import eu.kanade.tachiyomi.util.system.openInBrowser
@ -29,29 +31,38 @@ class MoreController : SettingsController(), RootController {
val tintColor = context.getResourceColor(R.attr.colorAccent)
badgePreference {
titleRes = R.string.label_extensions
iconRes = R.drawable.ic_extension_24dp
switchPreference {
key = Keys.offlineMode
titleRes = R.string.label_offline_mode
iconRes = R.drawable.ic_cloud_off_24dp
iconTint = tintColor
setBadge(Injekt.get<PreferencesHelper>().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<PreferencesHelper>().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())
}
}
}

View File

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

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) -->
<string name="label_more">More</string>
<string name="label_offline_mode">Offline mode</string>
<string name="label_settings">Settings</string>
<string name="label_download_queue">Download queue</string>
<string name="label_library">Library</string>