From 9162246b8b063a0655e79b6158707e152df3765f Mon Sep 17 00:00:00 2001 From: OxygenCobalt Date: Mon, 23 Aug 2021 19:32:33 -0600 Subject: [PATCH] home: fix appbar issues Fix two annoying appbar issues: - Appbar will collapse if the navigation sequence is too fast - Tab ripple would paint over the indicator unless the ripple was unbounded [???] --- app/build.gradle | 2 - .../org/oxycblt/auxio/home/HomeFragment.kt | 37 +++++++++---------- app/src/main/res/layout/fragment_home.xml | 8 +++- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 602d4f68d..1cc60bd16 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,8 +101,6 @@ dependencies { // Material implementation "com.google.android.material:material:1.4.0" - implementation 'me.zhanghai.android.fastscroll:library:1.1.7' - // --- DEBUG --- // Lint diff --git a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt index fe0047558..5d76d4c7b 100644 --- a/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/home/HomeFragment.kt @@ -49,8 +49,6 @@ import org.oxycblt.auxio.util.logE * It will require a new SortMode to be made simply for compat. Migrate the old SortMode * eventually. * TODO: Add lift-on-scroll eventually [when I can file a bug report or hack it into working] - * FIXME: Find a way to store the collapsed state so it stays consistent - * TODO: Fix issue where TabLayout ripples will shove above the indicator * @author OxygenCobalt */ class HomeFragment : Fragment() { @@ -69,9 +67,6 @@ class HomeFragment : Fragment() { binding.lifecycleOwner = viewLifecycleOwner - // For some insane reason certain navigation actions will collapse the app bar - binding.homeAppbar.setExpanded(true) - binding.homeToolbar.setOnMenuItemClickListener { item -> when (item.itemId) { R.id.action_settings -> { @@ -128,24 +123,28 @@ class HomeFragment : Fragment() { // --- VIEWMODEL SETUP --- detailModel.navToItem.observe(viewLifecycleOwner) { item -> - when (item) { - is Song -> findNavController().navigate( - HomeFragmentDirections.actionShowAlbum(item.album.id) - ) + // Unless we wait for the AppBarLayout to be done setting up before we navigate, + // it might result in the collapsed state being lost for...reasons. + binding.homeAppbar.post { + when (item) { + is Song -> findNavController().navigate( + HomeFragmentDirections.actionShowAlbum(item.album.id) + ) - is Album -> findNavController().navigate( - HomeFragmentDirections.actionShowAlbum(item.id) - ) + is Album -> findNavController().navigate( + HomeFragmentDirections.actionShowAlbum(item.id) + ) - is Artist -> findNavController().navigate( - HomeFragmentDirections.actionShowArtist(item.id) - ) + is Artist -> findNavController().navigate( + HomeFragmentDirections.actionShowArtist(item.id) + ) - is Genre -> findNavController().navigate( - HomeFragmentDirections.actionShowGenre(item.id) - ) + is Genre -> findNavController().navigate( + HomeFragmentDirections.actionShowGenre(item.id) + ) - else -> { + else -> { + } } } } diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 549cd9353..b40f3ecc1 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -16,6 +16,8 @@ android:id="@+id/home_appbar" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clickable="true" + android:focusable="true" android:background="?attr/colorSurface" android:elevation="@dimen/elevation_normal"> @@ -31,9 +33,13 @@ android:id="@+id/home_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" + android:clickable="true" + android:focusable="true" + app:tabUnboundedRipple="true" + app:tabRippleColor="?attr/colorControlHighlight" app:tabTextAppearance="@style/TextAppearance.TabLayout.Label" - app:tabMode="scrollable" app:tabContentStart="@dimen/spacing_medium" + app:tabMode="scrollable" app:tabTextColor="?android:attr/textColorPrimary" app:tabIndicatorColor="?attr/colorAccent" />