home: rework fab adaptiveness

Rework how the fab's adaptive functionality works.

Handle fab adaptiveness by using a style instead of a fully custom
view. This helps eliminate a usage of private resources.
This commit is contained in:
OxygenCobalt
2022-02-23 16:13:59 -07:00
parent 87035805d2
commit 280b582efa
8 changed files with 44 additions and 58 deletions
@@ -1,40 +0,0 @@
package org.oxycblt.auxio.home
import android.content.Context
import android.util.AttributeSet
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.oxycblt.auxio.util.getDimenSizeSafe
import org.oxycblt.auxio.util.logD
import com.google.android.material.R as MaterialR
/**
* A FloatingActionButton that automatically switches to a normal or large FAB depending on the
* screen size.
*/
@Suppress("PrivateResource")
class AdaptiveFloatingActionButton @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = MaterialR.style.Widget_Material3_FloatingActionButton_Primary
) : FloatingActionButton(context, attrs, defStyleAttr) {
init {
size = SIZE_NORMAL
// Use a large FAB on large screens, as it makes it easier to touch.
if (resources.configuration.smallestScreenWidthDp >= 640) {
logD("Using large FAB configuration")
val largeFabSize = context.getDimenSizeSafe(
MaterialR.dimen.m3_large_fab_size
)
val largeImageSize = context.getDimenSizeSafe(
MaterialR.dimen.m3_large_fab_max_image_size
)
customSize = largeFabSize
setMaxImageSize(largeImageSize)
}
}
}
@@ -30,7 +30,7 @@ import org.oxycblt.auxio.util.systemBarInsetsCompat
* A container for a FloatingActionButton that enables edge-to-edge support.
* @author OxygenCobalt
*/
class FloatingActionButtonContainer @JvmOverloads constructor(
class EdgeFabContainer @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
@AttrRes defStyleAttr: Int = 0
@@ -45,7 +45,6 @@ class FloatingActionButtonContainer @JvmOverloads constructor(
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
return insets
}
}
@@ -159,11 +159,9 @@ class HomeFragment : Fragment() {
).attach()
}
binding.homeFab.setOnClickListener {
playbackModel.shuffleAll()
}
binding.homeShuffleFab.setup(playbackModel)
// --- VIEWMODEL SETUP ---
// --- VIEWMODEL SETUP ---
// There is no way a fast scrolling event can continue across a re-create. Reset it.
homeModel.updateFastScrolling(false)
@@ -171,12 +169,12 @@ class HomeFragment : Fragment() {
musicModel.loaderResponse.observe(viewLifecycleOwner) { response ->
// Handle the loader response.
when (response) {
is MusicStore.Response.Ok -> binding.homeFab.show()
is MusicStore.Response.Ok -> binding.homeShuffleFab.show()
// While loading or during an error, make sure we keep the shuffle fab hidden so
// that any kind of playback is impossible. PlaybackStateManager also relies on this
// invariant, so please don't change it.
else -> binding.homeFab.hide()
else -> binding.homeShuffleFab.hide()
}
}
@@ -188,9 +186,9 @@ class HomeFragment : Fragment() {
}
if (scrolling) {
binding.homeFab.hide()
binding.homeShuffleFab.hide()
} else {
binding.homeFab.show()
binding.homeShuffleFab.show()
}
}