From 1dac7c1ed210c1f365cbc99b19139f8e425a4159 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 10 Jul 2021 13:41:21 -0400 Subject: [PATCH] Using nav rail only for landscape (phone + tablet) Tablet layout will extend the toolbar past the nav rail Phone layout will contain the toolbar inside the controller's bounds and is collaspable --- .../controller/OneWayFadeChangeHandler.kt | 5 +- .../tachiyomi/ui/library/LibraryController.kt | 7 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 7 +- .../ui/setting/SettingsGeneralController.kt | 4 +- .../util/view/ControllerExtensions.kt | 18 +- .../main/res/layout-land/main_activity.xml | 183 +++++++++++++++++ .../main_activity.xml | 3 +- .../res/layout-sw600dp-port/main_activity.xml | 192 ++++++++++++++++++ 8 files changed, 399 insertions(+), 20 deletions(-) create mode 100644 app/src/main/res/layout-land/main_activity.xml rename app/src/main/res/{layout-sw600dp => layout-sw600dp-land}/main_activity.xml (99%) create mode 100644 app/src/main/res/layout-sw600dp-port/main_activity.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt index 76e929df4f..a0d547ffe3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/OneWayFadeChangeHandler.kt @@ -3,11 +3,11 @@ package eu.kanade.tachiyomi.ui.base.controller import android.animation.Animator import android.animation.AnimatorSet import android.animation.ObjectAnimator +import android.content.res.Configuration import android.view.View import android.view.ViewGroup import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.changehandler.FadeChangeHandler -import eu.kanade.tachiyomi.util.system.isTablet /** * A variation of [FadeChangeHandler] that only fades in. @@ -34,8 +34,9 @@ class OneWayFadeChangeHandler : FadeChangeHandler { animator.play(ObjectAnimator.ofFloat(to, View.ALPHA, start, 1f)) } + val hasSideNav = container.context.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE if (from != null && (!isPush || removesFromViewOnPush())) { - if (!container.context.isTablet()) { + if (!hasSideNav) { animator.play(ObjectAnimator.ofFloat(from, View.ALPHA, 0f)) } else { container.removeView(from) 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 c6aecc1053..363eb39d84 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 @@ -82,7 +82,6 @@ import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.util.moveCategories import eu.kanade.tachiyomi.util.system.dpToPx -import eu.kanade.tachiyomi.util.system.getBottomGestureInsets import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.isImeVisible import eu.kanade.tachiyomi.util.system.launchUI @@ -308,13 +307,13 @@ class LibraryController( binding.filterBottomSheet.filterBottomSheet.updatePaddingRelative( bottom = max( (-pad).toInt(), - view?.rootWindowInsets?.getBottomGestureInsets() ?: 0 + view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 ) ) val padding = max( (-pad).toInt(), - view?.rootWindowInsets?.getBottomGestureInsets() ?: 0 + view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 ) binding.filterBottomSheet.filterBottomSheet.sheetBehavior?.peekHeight = 60.dpToPx + padding updateHopperY() @@ -323,7 +322,7 @@ class LibraryController( } } else { binding.filterBottomSheet.filterBottomSheet.updatePaddingRelative( - bottom = view?.rootWindowInsets?.getBottomGestureInsets() ?: 0 + bottom = view?.rootWindowInsets?.systemWindowInsetBottom ?: 0 ) updateHopperY() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 101e7826b7..3a4e1b1da7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -73,7 +73,6 @@ import eu.kanade.tachiyomi.util.system.contextCompatDrawable import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.hasSideNavBar import eu.kanade.tachiyomi.util.system.isBottomTappable -import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.util.system.launchUI import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets @@ -237,6 +236,10 @@ open class MainActivity : BaseActivity(), DownloadServiceLi left = insets.systemWindowInsetLeft, right = insets.systemWindowInsetRight ) + binding.sideNav?.updateLayoutParams { + topMargin = insets.systemWindowInsetTop + topMargin = insets.systemWindowInsetBottom + } binding.bottomView?.isVisible = insets.systemWindowInsetBottom > 0 binding.bottomView?.updateLayoutParams { height = insets.systemWindowInsetBottom @@ -793,7 +796,7 @@ open class MainActivity : BaseActivity(), DownloadServiceLi drawerArrow?.progress = 1f nav.visibility = if (!hideBottomNav) View.VISIBLE else nav.visibility - if (isTablet()) { + if (nav == binding.sideNav) { nav.isVisible = !hideBottomNav nav.alpha = 1f } else { 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 2552e8bf1a..db26a894a8 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 @@ -8,11 +8,11 @@ import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn +import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.appDelegateNightMode import eu.kanade.tachiyomi.util.system.getPrefTheme import eu.kanade.tachiyomi.util.system.isInNightMode -import eu.kanade.tachiyomi.util.system.isTablet import kotlinx.coroutines.flow.launchIn import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys @@ -88,7 +88,7 @@ class SettingsGeneralController : SettingsController() { ) entryRange = 0..2 defaultValue = 0 - isVisible = activity?.isTablet() == true + isVisible = (activity as? MainActivity)?.binding?.sideNav != null } preferenceCategory { 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 e035b10e34..cea447b626 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 @@ -5,6 +5,7 @@ import android.animation.ValueAnimator import android.content.Context import android.content.Intent import android.content.pm.PackageManager +import android.content.res.Configuration import android.os.Build import android.os.Environment import android.provider.Settings @@ -39,7 +40,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.util.system.toast -import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import kotlin.math.abs import kotlin.random.Random @@ -186,8 +186,8 @@ fun Controller.scrollViewWith( val tabBarHeight = 48.dpToPx activityBinding?.appBar?.y = 0f activityBinding?.tabsFrameLayout?.elevation = 0f - val isTabletWithTabs = recycler.context.isTablet() && includeTabView - activityBinding?.tabShadow?.isVisible = isTabletWithTabs + val isSideNavWithTabs = activityBinding?.sideNav != null && includeTabView && recycler.context.isTablet() + activityBinding?.tabShadow?.isVisible = isSideNavWithTabs val attrsArray = intArrayOf(R.attr.actionBarSize) val array = recycler.context.obtainStyledAttributes(attrsArray) var appBarHeight = ( @@ -243,13 +243,13 @@ fun Controller.scrollViewWith( liftOnScroll.invoke(el) } else { elevationAnim?.cancel() - if (isTabletWithTabs && el) { + if (isSideNavWithTabs && el) { activityBinding?.tabShadow?.isVisible = true } val floatingBar = (this as? FloatingSearchInterface)?.showFloatingBar() == true && !includeTabView if (floatingBar) { - if (isTabletWithTabs) { + if (isSideNavWithTabs) { activityBinding?.tabShadow?.alpha = 0f } else { activityBinding?.appBar?.elevation = 0f @@ -257,7 +257,7 @@ fun Controller.scrollViewWith( return@f } elevationAnim = ValueAnimator.ofFloat( - if (isTabletWithTabs) { + if (isSideNavWithTabs) { (activityBinding?.tabShadow?.alpha ?: 0f) * 100 } else { activityBinding?.appBar?.elevation ?: 0f @@ -265,7 +265,7 @@ fun Controller.scrollViewWith( if (el) 15f else 0f ) elevationAnim?.addUpdateListener { valueAnimator -> - if (isTabletWithTabs) { + if (isSideNavWithTabs) { activityBinding?.tabShadow?.alpha = valueAnimator.animatedValue as Float / 100 } else { activityBinding?.appBar?.elevation = valueAnimator.animatedValue as Float @@ -287,7 +287,7 @@ fun Controller.scrollViewWith( super.onChangeStart(controller, changeHandler, changeType) isInView = changeType.isEnter if (changeType.isEnter) { - activityBinding?.tabShadow?.isVisible = isTabletWithTabs + activityBinding?.tabShadow?.isVisible = isSideNavWithTabs elevateFunc(elevate) if (fakeToolbarView?.parent != null) { val parent = fakeToolbarView?.parent as? ViewGroup ?: return @@ -353,7 +353,7 @@ fun Controller.scrollViewWith( recycler.post { elevateFunc(recycler.canScrollVertically(-1)) } - val isTablet = recycler.context.isTablet() + val isTablet = recycler.context.isTablet() && recycler.context.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE recycler.addOnScrollListener( object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { diff --git a/app/src/main/res/layout-land/main_activity.xml b/app/src/main/res/layout-land/main_activity.xml new file mode 100644 index 0000000000..f7ec0f74b0 --- /dev/null +++ b/app/src/main/res/layout-land/main_activity.xml @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-sw600dp/main_activity.xml b/app/src/main/res/layout-sw600dp-land/main_activity.xml similarity index 99% rename from app/src/main/res/layout-sw600dp/main_activity.xml rename to app/src/main/res/layout-sw600dp-land/main_activity.xml index 8942d76f87..6961920418 100644 --- a/app/src/main/res/layout-sw600dp/main_activity.xml +++ b/app/src/main/res/layout-sw600dp-land/main_activity.xml @@ -48,7 +48,8 @@ android:layout_width="6dp" android:layout_height="0dp" android:layout_gravity="bottom" - android:alpha="0.13" + android:alpha="0.04" + android:rotation="180" android:translationZ="0dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="@id/side_nav" diff --git a/app/src/main/res/layout-sw600dp-port/main_activity.xml b/app/src/main/res/layout-sw600dp-port/main_activity.xml new file mode 100644 index 0000000000..361a931102 --- /dev/null +++ b/app/src/main/res/layout-sw600dp-port/main_activity.xml @@ -0,0 +1,192 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +