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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user