From 1b52acdad7771dcd4de0d4f8fe4985db8b1d9182 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 23 May 2021 13:05:45 -0400 Subject: [PATCH] Hide irrelevant settings on tablets --- .../tachiyomi/ui/manga/MangaController.kt | 30 +++++++++---------- .../ui/setting/SettingsGeneralController.kt | 11 ++++--- .../ui/setting/SettingsLibraryController.kt | 11 ++++--- .../util/system/ContextExtensions.kt | 7 +++++ 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt index db4dafd80..ccdc4fa85 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt @@ -237,6 +237,18 @@ class MangaController : it.scrollEvents() .onEach { updateToolbarTitleAlpha() } .launchIn(viewScope) + + // Skips directly to chapters list if navigated to from the library + it.post { + if (!fromSource && preferences.jumpToChapters()) { + (it.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0) + } + + // Delayed in case we need to jump to chapters + it.post { + updateToolbarTitleAlpha() + } + } } // Tablet layout binding.infoRecycler?.let { @@ -248,19 +260,7 @@ class MangaController : chaptersAdapter?.fastScroller = binding.fastScroller - actionFabScrollListener = actionFab?.shrinkOnScroll(chaptersRecycler) - - // Skips directly to chapters list if navigated to from the library - chaptersRecycler.post { - if (!fromSource && preferences.jumpToChapters()) { - (chaptersRecycler.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(1, 0) - } - - // Delayed in case we need to jump to chapters - binding.fullRecycler?.post { - updateToolbarTitleAlpha() - } - } + actionFabScrollListener = actionFab?.shrinkOnScroll(chapterRecycler) binding.swipeRefresh.refreshes() .onEach { @@ -340,7 +340,7 @@ class MangaController : override fun cleanupFab(fab: ExtendedFloatingActionButton) { fab.setOnClickListener(null) - actionFabScrollListener?.let { binding.fullRecycler?.removeOnScrollListener(it) } + actionFabScrollListener?.let { chapterRecycler.removeOnScrollListener(it) } actionFab = null } @@ -1103,7 +1103,7 @@ class MangaController : // Tracker sheet - end - private val chaptersRecycler: RecyclerView + private val chapterRecycler: RecyclerView get() = binding.fullRecycler ?: binding.chaptersRecycler!! companion object { 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 62e21c6d0..7eddcca91 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 @@ -17,6 +17,7 @@ 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.LocaleHelper +import eu.kanade.tachiyomi.util.system.isTablet import kotlinx.coroutines.flow.launchIn import java.util.Date import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys @@ -45,10 +46,12 @@ class SettingsGeneralController : SettingsController() { titleRes = R.string.pref_confirm_exit defaultValue = false } - switchPreference { - key = Keys.hideBottomBar - titleRes = R.string.pref_hide_bottom_bar_on_scroll - defaultValue = true + if (!context.isTablet()) { + switchPreference { + key = Keys.hideBottomBar + titleRes = R.string.pref_hide_bottom_bar_on_scroll + defaultValue = true + } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 3f8baf1bc..70915f8e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -28,6 +28,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes +import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.widget.MinMaxNumberPicker import eu.kanade.tachiyomi.widget.materialdialogs.QuadStateCheckBox import eu.kanade.tachiyomi.widget.materialdialogs.listItemsQuadStateMultiChoice @@ -75,10 +76,12 @@ class SettingsLibraryController : SettingsController() { } .launchIn(viewScope) } - switchPreference { - key = Keys.jumpToChapters - titleRes = R.string.pref_jump_to_chapters - defaultValue = false + if (!context.isTablet()) { + switchPreference { + key = Keys.jumpToChapters + titleRes = R.string.pref_jump_to_chapters + defaultValue = false + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index 3344e9817..0cb74bb9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -258,3 +258,10 @@ fun Context.createFileInCacheDir(name: String): File { file.createNewFile() return file } + +/** + * We consider anything with a width of >= 600dp as a tablet, i.e. with layouts in layout-sw600dp. + */ +fun Context.isTablet(): Boolean { + return resources.configuration.screenWidthDp >= 600 +}