playback: introduce new button design
This commit is contained in:
@@ -133,8 +133,8 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
if (tag != actionMode) {
|
||||
setIconResource(R.drawable.ic_skip_next_24)
|
||||
contentDescription = getString(R.string.desc_skip_next)
|
||||
iconTint = context.getAttrColorCompat(MR.attr.colorOnSurfaceVariant)
|
||||
setOnClickListener { playbackModel.next() }
|
||||
isChecked = false
|
||||
tag = actionMode
|
||||
}
|
||||
}
|
||||
@@ -144,12 +144,11 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
binding.playbackSecondaryAction.apply {
|
||||
if (tag != actionMode) {
|
||||
contentDescription = getString(R.string.desc_change_repeat)
|
||||
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
||||
setOnClickListener { playbackModel.toggleRepeatMode() }
|
||||
tag = actionMode
|
||||
}
|
||||
setIconResource(repeatMode.icon)
|
||||
isActivated = repeatMode != RepeatMode.NONE
|
||||
isChecked = repeatMode != RepeatMode.NONE
|
||||
}
|
||||
}
|
||||
ActionMode.SHUFFLE -> {
|
||||
@@ -158,11 +157,10 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
|
||||
if (tag != actionMode) {
|
||||
setIconResource(R.drawable.sel_shuffle_state_24)
|
||||
contentDescription = getString(R.string.desc_shuffle)
|
||||
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
|
||||
setOnClickListener { playbackModel.toggleShuffled() }
|
||||
tag = actionMode
|
||||
}
|
||||
isActivated = isShuffled
|
||||
isChecked = isShuffled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.media.audiofx.AudioEffect
|
||||
@@ -29,6 +30,7 @@ import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.dynamicanimation.animation.SpringForce
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -125,11 +127,22 @@ class PlaybackPanelFragment :
|
||||
|
||||
// Set up actions
|
||||
// TODO: Add better playback button accessibility
|
||||
binding.playbackRepeat.setOnClickListener { playbackModel.toggleRepeatMode() }
|
||||
binding.playbackRepeat.setOnClickListener {
|
||||
playbackModel.toggleRepeatMode()
|
||||
}
|
||||
binding.playbackSkipPrev.setOnClickListener { playbackModel.prev() }
|
||||
binding.playbackPlayPause.setOnClickListener { playbackModel.togglePlaying() }
|
||||
binding.playbackPlayPause.apply {
|
||||
@SuppressLint("RestrictedApi")
|
||||
setCornerSpringForce(SpringForce().apply {
|
||||
stiffness = 700f
|
||||
dampingRatio = 0.9f
|
||||
})
|
||||
setOnClickListener { playbackModel.togglePlaying() }
|
||||
}
|
||||
binding.playbackSkipNext.setOnClickListener { playbackModel.next() }
|
||||
binding.playbackShuffle.setOnClickListener { playbackModel.toggleShuffled() }
|
||||
binding.playbackShuffle.setOnClickListener {
|
||||
playbackModel.toggleShuffled()
|
||||
}
|
||||
binding.playbackMore?.setOnClickListener {
|
||||
playbackModel.song.value?.let {
|
||||
listModel.openMenu(R.menu.playback_song, it, PlaySong.ByItself)
|
||||
@@ -245,16 +258,17 @@ class PlaybackPanelFragment :
|
||||
private fun updateRepeat(repeatMode: RepeatMode) {
|
||||
requireBinding().playbackRepeat.apply {
|
||||
setIconResource(repeatMode.icon)
|
||||
isActivated = repeatMode != RepeatMode.NONE
|
||||
isChecked = repeatMode != RepeatMode.NONE
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePlaying(isPlaying: Boolean) {
|
||||
requireBinding().playbackPlayPause.isActivated = isPlaying
|
||||
requireBinding().playbackPlayPause.isChecked = isPlaying
|
||||
requireBinding().playbackSeekBar?.setWaveEnabled(isPlaying)
|
||||
}
|
||||
|
||||
private fun updateShuffled(isShuffled: Boolean) {
|
||||
requireBinding().playbackShuffle.isActivated = isShuffled
|
||||
requireBinding().playbackShuffle.isChecked = isShuffled
|
||||
}
|
||||
|
||||
private fun navigateToCurrentSong() {
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Auxio Project
|
||||
* AnimatedMaterialButton.kt is part of Auxio.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oxycblt.auxio.playback.ui
|
||||
|
||||
import android.animation.Animator
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import org.oxycblt.auxio.ui.MaterialCornerAnim
|
||||
import org.oxycblt.auxio.ui.RippleFixMaterialButton
|
||||
import timber.log.Timber as L
|
||||
|
||||
/**
|
||||
* A [MaterialButton] that automatically morphs from a circle to a squircle shape appearance when
|
||||
* [isActivated] changes.
|
||||
*
|
||||
* @author Alexander Capehart (OxygenCobalt)
|
||||
*/
|
||||
class AnimatedMaterialButton : RippleFixMaterialButton {
|
||||
constructor(context: Context) : super(context)
|
||||
|
||||
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet,
|
||||
defStyleAttr: Int,
|
||||
) : super(context, attrs, defStyleAttr)
|
||||
|
||||
private var animator: Animator? = null
|
||||
private val anim = MaterialCornerAnim(context)
|
||||
|
||||
override fun setActivated(activated: Boolean) {
|
||||
super.setActivated(activated)
|
||||
|
||||
// Activated -> Squircle (30% Radius), Inactive -> Circle (50% Radius)
|
||||
val targetRadius = if (activated) 0.3f else 0.5f
|
||||
if (!isLaidOut) {
|
||||
// Not laid out, initialize it without animation before drawing.
|
||||
L.d("Not laid out, immediately updating corner radius")
|
||||
shapeAppearanceModel = shapeAppearanceModel.withCornerSize { it.width() * targetRadius }
|
||||
return
|
||||
}
|
||||
|
||||
L.d("Starting corner radius animation")
|
||||
animator?.cancel()
|
||||
animator = anim.animate(this, width * targetRadius).also { it.start() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user