From 3c56dc6cbab3b4dce01041690740056ff815709f Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 5 May 2020 19:54:27 -0400 Subject: [PATCH] Using helper functions for bottom sheet methods --- .../ui/download/DownloadBottomSheet.kt | 24 ++++++++------ .../ui/extension/ExtensionBottomSheet.kt | 9 +++-- .../ui/library/DisplayBottomSheet.kt | 6 ++-- .../tachiyomi/ui/library/LibraryController.kt | 29 ++++++++-------- .../ui/library/filter/FilterBottomSheet.kt | 15 +++++---- .../manga/design/PreMigrationController.kt | 3 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 33 ++++++++++--------- .../tachiyomi/ui/reader/ReaderChapterSheet.kt | 16 ++++----- .../ui/reader/ReaderColorFilterSheet.kt | 3 +- .../tachiyomi/ui/recents/RecentsController.kt | 11 ++++--- .../tachiyomi/ui/source/SourceController.kt | 24 +++++++------- .../ui/source/browse/SourceSearchSheet.kt | 3 +- .../util/view/BottomSheetExtensions.kt | 22 +++++++++++++ .../util/view/ControllerExtensions.kt | 6 +--- 14 files changed, 119 insertions(+), 85 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/view/BottomSheetExtensions.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt index 671054819e..1fbc52ef87 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadBottomSheet.kt @@ -13,7 +13,13 @@ import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.ui.extension.ExtensionDividerItemDecoration import eu.kanade.tachiyomi.ui.recents.RecentsController import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.hide +import eu.kanade.tachiyomi.util.view.isCollapsed +import eu.kanade.tachiyomi.util.view.isExpanded +import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.updateLayoutParams import kotlinx.android.synthetic.main.download_bottom_sheet.view.* @@ -65,17 +71,17 @@ class DownloadBottomSheet @JvmOverloads constructor( } } sheet_layout.setOnClickListener { - if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) { - sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + if (!sheetBehavior.isExpanded()) { + sheetBehavior?.expand() } else { - sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + sheetBehavior?.collapse() } } update() setInformationView() if (!controller.hasQueue()) { sheetBehavior?.isHideable = true - sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + sheetBehavior?.hide() } } @@ -205,9 +211,9 @@ class DownloadBottomSheet @JvmOverloads constructor( fun dismiss() { if (sheetBehavior?.isHideable == true) { - sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + sheetBehavior?.hide() } else { - sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + sheetBehavior?.collapse() } } @@ -215,13 +221,11 @@ class DownloadBottomSheet @JvmOverloads constructor( val hasQueue = presenter.downloadQueue.isNotEmpty() if (hasQueue) { sheetBehavior?.skipCollapsed = !hasQueue - if (sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN) sheetBehavior?.state = - BottomSheetBehavior.STATE_COLLAPSED + if (sheetBehavior.isHidden()) sheetBehavior?.collapse() } else { sheetBehavior?.isHideable = !hasQueue sheetBehavior?.skipCollapsed = !hasQueue - if (sheetBehavior?.state == BottomSheetBehavior.STATE_COLLAPSED) sheetBehavior?.state = - BottomSheetBehavior.STATE_HIDDEN + if (sheetBehavior.isCollapsed()) sheetBehavior?.hide() } controller.setPadding(!hasQueue) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt index 55065a57b9..d2598a5c22 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionBottomSheet.kt @@ -18,7 +18,10 @@ import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.source.SourceController import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.withFadeTransaction import kotlinx.android.synthetic.main.extensions_bottom_sheet.view.* @@ -72,11 +75,11 @@ ExtensionAdapter.OnButtonClickListener, } } sheet_layout.setOnClickListener { - if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) { - sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + if (!sheetBehavior.isExpanded()) { + sheetBehavior?.expand() fetchOnlineExtensionsIfNeeded() } else { - sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + sheetBehavior?.collapse() } } presenter.getExtensionUpdateCount() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt index 5a38e4e917..2494baf357 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/DisplayBottomSheet.kt @@ -13,6 +13,8 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.system.dpToPx +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.isCollapsed import eu.kanade.tachiyomi.util.view.setBottomEdge import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.util.view.visibleIf @@ -55,7 +57,7 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee override fun onStart() { super.onStart() sheetBehavior.skipCollapsed = true - sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + sheetBehavior.expand() } /** @@ -77,7 +79,7 @@ class DisplayBottomSheet(private val controller: LibraryController) : BottomShee private fun initGeneralPreferences() { display_group.bindToPreference(preferences.libraryLayout()) { controller.reattachAdapter() - if (sheetBehavior.state == BottomSheetBehavior.STATE_COLLAPSED) + if (sheetBehavior.isCollapsed()) dismiss() } uniform_grid.bindToPreference(preferences.uniformGrid()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 98325967a7..6e2c037d00 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -28,7 +28,6 @@ import com.afollestad.materialdialogs.list.listItemsSingleChoice import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.github.florent37.viewtooltip.ViewTooltip -import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.Snackbar import com.reddit.indicatorfastscroll.FastScrollItemIndicator @@ -61,9 +60,13 @@ import eu.kanade.tachiyomi.util.system.dpToPxEnd import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController +import eu.kanade.tachiyomi.util.view.collapse +import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.getItemView import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.hide +import eu.kanade.tachiyomi.util.view.isExpanded +import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setBackground import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener @@ -161,10 +164,10 @@ class LibraryController( val notAtTop = recycler.canScrollVertically(-1) if (notAtTop != elevate) elevateFunc(notAtTop) val order = getCategoryOrder() - if (filter_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_HIDDEN) { + if (!filter_bottom_sheet.sheetBehavior.isHidden()) { scrollDistance += abs(dy) if (scrollDistance > scrollDistanceTilHidden) { - filter_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + filter_bottom_sheet.sheetBehavior?.hide() scrollDistance = 0f } } else scrollDistance = 0f @@ -1009,9 +1012,8 @@ class LibraryController( override fun showSheet() { closeTip() when { - filter_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN -> filter_bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_COLLAPSED - filter_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED -> filter_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + filter_bottom_sheet.sheetBehavior.isHidden() -> filter_bottom_sheet.sheetBehavior?.collapse() + !filter_bottom_sheet.sheetBehavior.isExpanded() -> filter_bottom_sheet.sheetBehavior?.expand() else -> DisplayBottomSheet(this).show() } } @@ -1019,22 +1021,17 @@ class LibraryController( override fun toggleSheet() { closeTip() when { - filter_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN -> filter_bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_COLLAPSED - filter_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED -> filter_bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_EXPANDED - filter_bottom_sheet.sheetBehavior?.isHideable == true -> filter_bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_HIDDEN - else -> filter_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + filter_bottom_sheet.sheetBehavior.isHidden() -> filter_bottom_sheet.sheetBehavior?.collapse() + !filter_bottom_sheet.sheetBehavior.isExpanded() -> filter_bottom_sheet.sheetBehavior?.expand() + else -> filter_bottom_sheet.sheetBehavior?.hide() } } override fun sheetIsExpanded(): Boolean = false override fun handleSheetBack(): Boolean { - val sheetBehavior = BottomSheetBehavior.from(filter_bottom_sheet) - if (sheetBehavior.state != BottomSheetBehavior.STATE_COLLAPSED && sheetBehavior.state != BottomSheetBehavior.STATE_HIDDEN) { - sheetBehavior.state = BottomSheetBehavior.STATE_COLLAPSED + if (filter_bottom_sheet.sheetBehavior.isExpanded()) { + filter_bottom_sheet.sheetBehavior?.collapse() return true } return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt index 88660778de..ebcd4ab831 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/filter/FilterBottomSheet.kt @@ -15,7 +15,11 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.util.system.launchUI +import eu.kanade.tachiyomi.util.view.collapse +import eu.kanade.tachiyomi.util.view.hide import eu.kanade.tachiyomi.util.view.inflate +import eu.kanade.tachiyomi.util.view.isExpanded +import eu.kanade.tachiyomi.util.view.isHidden import eu.kanade.tachiyomi.util.view.updatePaddingRelative import eu.kanade.tachiyomi.util.view.visibleIf import kotlinx.android.synthetic.main.filter_bottom_sheet.view.* @@ -92,7 +96,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } }) if (preferences.hideFiltersAtStart().getOrDefault()) { - sheetBehavior?.state = BottomSheetBehavior.STATE_HIDDEN + sheetBehavior?.hide() } hide_filters.isChecked = preferences.hideFiltersAtStart().getOrDefault() hide_filters.setOnCheckedChangeListener { _, isChecked -> @@ -105,9 +109,8 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri } val activeFilters = hasActiveFiltersFromPref() - if (activeFilters && sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN && - sheetBehavior?.skipCollapsed == false) - sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (activeFilters && sheetBehavior.isHidden() && sheetBehavior?.skipCollapsed == false) + sheetBehavior?.collapse() post { updateRootPadding( @@ -117,7 +120,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri else -> 0f } ) - shadow.alpha = if (sheetBehavior?.state == BottomSheetBehavior.STATE_HIDDEN) 0f else 1f + shadow.alpha = if (sheetBehavior.isHidden()) 0f else 1f } createTags() @@ -151,7 +154,7 @@ class FilterBottomSheet @JvmOverloads constructor(context: Context, attrs: Attri val minHeight = sheetBehavior?.peekHeight ?: 0 val maxHeight = height val trueProgress = progress - ?: if (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) 1f else 0f + ?: if (sheetBehavior.isExpanded()) 1f else 0f val percent = (trueProgress * 100).roundToInt() val value = (percent * (maxHeight - minHeight) / 100) + minHeight val height = context.resources.getDimensionPixelSize(R.dimen.rounder_radius) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt index 88e38233a5..15943204b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/manga/design/PreMigrationController.kt @@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationListController import eu.kanade.tachiyomi.ui.migration.manga.process.MigrationProcedureConfig import eu.kanade.tachiyomi.util.view.applyWindowInsetsForController import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets +import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.marginBottom import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -81,7 +82,7 @@ class PreMigrationController(bundle: Bundle? = null) : BaseController(bundle), F ) if (bottomSheet != null) { val behavior: BottomSheetBehavior<*> = BottomSheetBehavior.from(bottomSheet) - behavior.state = BottomSheetBehavior.STATE_EXPANDED + behavior.expand() behavior.skipCollapsed = true } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index ae4f3fe3b1..6bc9ce06f0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -57,8 +57,11 @@ import eu.kanade.tachiyomi.util.system.hasSideNavBar import eu.kanade.tachiyomi.util.system.isBottomTappable import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast +import eu.kanade.tachiyomi.util.view.collapse import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.hide +import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.updateLayoutParams import eu.kanade.tachiyomi.util.view.updatePaddingRelative @@ -272,8 +275,8 @@ class ReaderActivity : BaseRxActivity(), else -> return super.onOptionsItemSelected(item) } bottomSheet?.show() - if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { + chapters_bottom_sheet.sheetBehavior?.collapse() } return true } @@ -283,8 +286,8 @@ class ReaderActivity : BaseRxActivity(), * delegated to the presenter. */ override fun onBackPressed() { - if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { + chapters_bottom_sheet.sheetBehavior?.collapse() return } presenter.onBackPressed() @@ -336,8 +339,7 @@ class ReaderActivity : BaseRxActivity(), // Set initial visibility setMenuVisibility(menuVisible) chapters_bottom_sheet.sheetBehavior?.isHideable = !menuVisible - if (!menuVisible) chapters_bottom_sheet.sheetBehavior?.state = - BottomSheetBehavior.STATE_HIDDEN + if (!menuVisible) chapters_bottom_sheet.sheetBehavior?.hide() val peek = chapters_bottom_sheet.sheetBehavior?.peekHeight ?: 30.dpToPx reader_layout.doOnApplyWindowInsets { v, insets, _ -> sheetManageNavColor = when { @@ -386,11 +388,11 @@ class ReaderActivity : BaseRxActivity(), systemUi?.show() appbar.visible() - if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { + if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { chapters_bottom_sheet.sheetBehavior?.isHideable = false } - if (chapters_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED && sheetManageNavColor) { - window.navigationBarColor = Color.TRANSPARENT // getResourceColor(R.attr.colorPrimaryDark) + if (!chapters_bottom_sheet.sheetBehavior.isExpanded() && sheetManageNavColor) { + window.navigationBarColor = Color.TRANSPARENT } if (animate) { if (!menuStickyVisible) { @@ -402,7 +404,7 @@ class ReaderActivity : BaseRxActivity(), }) appbar.startAnimation(toolbarAnimation) } - BottomSheetBehavior.from(chapters_bottom_sheet).state = BottomSheetBehavior.STATE_COLLAPSED + chapters_bottom_sheet.sheetBehavior?.collapse() } } else { systemUi?.hide() @@ -416,8 +418,7 @@ class ReaderActivity : BaseRxActivity(), }) appbar.startAnimation(toolbarAnimation) BottomSheetBehavior.from(chapters_bottom_sheet).isHideable = true - BottomSheetBehavior.from(chapters_bottom_sheet).state = - BottomSheetBehavior.STATE_HIDDEN + chapters_bottom_sheet.sheetBehavior?.hide() } else { appbar.gone() } @@ -553,8 +554,8 @@ class ReaderActivity : BaseRxActivity(), if (config?.showNewChapter == false) { systemUi?.show() } - } else if (chapters_bottom_sheet.shouldCollaspe && chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + } else if (chapters_bottom_sheet.shouldCollaspe && chapters_bottom_sheet.sheetBehavior.isExpanded()) { + chapters_bottom_sheet.sheetBehavior?.collapse() } if (chapters_bottom_sheet.selectedChapterId != page.chapter.chapter.id) { chapters_bottom_sheet.refreshList() @@ -572,8 +573,8 @@ class ReaderActivity : BaseRxActivity(), */ fun onPageLongTap(page: ReaderPage) { ReaderPageSheet(this, page).show() - if (chapters_bottom_sheet.sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - chapters_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (chapters_bottom_sheet.sheetBehavior.isExpanded()) { + chapters_bottom_sheet.sheetBehavior?.collapse() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt index b580da9806..5799083431 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderChapterSheet.kt @@ -17,6 +17,9 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.launchUI +import eu.kanade.tachiyomi.util.view.collapse +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.isExpanded import kotlinx.android.synthetic.main.reader_chapters_sheet.view.* import kotlin.math.max import kotlin.math.min @@ -39,18 +42,15 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr sheetBehavior = BottomSheetBehavior.from(this) chapters_button.setOnClickListener { - if (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (sheetBehavior.isExpanded()) { + sheetBehavior?.collapse() } else { - sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + sheetBehavior?.expand() } } post { - chapter_recycler.alpha = when (sheetBehavior?.state == BottomSheetBehavior.STATE_EXPANDED) { - true -> 1f - false -> 0f - } + chapter_recycler.alpha = if (sheetBehavior.isExpanded()) 1f else 0f } sheetBehavior?.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { @@ -112,7 +112,7 @@ class ReaderChapterSheet @JvmOverloads constructor(context: Context, attrs: Attr }) backgroundTintList = ColorStateList.valueOf( - if (sheetBehavior?.state != BottomSheetBehavior.STATE_EXPANDED) primary + if (!sheetBehavior.isExpanded()) primary else fullPrimary ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index 9c8937923e..4590db11c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.util.lang.plusAssign import eu.kanade.tachiyomi.util.system.hasSideNavBar +import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.setBottomEdge import eu.kanade.tachiyomi.util.view.setEdgeToEdge import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener @@ -157,7 +158,7 @@ class ReaderColorFilterSheet(activity: ReaderActivity) : BottomSheetDialog override fun onStart() { super.onStart() sheetBehavior?.skipCollapsed = true - sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + sheetBehavior?.expand() } override fun onDetachedFromWindow() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt index 8b114f1e5e..701da4b2b8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recents/RecentsController.kt @@ -39,6 +39,8 @@ import eu.kanade.tachiyomi.ui.recently_read.RemoveHistoryDialog import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.requestPermissionsSafe import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener @@ -201,7 +203,7 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), } if (showingDownloads) { - dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + dl_bottom_sheet.sheetBehavior?.expand() } setPadding(dl_bottom_sheet.sheetBehavior?.isHideable == true) requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 301) @@ -431,16 +433,15 @@ class RecentsController(bundle: Bundle? = null) : BaseController(bundle), override fun showSheet() { if (dl_bottom_sheet.sheetBehavior?.isHideable == false || hasQueue()) - dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + dl_bottom_sheet.sheetBehavior?.expand() } override fun toggleSheet() { if (showingDownloads) dl_bottom_sheet.dismiss() - else dl_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + else dl_bottom_sheet.sheetBehavior?.expand() } - override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior?.state == - BottomSheetBehavior.STATE_EXPANDED + override fun sheetIsExpanded(): Boolean = dl_bottom_sheet.sheetBehavior.isExpanded() override fun expandSearch() { if (showingDownloads) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt index dd038fe2ef..7fdb2d7618 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt @@ -33,6 +33,10 @@ import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.global_search.SourceSearchController import eu.kanade.tachiyomi.ui.source.latest.LatestUpdatesController import eu.kanade.tachiyomi.util.view.applyWindowInsetsForRootController +import eu.kanade.tachiyomi.util.view.collapse +import eu.kanade.tachiyomi.util.view.expand +import eu.kanade.tachiyomi.util.view.isCollapsed +import eu.kanade.tachiyomi.util.view.isExpanded import eu.kanade.tachiyomi.util.view.requestPermissionsSafe import eu.kanade.tachiyomi.util.view.scrollViewWith import eu.kanade.tachiyomi.util.view.setOnQueryTextChangeListener @@ -169,28 +173,27 @@ class SourceController : NucleusController(), }) if (showingExtensions) { - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + ext_bottom_sheet.sheetBehavior?.expand() } } override fun showSheet() { - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + ext_bottom_sheet.sheetBehavior?.expand() } override fun toggleSheet() { - if (ext_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) { - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (!ext_bottom_sheet.sheetBehavior.isCollapsed()) { + ext_bottom_sheet.sheetBehavior?.collapse() } else { - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_EXPANDED + ext_bottom_sheet.sheetBehavior?.expand() } } - override fun sheetIsExpanded(): Boolean = ext_bottom_sheet.sheetBehavior?.state == - BottomSheetBehavior.STATE_EXPANDED + override fun sheetIsExpanded(): Boolean = ext_bottom_sheet.sheetBehavior.isExpanded() override fun handleSheetBack(): Boolean { - if (ext_bottom_sheet.sheetBehavior?.state != BottomSheetBehavior.STATE_COLLAPSED) { - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (!ext_bottom_sheet.sheetBehavior.isCollapsed()) { + ext_bottom_sheet.sheetBehavior?.collapse() return true } return false @@ -279,8 +282,7 @@ class SourceController : NucleusController(), } override fun expandSearch() { - if (showingExtensions) - ext_bottom_sheet.sheetBehavior?.state = BottomSheetBehavior.STATE_COLLAPSED + if (showingExtensions) ext_bottom_sheet.sheetBehavior?.collapse() else activity?.toolbar?.menu?.findItem(R.id.action_search)?.expandActionView() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt index 2232a72405..0a5f65852d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/SourceSearchSheet.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.view.RecyclerWindowInsetsListener +import eu.kanade.tachiyomi.util.view.expand import eu.kanade.tachiyomi.util.view.setEdgeToEdge import kotlinx.android.synthetic.main.source_filter_sheet.* import uy.kohesive.injekt.injectLazy @@ -51,7 +52,7 @@ class SourceSearchSheet(activity: Activity) : sheetBehavior = BottomSheetBehavior.from(view.parent as ViewGroup) sheetBehavior.skipCollapsed = true - sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED + sheetBehavior.expand() setEdgeToEdge( activity, view, 50.dpToPx ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/BottomSheetExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/BottomSheetExtensions.kt new file mode 100644 index 0000000000..07fe46f7c5 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/BottomSheetExtensions.kt @@ -0,0 +1,22 @@ +package eu.kanade.tachiyomi.util.view + +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_COLLAPSED +import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDED +import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_HIDDEN + +fun BottomSheetBehavior<*>.hide() { + state = STATE_HIDDEN +} + +fun BottomSheetBehavior<*>.collapse() { + state = STATE_COLLAPSED +} + +fun BottomSheetBehavior<*>.expand() { + state = STATE_EXPANDED +} + +fun BottomSheetBehavior<*>?.isExpanded() = this?.state == STATE_EXPANDED +fun BottomSheetBehavior<*>?.isCollapsed() = this?.state == STATE_COLLAPSED +fun BottomSheetBehavior<*>?.isHidden() = this?.state == STATE_HIDDEN diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt index 3d9111fdb8..6740b2eb00 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ControllerExtensions.kt @@ -3,13 +3,11 @@ package eu.kanade.tachiyomi.util.view import android.animation.ValueAnimator import android.content.Context import android.content.pm.PackageManager -import android.os.Build import android.view.View import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.MATCH_PARENT import android.view.WindowInsets import android.view.inputmethod.InputMethodManager -import androidx.annotation.RequiresApi import androidx.appcompat.widget.SearchView import androidx.core.content.ContextCompat import androidx.core.math.MathUtils @@ -57,7 +55,6 @@ fun Controller.setOnQueryTextChangeListener( }) } -@RequiresApi(Build.VERSION_CODES.N_MR1) fun Controller.scrollViewWith( recycler: RecyclerView, padBottom: Boolean = false, @@ -81,11 +78,10 @@ fun Controller.scrollViewWith( } } val randomTag = Random.nextLong() - var headerHeight = 0 var lastY = 0f var fakeToolbarView: View? = null recycler.doOnApplyWindowInsets { view, insets, _ -> - headerHeight = insets.systemWindowInsetTop + appBarHeight + val headerHeight = insets.systemWindowInsetTop + appBarHeight if (!customPadding) view.updatePaddingRelative( top = headerHeight, bottom = if (padBottom) insets.systemWindowInsetBottom else view.paddingBottom