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:
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.
|
* A container for a FloatingActionButton that enables edge-to-edge support.
|
||||||
* @author OxygenCobalt
|
* @author OxygenCobalt
|
||||||
*/
|
*/
|
||||||
class FloatingActionButtonContainer @JvmOverloads constructor(
|
class EdgeFabContainer @JvmOverloads constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
attrs: AttributeSet? = null,
|
attrs: AttributeSet? = null,
|
||||||
@AttrRes defStyleAttr: Int = 0
|
@AttrRes defStyleAttr: Int = 0
|
||||||
|
@ -45,7 +45,6 @@ class FloatingActionButtonContainer @JvmOverloads constructor(
|
||||||
|
|
||||||
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
override fun onApplyWindowInsets(insets: WindowInsets): WindowInsets {
|
||||||
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
|
||||||
|
|
||||||
return insets
|
return insets
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -159,9 +159,7 @@ class HomeFragment : Fragment() {
|
||||||
).attach()
|
).attach()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.homeFab.setOnClickListener {
|
binding.homeShuffleFab.setup(playbackModel)
|
||||||
playbackModel.shuffleAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- VIEWMODEL SETUP ---
|
||||||
|
|
||||||
|
@ -171,12 +169,12 @@ class HomeFragment : Fragment() {
|
||||||
musicModel.loaderResponse.observe(viewLifecycleOwner) { response ->
|
musicModel.loaderResponse.observe(viewLifecycleOwner) { response ->
|
||||||
// Handle the loader response.
|
// Handle the loader response.
|
||||||
when (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
|
// 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
|
// that any kind of playback is impossible. PlaybackStateManager also relies on this
|
||||||
// invariant, so please don't change it.
|
// invariant, so please don't change it.
|
||||||
else -> binding.homeFab.hide()
|
else -> binding.homeShuffleFab.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,9 +186,9 @@ class HomeFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scrolling) {
|
if (scrolling) {
|
||||||
binding.homeFab.hide()
|
binding.homeShuffleFab.hide()
|
||||||
} else {
|
} else {
|
||||||
binding.homeFab.show()
|
binding.homeShuffleFab.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,24 +40,23 @@
|
||||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
|
||||||
tools:layout="@layout/fragment_home_list" />
|
tools:layout="@layout/fragment_home_list" />
|
||||||
|
|
||||||
<org.oxycblt.auxio.home.FloatingActionButtonContainer
|
<org.oxycblt.auxio.home.EdgeFabContainer
|
||||||
android:id="@+id/home_fab_container"
|
android:id="@+id/home_fab_container"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
app:layout_anchor="@id/home_pager"
|
app:layout_anchor="@id/home_pager"
|
||||||
app:layout_anchorGravity="bottom|end">
|
app:layout_anchorGravity="bottom|end">
|
||||||
|
|
||||||
<org.oxycblt.auxio.home.AdaptiveFloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/home_fab"
|
android:id="@+id/home_fab"
|
||||||
|
style="@style/Widget.Auxio.FloatingActionButton.Adaptive"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/Widget.Material3.FloatingActionButton.Primary"
|
|
||||||
android:layout_margin="@dimen/spacing_medium"
|
android:layout_margin="@dimen/spacing_medium"
|
||||||
android:contentDescription="@string/desc_shuffle_all"
|
android:contentDescription="@string/desc_shuffle_all"
|
||||||
android:src="@drawable/ic_shuffle"
|
android:src="@drawable/ic_shuffle" />
|
||||||
app:tint="?attr/colorOnPrimaryContainer" />
|
|
||||||
|
|
||||||
</org.oxycblt.auxio.home.FloatingActionButtonContainer>
|
</org.oxycblt.auxio.home.EdgeFabContainer>
|
||||||
|
|
||||||
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
|
</org.oxycblt.auxio.ui.EdgeCoordinatorLayout>
|
||||||
</layout>
|
</layout>
|
19
app/src/main/res/layout/view_shuffle_button.xml
Normal file
19
app/src/main/res/layout/view_shuffle_button.xml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:parentTag="android.widget.FrameLayout">
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/shuffle_fab"
|
||||||
|
style="@style/Widget.Auxio.FloatingActionButton.Adaptive"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="@dimen/spacing_medium"
|
||||||
|
android:contentDescription="@string/desc_shuffle_all"
|
||||||
|
android:src="@drawable/ic_shuffle"
|
||||||
|
app:icon="@drawable/ic_shuffle" />
|
||||||
|
|
||||||
|
</merge>
|
||||||
|
</layout>
|
6
app/src/main/res/values-sw640dp/styles_ui.xml
Normal file
6
app/src/main/res/values-sw640dp/styles_ui.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<style name="Widget.Auxio.FloatingActionButton.Adaptive" parent="Widget.Material3.FloatingActionButton.Large.Primary">
|
||||||
|
<item name="fabSize">normal</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
|
@ -167,9 +167,14 @@
|
||||||
compensate.
|
compensate.
|
||||||
2. For some reason elevation behaves strangely in the playback panel, so we disable it.
|
2. For some reason elevation behaves strangely in the playback panel, so we disable it.
|
||||||
-->
|
-->
|
||||||
<item name="maxImageSize">@dimen/size_playback_icon</item>
|
<item name="fabSize">normal</item>
|
||||||
<item name="fabCustomSize">@dimen/size_btn_large</item>
|
<item name="fabCustomSize">@dimen/size_btn_large</item>
|
||||||
|
<item name="maxImageSize">@dimen/size_playback_icon</item>
|
||||||
<item name="android:elevation">0dp</item>
|
<item name="android:elevation">0dp</item>
|
||||||
<item name="elevation">0dp</item>
|
<item name="elevation">0dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="Widget.Auxio.FloatingActionButton.Adaptive" parent="Widget.Material3.FloatingActionButton.Primary">
|
||||||
|
<item name="fabSize">normal</item>
|
||||||
|
</style>
|
||||||
</resources>
|
</resources>
|
|
@ -9,7 +9,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:7.1.1'
|
classpath 'com.android.tools.build:gradle:7.1.2'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
|
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue