Fixed AppBarLayout issues

This commit is contained in:
Prathamesh More 2021-10-23 17:25:48 +05:30
parent cb8ef7f32c
commit efeacfa622
7 changed files with 14 additions and 16 deletions

View file

@ -313,7 +313,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
bottomNavAnimator?.end() bottomNavAnimator?.end()
bottomNavAnimator = binding.bottomNavigationView.translateYAnimate(0F) bottomNavAnimator = binding.bottomNavigationView.translateYAnimate(0F)
binding.bottomNavigationView.bringToFront() binding.bottomNavigationView.bringToFront()
libraryViewModel.setFabMargin(heightOfBarWithTabs - windowInsets.safeGetBottomInsets()) libraryViewModel.setFabMargin(heightOfBarWithTabs - 2 * windowInsets.safeGetBottomInsets())
} else { } else {
println("Details") println("Details")
bottomSheetBehavior.peekHeightAnimate(heightOfBar) bottomSheetBehavior.peekHeightAnimate(heightOfBar)
@ -323,7 +323,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
bottomNavAnimator?.doOnEnd { bottomNavAnimator?.doOnEnd {
binding.slidingPanel.bringToFront() binding.slidingPanel.bringToFront()
} }
libraryViewModel.setFabMargin(heightOfBar - windowInsets.safeGetBottomInsets()) libraryViewModel.setFabMargin(heightOfBar - 2 * windowInsets.safeGetBottomInsets())
} }
} }
} }

View file

@ -24,11 +24,11 @@ import android.view.ViewGroup.MarginLayoutParams
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.EditText import android.widget.EditText
import android.widget.FrameLayout
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.core.animation.doOnEnd import androidx.core.animation.doOnEnd
import androidx.core.animation.doOnStart import androidx.core.animation.doOnStart
import androidx.core.view.* import androidx.core.view.*
import androidx.core.view.WindowInsetsCompat.Type.navigationBars
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
@ -191,17 +191,16 @@ fun View.requestApplyInsetsWhenAttached() {
} }
} }
fun AppBarLayout.drawNextToNavbar() { fun View.drawNextToNavbar() {
val initialMargin = recordInitialMarginForView(this) val initialPadding = recordInitialPaddingForView(this)
ViewCompat.setOnApplyWindowInsetsListener( ViewCompat.setOnApplyWindowInsetsListener(
(this) (this)
) { v: View, windowInsets: WindowInsetsCompat -> ) { v: View, windowInsets: WindowInsetsCompat ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
v.updatePadding( v.updatePadding(
top = initialMargin.top + insets.top, left = initialPadding.left + insets.left,
left = initialMargin.left + insets.left, right = initialPadding.right + insets.right
right = initialMargin.right + insets.right
) )
windowInsets windowInsets
} }
@ -228,7 +227,7 @@ data class InitialMargin(
val right: Int, val bottom: Int val right: Int, val bottom: Int
) )
private fun recordInitialMarginForView(view: View) = InitialMargin( fun recordInitialMarginForView(view: View) = InitialMargin(
view.marginLeft, view.marginTop, view.marginRight, view.marginBottom view.marginLeft, view.marginTop, view.marginRight, view.marginBottom
) )

View file

@ -64,9 +64,6 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
initAdapter() initAdapter()
setUpRecyclerView() setUpRecyclerView()
setupToolbar() setupToolbar()
binding.appBarLayout.statusBarForeground =
MaterialShapeDrawable.createWithElevationOverlay(requireContext())
// Add listeners when shuffle is visible // Add listeners when shuffle is visible
if (isShuffleVisible) { if (isShuffleVisible) {
binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { binding.recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
@ -95,7 +92,6 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
bottomMargin = it bottomMargin = it
} }
}) })
binding.appBarLayout.drawNextToNavbar()
} }
open fun onShuffleClicked() { open fun onShuffleClicked() {
@ -117,6 +113,9 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
} }
val appName = resources.getString(titleRes) val appName = resources.getString(titleRes)
binding.appNameText.text = appName binding.appNameText.text = appName
binding.toolbarContainer.drawNextToNavbar()
binding.appBarLayout.statusBarForeground =
MaterialShapeDrawable.createWithElevationOverlay(requireContext())
} }
abstract val titleRes: Int abstract val titleRes: Int

View file

@ -124,7 +124,7 @@ class FoldersFragment : AbsMainActivityFragment(R.layout.fragment_folder),
} }
} }
}) })
binding.appBarLayout.drawNextToNavbar() binding.toolbarContainer.drawNextToNavbar()
} }
private fun setUpTitle() { private fun setUpTitle() {

View file

@ -76,7 +76,7 @@ class HomeFragment :
view.doOnPreDraw { startPostponedEnterTransition() } view.doOnPreDraw { startPostponedEnterTransition() }
binding.appBarLayout.statusBarForeground = binding.appBarLayout.statusBarForeground =
MaterialShapeDrawable.createWithElevationOverlay(requireContext()) MaterialShapeDrawable.createWithElevationOverlay(requireContext())
binding.appBarLayout.drawNextToNavbar() binding.toolbar.drawNextToNavbar()
} }
private fun setupListeners() { private fun setupListeners() {

View file

@ -94,6 +94,7 @@
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginBottom="70dp" android:layout_marginBottom="70dp"
android:fitsSystemWindows="false"
android:gravity="center" android:gravity="center"
android:text="@string/save" android:text="@string/save"
app:icon="@drawable/ic_save" app:icon="@drawable/ic_save"

View file

@ -191,7 +191,6 @@
<style name="BottomSheetStyle" parent="Widget.Material3.BottomSheet"> <style name="BottomSheetStyle" parent="Widget.Material3.BottomSheet">
<item name="android:maxWidth">@empty</item> <item name="android:maxWidth">@empty</item>
<item name="android:backgroundTint">?attr/bottomSheetTint</item> <item name="android:backgroundTint">?attr/bottomSheetTint</item>
<item name="gestureInsetBottomIgnored">true</item>
</style> </style>
<style name="MaterialCardViewStroke"> <style name="MaterialCardViewStroke">