Fixed fab bottom margin

This commit is contained in:
Prathamesh More 2021-09-24 13:01:53 +05:30
parent a83879dffb
commit 541a6fffe5
8 changed files with 36 additions and 13 deletions

View file

@ -132,7 +132,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
val navbarHeight = RetroUtil.getNavigationBarHeight() val navbarHeight = RetroUtil.getNavigationBarHeight()
updatePadding(bottom = navbarHeight) updatePadding(bottom = navbarHeight)
binding.bottomNavigationView.updateLayoutParams { binding.bottomNavigationView.updateLayoutParams {
height = dip(R.dimen.mini_player_height) + navbarHeight height = dip(R.dimen.bottom_nav_height) + navbarHeight
} }
} }
} }
@ -289,14 +289,12 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
fun hideBottomBar(hide: Boolean) { fun hideBottomBar(hide: Boolean) {
val heightOfBar = RetroUtil.getNavigationBarHeight() + val heightOfBar = RetroUtil.getNavigationBarHeight() +
if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height) if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height)
val heightOfBarWithTabs = RetroUtil.getNavigationBarHeight() + val heightOfBarWithTabs = heightOfBar + dip(R.dimen.bottom_nav_height)
if (MusicPlayerRemote.isCasting) dip(R.dimen.mini_cast_player_height_expanded) else dip(
R.dimen.mini_player_height_expanded
)
val isVisible = binding.bottomNavigationView.isVisible val isVisible = binding.bottomNavigationView.isVisible
if (hide) { if (hide) {
bottomSheetBehavior.isHideable = true bottomSheetBehavior.isHideable = true
bottomSheetBehavior.peekHeight = 0 bottomSheetBehavior.peekHeight = 0
libraryViewModel.setFabMargin(if (isVisible) dip(R.dimen.bottom_nav_height) else 0)
ViewCompat.setElevation(binding.slidingPanel, 0f) ViewCompat.setElevation(binding.slidingPanel, 0f)
ViewCompat.setElevation(binding.bottomNavigationView, 10f) ViewCompat.setElevation(binding.bottomNavigationView, 10f)
collapsePanel() collapsePanel()
@ -310,9 +308,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
if (bottomSheetBehavior.state != STATE_EXPANDED) if (bottomSheetBehavior.state != STATE_EXPANDED)
getBottomNavigationView().translateYAnimate(0F) getBottomNavigationView().translateYAnimate(0F)
bottomSheetBehavior.peekHeightAnimate(heightOfBarWithTabs) bottomSheetBehavior.peekHeightAnimate(heightOfBarWithTabs)
libraryViewModel.setFabMargin(heightOfBarWithTabs - RetroUtil.getNavigationBarHeight())
} else { } else {
println("Details") println("Details")
bottomSheetBehavior.peekHeight = heightOfBar bottomSheetBehavior.peekHeight = heightOfBar
libraryViewModel.setFabMargin(heightOfBar - RetroUtil.getNavigationBarHeight())
} }
} }
} }

View file

@ -23,6 +23,7 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.interfaces.IMusicServiceEventListener import code.name.monkey.retromusic.interfaces.IMusicServiceEventListener
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.repository.RealRepository import code.name.monkey.retromusic.repository.RealRepository
import code.name.monkey.retromusic.util.DensityUtil
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -40,6 +41,7 @@ class LibraryViewModel(
private val legacyPlaylists = MutableLiveData<List<Playlist>>() private val legacyPlaylists = MutableLiveData<List<Playlist>>()
private val genres = MutableLiveData<List<Genre>>() private val genres = MutableLiveData<List<Genre>>()
private val searchResults = MutableLiveData<List<Any>>() private val searchResults = MutableLiveData<List<Any>>()
private val fabMargin = MutableLiveData(0)
val paletteColor: LiveData<Int> = _paletteColor val paletteColor: LiveData<Int> = _paletteColor
init { init {
@ -85,6 +87,10 @@ class LibraryViewModel(
return home return home
} }
fun getFabMargin(): LiveData<Int> {
return fabMargin
}
private fun fetchSongs() { private fun fetchSongs() {
viewModelScope.launch(IO) { viewModelScope.launch(IO) {
songs.postValue(repository.allSongs()) songs.postValue(repository.allSongs())
@ -328,6 +334,14 @@ class LibraryViewModel(
} }
} }
} }
fun setFabMargin(bottomMargin: Int) {
fabMargin.postValue(
// Normal Margin
DensityUtil.dip2px(App.getContext(), 16F) +
bottomMargin
)
}
} }
enum class ReloadType { enum class ReloadType {

View file

@ -22,6 +22,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.doOnPreDraw import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -85,6 +86,11 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
} else { } else {
binding.shuffleButton.isVisible = false binding.shuffleButton.isVisible = false
} }
libraryViewModel.getFabMargin().observe(viewLifecycleOwner, {
binding.shuffleButton.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = it
}
})
} }
open fun onShuffleClicked() { open fun onShuffleClicked() {

View file

@ -52,7 +52,7 @@ class PlayingQueueFragment : AbsRecyclerViewFragment<PlayingQueueAdapter, Linear
private fun setupToolbar() { private fun setupToolbar() {
toolbar().apply { toolbar().apply {
setOnClickListener { setNavigationOnClickListener {
findNavController().navigateUp() findNavController().navigateUp()
} }
setNavigationIcon(R.drawable.ic_keyboard_backspace_black) setNavigationIcon(R.drawable.ic_keyboard_backspace_black)

View file

@ -23,12 +23,10 @@ import android.speech.RecognizerIntent
import android.text.Editable import android.text.Editable
import android.text.TextWatcher import android.text.TextWatcher
import android.view.View import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.CompoundButton import android.widget.CompoundButton
import androidx.core.view.children import androidx.core.view.*
import androidx.core.view.doOnPreDraw
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager import androidx.transition.TransitionManager
@ -89,6 +87,11 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
view.doOnPreDraw { view.doOnPreDraw {
startPostponedEnterTransition() startPostponedEnterTransition()
} }
libraryViewModel.getFabMargin().observe(viewLifecycleOwner, {
binding.keyboardPopup.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = it
}
})
} }
private fun setupChips() { private fun setupChips() {

View file

@ -85,6 +85,5 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
app:srcCompat="@drawable/ic_shuffle" app:srcCompat="@drawable/ic_shuffle"
android:layout_marginBottom="116dp"
android:layout_marginHorizontal="16dp"/> android:layout_marginHorizontal="16dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -56,7 +56,7 @@
<code.name.monkey.retromusic.views.BottomNavigationBarTinted <code.name.monkey.retromusic.views.BottomNavigationBarTinted
android:id="@+id/bottomNavigationView" android:id="@+id/bottomNavigationView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="56dp" android:layout_height="@dimen/bottom_nav_height"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:background="?attr/colorSurface" android:background="?attr/colorSurface"
android:elevation="0dp" android:elevation="0dp"

View file

@ -53,4 +53,5 @@
<dimen name="indicator_radius">10dp</dimen> <dimen name="indicator_radius">10dp</dimen>
<dimen name="lyrics_dialog_radius">20dp</dimen> <dimen name="lyrics_dialog_radius">20dp</dimen>
<dimen name="cast_mini_player_height">64dp</dimen> <dimen name="cast_mini_player_height">64dp</dimen>
<dimen name="bottom_nav_height">56dp</dimen>
</resources> </resources>