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 {
|
||||
binding.navBar.setOnNavigationItemSelectedListener { item ->
|
||||
navigateWithItem(item, navController)
|
||||
navigateWithItem(item, it)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,7 @@ class MainFragment : Fragment() {
|
|||
)
|
||||
|
||||
binding.compactPlayback.visibility = View.GONE
|
||||
playbackModel.resetCanAnimate()
|
||||
} else {
|
||||
binding.compactPlayback.visibility = View.VISIBLE
|
||||
}
|
||||
|
@ -103,8 +104,6 @@ class MainFragment : Fragment() {
|
|||
* Some custom navigator code based off [NavigationUI] that makes animations function
|
||||
*/
|
||||
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) {
|
||||
val builder = NavOptions.Builder().setLaunchSingleTop(true)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.graphics.drawable.AnimatedVectorDrawable
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
|
@ -30,7 +31,7 @@ class CompactPlaybackFragment : Fragment() {
|
|||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
): View {
|
||||
val binding = FragmentCompactPlaybackBinding.inflate(inflater)
|
||||
|
||||
val iconPauseToPlay = ContextCompat.getDrawable(
|
||||
|
@ -74,13 +75,21 @@ class CompactPlaybackFragment : Fragment() {
|
|||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
if (it) {
|
||||
// Animate the icon transition when the playing status switches
|
||||
binding.playbackControls.setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
if (playbackModel.canAnimate) {
|
||||
if (it) {
|
||||
// Animate the icon transition when the playing status switches
|
||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
} else {
|
||||
binding.playbackControls.setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
}
|
||||
} else {
|
||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
if (it) {
|
||||
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
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
|
||||
playbackModel.resetCanAnimate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,13 +107,13 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
if (it) {
|
||||
// Animate the playing status and switch the button to the accent color
|
||||
// if its playing, and back to a inactive gray if not.
|
||||
binding.playbackPlayPause.setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
binding.playbackPlayPause.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
|
||||
binding.playbackPlayPause.backgroundTintList = accentColor
|
||||
} else {
|
||||
binding.playbackPlayPause.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
binding.playbackPlayPause.setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
|
||||
binding.playbackPlayPause.backgroundTintList = controlColor
|
||||
}
|
||||
|
|
|
@ -58,6 +58,9 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
private val mLoopMode = MutableLiveData(LoopMode.NONE)
|
||||
val loopMode: LiveData<LoopMode> get() = mLoopMode
|
||||
|
||||
private var mCanAnimate = false
|
||||
val canAnimate: Boolean get() = mCanAnimate
|
||||
|
||||
// Other
|
||||
private val mIsSeeking = MutableLiveData(false)
|
||||
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
||||
|
@ -238,6 +241,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
|
||||
// Flip the playing status.
|
||||
fun invertPlayingStatus() {
|
||||
mCanAnimate = true
|
||||
|
||||
playbackManager.setPlayingStatus(!playbackManager.isPlaying)
|
||||
}
|
||||
|
||||
|
@ -270,6 +275,10 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
}
|
||||
}
|
||||
|
||||
fun resetCanAnimate() {
|
||||
mCanAnimate = false
|
||||
}
|
||||
|
||||
// --- OVERRIDES ---
|
||||
|
||||
override fun onCleared() {
|
||||
|
@ -308,6 +317,8 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
|
|||
|
||||
override fun onPlayingUpdate(isPlaying: Boolean) {
|
||||
mIsPlaying.value = isPlaying
|
||||
|
||||
mCanAnimate = true
|
||||
}
|
||||
|
||||
override fun onShuffleUpdate(isShuffling: Boolean) {
|
||||
|
|
|
@ -545,6 +545,7 @@ class PlaybackStateManager private constructor() {
|
|||
mShuffleSeed = playbackState.shuffleSeed
|
||||
mIsInUserQueue = playbackState.inUserQueue
|
||||
mIndex = playbackState.index
|
||||
mIsPlaying = false
|
||||
|
||||
callbacks.forEach {
|
||||
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"
|
||||
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">
|
||||
<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">
|
||||
<target android:name="play_upper">
|
||||
<aapt:attr name="android:animation">
|
||||
<set>
|
||||
<objectAnimator
|
||||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="pathData"
|
||||
android:valueFrom="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueTo="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||
android:valueFrom="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||
android:valueTo="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueType="pathType" />
|
||||
</set>
|
||||
</aapt:attr>
|
||||
</target>
|
||||
|
||||
<target android:name="pause_left">
|
||||
<target android:name="play_lower">
|
||||
<aapt:attr name="android:animation">
|
||||
<set>
|
||||
<objectAnimator
|
||||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="pathData"
|
||||
android:valueFrom="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueTo="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||
android:valueFrom="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||
android:valueTo="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueType="pathType" />
|
||||
</set>
|
||||
</aapt:attr>
|
||||
|
@ -66,8 +37,8 @@ https://github.com/ashutoshgngwr/noice
|
|||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="rotation"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="90"
|
||||
android:valueFrom="-90"
|
||||
android:valueTo="0"
|
||||
android:valueType="floatType" />
|
||||
</set>
|
||||
</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"
|
||||
xmlns:aapt="http://schemas.android.com/aapt">
|
||||
|
||||
<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>
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:drawable="@drawable/ic_play_large">
|
||||
|
||||
<target android:name="play_upper">
|
||||
<aapt:attr name="android:animation">
|
||||
|
@ -41,8 +9,8 @@ https://github.com/ashutoshgngwr/noice
|
|||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="pathData"
|
||||
android:valueFrom="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||
android:valueTo="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueFrom="M8.25,6L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueTo="M6,7.5L6,10.5L18,10.5L18,7.5Z"
|
||||
android:valueType="pathType" />
|
||||
</set>
|
||||
</aapt:attr>
|
||||
|
@ -55,8 +23,8 @@ https://github.com/ashutoshgngwr/noice
|
|||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="pathData"
|
||||
android:valueFrom="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||
android:valueTo="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueFrom="M8.25,18L8.25,12L18.75,12L18.75,12Z"
|
||||
android:valueTo="M6,16.5L6,13.5L18,13.5L18,16.5Z"
|
||||
android:valueType="pathType" />
|
||||
</set>
|
||||
</aapt:attr>
|
||||
|
@ -69,8 +37,8 @@ https://github.com/ashutoshgngwr/noice
|
|||
android:duration="200"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"
|
||||
android:propertyName="rotation"
|
||||
android:valueFrom="-90"
|
||||
android:valueTo="0"
|
||||
android:valueFrom="0"
|
||||
android:valueTo="90"
|
||||
android:valueType="floatType" />
|
||||
</set>
|
||||
</aapt:attr>
|
||||
|
|
Loading…
Reference in a new issue