Stop play/pause button from animating on creation
Re-add the fix that makes the play/pause button not animate when created initially.
This commit is contained in:
parent
c11882bc7b
commit
2cd45f8350
9 changed files with 110 additions and 93 deletions
|
@ -72,7 +72,7 @@ class MainFragment : Fragment() {
|
||||||
|
|
||||||
navController?.let {
|
navController?.let {
|
||||||
binding.navBar.setOnNavigationItemSelectedListener { item ->
|
binding.navBar.setOnNavigationItemSelectedListener { item ->
|
||||||
navigateWithItem(item, navController)
|
navigateWithItem(item, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ class MainFragment : Fragment() {
|
||||||
)
|
)
|
||||||
|
|
||||||
binding.compactPlayback.visibility = View.GONE
|
binding.compactPlayback.visibility = View.GONE
|
||||||
|
playbackModel.resetCanAnimate()
|
||||||
} else {
|
} else {
|
||||||
binding.compactPlayback.visibility = View.VISIBLE
|
binding.compactPlayback.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
@ -103,8 +104,6 @@ class MainFragment : Fragment() {
|
||||||
* Some custom navigator code based off [NavigationUI] that makes animations function
|
* Some custom navigator code based off [NavigationUI] that makes animations function
|
||||||
*/
|
*/
|
||||||
private fun navigateWithItem(item: MenuItem, navController: NavController): Boolean {
|
private fun navigateWithItem(item: MenuItem, navController: NavController): Boolean {
|
||||||
// Custom navigator code so that animations actually function
|
|
||||||
// [Which doesn't happen if I use BottomNavigationView.setupWithNavController()
|
|
||||||
if (item.itemId != navController.currentDestination!!.id) {
|
if (item.itemId != navController.currentDestination!!.id) {
|
||||||
val builder = NavOptions.Builder().setLaunchSingleTop(true)
|
val builder = NavOptions.Builder().setLaunchSingleTop(true)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.oxycblt.auxio.playback
|
package org.oxycblt.auxio.playback
|
||||||
|
|
||||||
import android.graphics.drawable.AnimatedVectorDrawable
|
import android.graphics.drawable.AnimatedVectorDrawable
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -30,7 +31,7 @@ class CompactPlaybackFragment : Fragment() {
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View {
|
||||||
val binding = FragmentCompactPlaybackBinding.inflate(inflater)
|
val binding = FragmentCompactPlaybackBinding.inflate(inflater)
|
||||||
|
|
||||||
val iconPauseToPlay = ContextCompat.getDrawable(
|
val iconPauseToPlay = ContextCompat.getDrawable(
|
||||||
|
@ -74,13 +75,21 @@ class CompactPlaybackFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||||
if (it) {
|
if (playbackModel.canAnimate) {
|
||||||
// Animate the icon transition when the playing status switches
|
if (it) {
|
||||||
binding.playbackControls.setImageDrawable(iconPauseToPlay)
|
// Animate the icon transition when the playing status switches
|
||||||
iconPauseToPlay.start()
|
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||||
|
iconPlayToPause.start()
|
||||||
|
} else {
|
||||||
|
binding.playbackControls.setImageDrawable(iconPauseToPlay)
|
||||||
|
iconPauseToPlay.start()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
if (it) {
|
||||||
iconPlayToPause.start()
|
binding.playbackControls.setImageResource(R.drawable.ic_pause_large)
|
||||||
|
} else {
|
||||||
|
binding.playbackControls.setImageResource(R.drawable.ic_play_large)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,4 +101,10 @@ class CompactPlaybackFragment : Fragment() {
|
||||||
|
|
||||||
return binding.root
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onDestroy() {
|
||||||
|
super.onDestroy()
|
||||||
|
|
||||||
|
playbackModel.resetCanAnimate()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,13 +107,13 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||||
if (it) {
|
if (it) {
|
||||||
// Animate the playing status and switch the button to the accent color
|
// Animate the playing status and switch the button to the accent color
|
||||||
// if its playing, and back to a inactive gray if not.
|
// if its playing, and back to a inactive gray if not.
|
||||||
binding.playbackPlayPause.setImageDrawable(iconPauseToPlay)
|
binding.playbackPlayPause.setImageDrawable(iconPlayToPause)
|
||||||
iconPauseToPlay.start()
|
iconPlayToPause.start()
|
||||||
|
|
||||||
binding.playbackPlayPause.backgroundTintList = accentColor
|
binding.playbackPlayPause.backgroundTintList = accentColor
|
||||||
} else {
|
} else {
|
||||||
binding.playbackPlayPause.setImageDrawable(iconPlayToPause)
|
binding.playbackPlayPause.setImageDrawable(iconPauseToPlay)
|
||||||
iconPlayToPause.start()
|
iconPauseToPlay.start()
|
||||||
|
|
||||||
binding.playbackPlayPause.backgroundTintList = controlColor
|
binding.playbackPlayPause.backgroundTintList = controlColor
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,9 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
private val mLoopMode = MutableLiveData(LoopMode.NONE)
|
private val mLoopMode = MutableLiveData(LoopMode.NONE)
|
||||||
val loopMode: LiveData<LoopMode> get() = mLoopMode
|
val loopMode: LiveData<LoopMode> get() = mLoopMode
|
||||||
|
|
||||||
|
private var mCanAnimate = false
|
||||||
|
val canAnimate: Boolean get() = mCanAnimate
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
private val mIsSeeking = MutableLiveData(false)
|
private val mIsSeeking = MutableLiveData(false)
|
||||||
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
||||||
|
@ -238,6 +241,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
|
|
||||||
// Flip the playing status.
|
// Flip the playing status.
|
||||||
fun invertPlayingStatus() {
|
fun invertPlayingStatus() {
|
||||||
|
mCanAnimate = true
|
||||||
|
|
||||||
playbackManager.setPlayingStatus(!playbackManager.isPlaying)
|
playbackManager.setPlayingStatus(!playbackManager.isPlaying)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +275,10 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resetCanAnimate() {
|
||||||
|
mCanAnimate = false
|
||||||
|
}
|
||||||
|
|
||||||
// --- OVERRIDES ---
|
// --- OVERRIDES ---
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
|
@ -308,6 +317,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
||||||
|
|
||||||
override fun onPlayingUpdate(isPlaying: Boolean) {
|
override fun onPlayingUpdate(isPlaying: Boolean) {
|
||||||
mIsPlaying.value = isPlaying
|
mIsPlaying.value = isPlaying
|
||||||
|
|
||||||
|
mCanAnimate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onShuffleUpdate(isShuffling: Boolean) {
|
override fun onShuffleUpdate(isShuffling: Boolean) {
|
||||||
|
|
|
@ -545,6 +545,7 @@ class PlaybackStateManager private constructor() {
|
||||||
mShuffleSeed = playbackState.shuffleSeed
|
mShuffleSeed = playbackState.shuffleSeed
|
||||||
mIsInUserQueue = playbackState.inUserQueue
|
mIsInUserQueue = playbackState.inUserQueue
|
||||||
mIndex = playbackState.index
|
mIndex = playbackState.index
|
||||||
|
mIsPlaying = false
|
||||||
|
|
||||||
callbacks.forEach {
|
callbacks.forEach {
|
||||||
it.onSeekConfirm(mPosition)
|
it.onSeekConfirm(mPosition)
|
||||||
|
|
26
app/src/main/res/drawable/ic_pause_large.xml
Normal file
26
app/src/main/res/drawable/ic_pause_large.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
android:width="32dp"
|
||||||
|
android:height="32dp"
|
||||||
|
android:tint="@color/control_color"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<group
|
||||||
|
android:name="play"
|
||||||
|
android:pivotX="12"
|
||||||
|
android:pivotY="12"
|
||||||
|
android:rotation="-90">
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:name="play_upper"
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M6,7.5L6,10.5L18,10.5L18,7.5Z" />
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:name="play_lower"
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M6,16.5L6,13.5L18,13.5L18,16.5Z" />
|
||||||
|
|
||||||
|
</group>
|
||||||
|
</vector>
|
|
@ -1,59 +1,30 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?><!--
|
|
||||||
Animated control icons derived from Noice
|
|
||||||
https://github.com/ashutoshgngwr/noice
|
|
||||||
-->
|
|
||||||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:aapt="http://schemas.android.com/aapt">
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:drawable="@drawable/ic_pause_large">
|
||||||
|
|
||||||
<aapt:attr name="android:drawable">
|
<target android:name="play_upper">
|
||||||
<vector
|
|
||||||
android:width="32dp"
|
|
||||||
android:height="32dp"
|
|
||||||
android:viewportWidth="24.0"
|
|
||||||
android:viewportHeight="24.0">
|
|
||||||
|
|
||||||
<group
|
|
||||||
android:name="play"
|
|
||||||
android:pivotX="12"
|
|
||||||
android:pivotY="12">
|
|
||||||
|
|
||||||
<path
|
|
||||||
android:name="pause_right"
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M 22.677734 18.898438 L 22.677734 71.810547 L 37.794922 71.810547 L 37.794922 18.898438 L 22.677734 18.898438 z" />
|
|
||||||
|
|
||||||
<path
|
|
||||||
android:name="pause_left"
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M 52.914062 18.898438 L 52.914062 71.810547 L 68.03125 71.810547 L 68.03125 18.898438 L 52.914062 18.898438 z " />
|
|
||||||
|
|
||||||
</group>
|
|
||||||
</vector>
|
|
||||||
</aapt:attr>
|
|
||||||
|
|
||||||
<target android:name="pause_right">
|
|
||||||
<aapt:attr name="android:animation">
|
<aapt:attr name="android:animation">
|
||||||
<set>
|
<set>
|
||||||
<objectAnimator
|
<objectAnimator
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="pathData"
|
android:propertyName="pathData"
|
||||||
android:valueFrom="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
android:valueFrom="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||||
android:valueTo="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
android:valueTo="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||||
android:valueType="pathType" />
|
android:valueType="pathType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target android:name="pause_left">
|
<target android:name="play_lower">
|
||||||
<aapt:attr name="android:animation">
|
<aapt:attr name="android:animation">
|
||||||
<set>
|
<set>
|
||||||
<objectAnimator
|
<objectAnimator
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="pathData"
|
android:propertyName="pathData"
|
||||||
android:valueFrom="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
android:valueFrom="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||||
android:valueTo="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
android:valueTo="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||||
android:valueType="pathType" />
|
android:valueType="pathType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
|
@ -66,8 +37,8 @@ https://github.com/ashutoshgngwr/noice
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="rotation"
|
android:propertyName="rotation"
|
||||||
android:valueFrom="0"
|
android:valueFrom="-90"
|
||||||
android:valueTo="90"
|
android:valueTo="0"
|
||||||
android:valueType="floatType" />
|
android:valueType="floatType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
|
|
26
app/src/main/res/drawable/ic_play_large.xml
Normal file
26
app/src/main/res/drawable/ic_play_large.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<vector
|
||||||
|
android:width="32dp"
|
||||||
|
android:height="32dp"
|
||||||
|
android:tint="@color/control_color"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<group
|
||||||
|
android:name="play"
|
||||||
|
android:pivotX="12"
|
||||||
|
android:pivotY="12">
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:name="play_upper"
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M8.25,6L8.25,12L18.75,12L18.75,12Z" />
|
||||||
|
|
||||||
|
<path
|
||||||
|
android:name="play_lower"
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M8.25,18L8.25,12L18.75,12L18.75,12Z" />
|
||||||
|
|
||||||
|
</group>
|
||||||
|
|
||||||
|
</vector>
|
|
@ -1,38 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?><!--
|
|
||||||
Animated control icons derived from Noice
|
|
||||||
https://github.com/ashutoshgngwr/noice
|
|
||||||
-->
|
|
||||||
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:aapt="http://schemas.android.com/aapt">
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:drawable="@drawable/ic_play_large">
|
||||||
<aapt:attr name="android:drawable">
|
|
||||||
<vector
|
|
||||||
android:width="32dp"
|
|
||||||
android:height="32dp"
|
|
||||||
android:tint="@android:color/white"
|
|
||||||
android:viewportWidth="24.0"
|
|
||||||
android:viewportHeight="24.0">
|
|
||||||
|
|
||||||
<group
|
|
||||||
android:name="play"
|
|
||||||
android:pivotX="12"
|
|
||||||
android:pivotY="12"
|
|
||||||
android:rotation="-90">
|
|
||||||
|
|
||||||
<path
|
|
||||||
android:name="play_upper"
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M6,7.5L6,10.5L18,10.5L18,7.5Z" />
|
|
||||||
|
|
||||||
<path
|
|
||||||
android:name="play_lower"
|
|
||||||
android:fillColor="@android:color/white"
|
|
||||||
android:pathData="M6,16.5L6,13.5L18,13.5L18,16.5Z" />
|
|
||||||
|
|
||||||
</group>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
</aapt:attr>
|
|
||||||
|
|
||||||
<target android:name="play_upper">
|
<target android:name="play_upper">
|
||||||
<aapt:attr name="android:animation">
|
<aapt:attr name="android:animation">
|
||||||
|
@ -41,8 +9,8 @@ https://github.com/ashutoshgngwr/noice
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="pathData"
|
android:propertyName="pathData"
|
||||||
android:valueFrom="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
android:valueFrom="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||||
android:valueTo="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
android:valueTo="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||||
android:valueType="pathType" />
|
android:valueType="pathType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
|
@ -55,8 +23,8 @@ https://github.com/ashutoshgngwr/noice
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="pathData"
|
android:propertyName="pathData"
|
||||||
android:valueFrom="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
android:valueFrom="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||||
android:valueTo="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
android:valueTo="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||||
android:valueType="pathType" />
|
android:valueType="pathType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
|
@ -69,8 +37,8 @@ https://github.com/ashutoshgngwr/noice
|
||||||
android:duration="200"
|
android:duration="200"
|
||||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||||
android:propertyName="rotation"
|
android:propertyName="rotation"
|
||||||
android:valueFrom="-90"
|
android:valueFrom="0"
|
||||||
android:valueTo="0"
|
android:valueTo="90"
|
||||||
android:valueType="floatType" />
|
android:valueType="floatType" />
|
||||||
</set>
|
</set>
|
||||||
</aapt:attr>
|
</aapt:attr>
|
||||||
|
|
Loading…
Reference in a new issue