From cf99446a12f894d6b4a513aaf668520f52b40170 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 19 May 2021 23:18:24 -0400 Subject: [PATCH] Adjust tablet layout (closes #5113) --- .../tachiyomi/ui/browse/BrowseController.kt | 4 +- .../tachiyomi/ui/library/LibraryController.kt | 4 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 36 ++++---- .../tachiyomi/ui/manga/MangaController.kt | 2 +- .../main/res/layout-sw600dp/main_activity.xml | 84 ++++++++++++++++--- app/src/main/res/layout/main_activity.xml | 61 +++++++++++++- 6 files changed, 155 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt index deaf2f1319..3107fe5a3c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/BrowseController.kt @@ -70,7 +70,7 @@ class BrowseController : override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { - (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.apply { + (activity as? MainActivity)?.binding?.tabs?.apply { setupWithViewPager(binding.pager) // Show badge on tab for extension updates @@ -92,7 +92,7 @@ class BrowseController : } fun setExtensionUpdateBadge() { - (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.apply { + (activity as? MainActivity)?.binding?.tabs?.apply { val updates = preferences.extensionUpdatesCount().get() if (updates > 0) { val badge: BadgeDrawable? = getTabAt(1)?.orCreateBadge 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 2909574be8..18023a2351 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 @@ -218,7 +218,7 @@ class LibraryController( override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { super.onChangeStarted(handler, type) if (type.isEnter) { - (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.setupWithViewPager(binding.libraryPager) + (activity as? MainActivity)?.binding?.tabs?.setupWithViewPager(binding.libraryPager) presenter.subscribeLibrary() } } @@ -297,7 +297,7 @@ class LibraryController( // Delay the scroll position to allow the view to be properly measured. view.post { if (isAttached) { - (activity as? MainActivity)?.binding?.toolbarLayout?.tabs?.setScrollPosition(binding.libraryPager.currentItem, 0f, true) + (activity as? MainActivity)?.binding?.tabs?.setScrollPosition(binding.libraryPager.currentItem, 0f, true) } } 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 5063e1c310..589faac510 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 @@ -96,11 +96,11 @@ class MainActivity : BaseViewBindingActivity() { } setContentView(binding.root) - setSupportActionBar(binding.toolbarLayout.toolbar) + setSupportActionBar(binding.toolbar) // Draw edge-to-edge WindowCompat.setDecorFitsSystemWindows(window, false) - binding.toolbarLayout.appbar.applyInsetter { + binding.appbar.applyInsetter { type(navigationBars = true, statusBars = true) { padding(left = true, top = true, right = true) } @@ -131,13 +131,13 @@ class MainActivity : BaseViewBindingActivity() { insets } - tabAnimator = ViewHeightAnimator(binding.toolbarLayout.tabs, 0L) + tabAnimator = ViewHeightAnimator(binding.tabs, 0L) if (binding.bottomNav != null) { bottomNavAnimator = ViewHeightAnimator(binding.bottomNav!!) // If bottom nav is hidden, make it visible again when the app bar is expanded - binding.toolbarLayout.appbar.addOnOffsetChangedListener( + binding.appbar.addOnOffsetChangedListener( AppBarLayout.OnOffsetChangedListener { _, verticalOffset -> if (verticalOffset == 0) { showNav(visible = true) @@ -186,7 +186,7 @@ class MainActivity : BaseViewBindingActivity() { } } - binding.toolbarLayout.toolbar.setNavigationOnClickListener { + binding.toolbar.setNavigationOnClickListener { onBackPressed() } @@ -227,13 +227,13 @@ class MainActivity : BaseViewBindingActivity() { .launchIn(lifecycleScope) preferences.downloadedOnly() - .asImmediateFlow { binding.toolbarLayout.downloadedOnly.isVisible = it } + .asImmediateFlow { binding.downloadedOnly.isVisible = it } .launchIn(lifecycleScope) preferences.incognitoMode().asFlow() .drop(1) .onEach { - binding.toolbarLayout.incognitoMode.isVisible = it + binding.incognitoMode.isVisible = it // Close BrowseSourceController and its MangaController child when incognito mode is disabled if (!it) { @@ -355,7 +355,7 @@ class MainActivity : BaseViewBindingActivity() { // Binding sometimes isn't actually instantiated yet somehow nav.setOnItemSelectedListener(null) - binding?.toolbarLayout?.toolbar.setNavigationOnClickListener(null) + binding?.toolbar.setNavigationOnClickListener(null) } override fun onBackPressed() { @@ -408,7 +408,7 @@ class MainActivity : BaseViewBindingActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1) // Always show appbar again when changing controllers - binding.toolbarLayout.appbar.setExpanded(true) + binding.appbar.setExpanded(true) if ((from == null || from is RootController) && to !is RootController) { showNav(visible = false, collapse = true) @@ -419,14 +419,14 @@ class MainActivity : BaseViewBindingActivity() { } if (from is TabbedController) { - from.cleanupTabs(binding.toolbarLayout.tabs) + from.cleanupTabs(binding.tabs) } if (to is TabbedController) { tabAnimator.expand() - to.configureTabs(binding.toolbarLayout.tabs) + to.configureTabs(binding.tabs) } else { tabAnimator.collapse() - binding.toolbarLayout.tabs.setupWithViewPager(null) + binding.tabs.setupWithViewPager(null) } if (from is FabController) { @@ -440,13 +440,13 @@ class MainActivity : BaseViewBindingActivity() { when (to) { is NoToolbarElevationController -> { - binding.toolbarLayout.appbar.disableElevation() + binding.appbar.disableElevation() } is ToolbarLiftOnScrollController -> { - binding.toolbarLayout.appbar.enableElevation(true) + binding.appbar.enableElevation(true) } else -> { - binding.toolbarLayout.appbar.enableElevation(false) + binding.appbar.enableElevation(false) } } } @@ -489,16 +489,16 @@ class MainActivity : BaseViewBindingActivity() { */ fun fixViewToBottom(view: View) { val listener = AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset -> - val maxAbsOffset = appBarLayout.measuredHeight - binding.toolbarLayout.tabs.measuredHeight + val maxAbsOffset = appBarLayout.measuredHeight - binding.tabs.measuredHeight view.translationY = -maxAbsOffset - verticalOffset.toFloat() + appBarLayout.marginTop } - binding.toolbarLayout.appbar.addOnOffsetChangedListener(listener) + binding.appbar.addOnOffsetChangedListener(listener) fixedViewsToBottom[view] = listener } fun clearFixViewToBottom(view: View) { val listener = fixedViewsToBottom.remove(view) - binding.toolbarLayout.appbar.removeOnOffsetChangedListener(listener) + binding.appbar.removeOnOffsetChangedListener(listener) } private fun setBottomNavBehaviorOnScroll() { 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 8c8a9a26d3..8be864f0af 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 @@ -277,7 +277,7 @@ class MangaController : else -> min(binding.recycler.computeVerticalScrollOffset(), 255) } - (activity as? MainActivity)?.binding?.toolbarLayout?.toolbar?.setTitleTextColor( + (activity as? MainActivity)?.binding?.toolbar?.setTitleTextColor( Color.argb( calculatedAlpha, toolbarTextColor.red, diff --git a/app/src/main/res/layout-sw600dp/main_activity.xml b/app/src/main/res/layout-sw600dp/main_activity.xml index 8d794d3509..de0503c208 100644 --- a/app/src/main/res/layout-sw600dp/main_activity.xml +++ b/app/src/main/res/layout-sw600dp/main_activity.xml @@ -1,41 +1,105 @@ - - + android:layout_height="match_parent"> + + + + + + + + + + + + + + + + + + + + + app:layout_constraintTop_toBottomOf="@+id/tabs" /> diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 617cf933c3..5e21c8fae7 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -1,14 +1,69 @@ - + + + + + + + + + + + + + + + + + + +