From d72c51c8dd778ee14b3fc7936a43718fefe76cd8 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 2 May 2020 11:12:10 -0400 Subject: [PATCH] Hide app/nav bars on scroll --- .../source/browse/BrowseSourceController.kt | 3 ++ .../ui/category/CategoryController.kt | 3 ++ .../ui/download/DownloadController.kt | 3 ++ .../kanade/tachiyomi/ui/main/MainActivity.kt | 35 +++++++++++++++++-- .../ui/manga/chapter/ChaptersController.kt | 2 ++ app/src/main/res/layout/main_activity.xml | 13 ++++--- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index bc0b6ede55..73ec958de3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -31,6 +31,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog +import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.system.connectivityManager @@ -157,6 +158,8 @@ open class BrowseSourceController(bundle: Bundle) : filterSheet?.setOnDismissListener { binding.fabFilter.visible() } binding.fabFilter.setOnClickListener { filterSheet?.show() } + + binding.fabFilter.offsetFabAppbarHeight(activity!!) binding.fabFilter.visible() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index 55d5448cae..5db3fc623d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.databinding.CategoriesControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -93,6 +94,8 @@ class CategoryController : CategoryCreateDialog(this@CategoryController).showDialog(router, null) } .launchIn(scope) + + binding.fab.offsetFabAppbarHeight(activity!!) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 5e0d3c5303..be08c93bb4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.databinding.DownloadControllerBinding import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight import java.util.HashMap import java.util.concurrent.TimeUnit import kotlinx.coroutines.flow.launchIn @@ -92,6 +93,8 @@ class DownloadController : } .launchIn(scope) + binding.fab.offsetFabAppbarHeight(activity!!) + // Subscribe to changes DownloadService.runningRelay .observeOn(AndroidSchedulers.mainThread()) 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 daa1e265f2..7448d02bad 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 @@ -1,15 +1,21 @@ package eu.kanade.tachiyomi.ui.main +import android.app.Activity import android.app.SearchManager import android.content.Intent import android.os.Bundle +import android.view.View import android.view.ViewGroup import android.widget.Toast +import androidx.coordinatorlayout.widget.CoordinatorLayout import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction +import com.google.android.material.appbar.AppBarLayout +import com.google.android.material.behavior.HideBottomViewOnScrollBehavior +import com.google.android.material.tabs.TabLayout import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver @@ -318,11 +324,21 @@ class MainActivity : BaseActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(router.backstackSize != 1) + // Always show appbar again when changing controllers + binding.appbar.setExpanded(true) + if ((from == null || from is RootController) && to !is RootController) { bottomNavAnimator.collapse() } - if (to is RootController && from !is RootController) { - bottomNavAnimator.expand() + if (to is RootController) { + if (from !is RootController) { + bottomNavAnimator.expand() + } + + // Always show bottom nav again when returning to a RootController + val layoutParams = binding.bottomNav.layoutParams as CoordinatorLayout.LayoutParams + val bottomViewNavigationBehavior = layoutParams.behavior as HideBottomViewOnScrollBehavior + bottomViewNavigationBehavior.slideUp(binding.bottomNav) } if (from is TabbedController) { @@ -358,3 +374,18 @@ class MainActivity : BaseActivity() { const val INTENT_SEARCH_FILTER = "filter" } } + +/** + * Used to manually offset a FAB within child views that might be cut off due to the collapsing + * AppBarLayout. + */ +fun View.offsetFabAppbarHeight(activity: Activity) { + val appbar: AppBarLayout = activity.findViewById(R.id.appbar) + val tabs: TabLayout = activity.findViewById(R.id.tabs) + appbar.addOnOffsetChangedListener( + AppBarLayout.OnOffsetChangedListener { appBarLayout, verticalOffset -> + val maxAbsOffset = appBarLayout.measuredHeight - tabs.measuredHeight + translationY = -maxAbsOffset - verticalOffset.toFloat() + } + ) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 00e2a4a405..d95a10e3c9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -24,6 +24,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.databinding.ChaptersControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController +import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.getResourceColor @@ -120,6 +121,7 @@ class ChaptersController : } .launchIn(scope) + binding.fab.offsetFabAppbarHeight(activity!!) binding.fab.shrinkOnScroll(binding.recycler) } diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index cbbbabfc4a..300706be68 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -1,5 +1,5 @@ - + android:theme="?attr/actionBarTheme" + app:layout_scrollFlags="scroll|enterAlways|snap" /> + android:layout_height="match_parent" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - +