Prevent animated icons from animation on startup
Make ImageButtons that use animated icons not animate when the fragment is initially created.
This commit is contained in:
@@ -122,7 +122,10 @@ class AlbumDetailFragment : Fragment() {
|
||||
// Update the play button depending on the current playback status
|
||||
// If playing this album -> Make button show media controls
|
||||
// If not playing this album -> Make button update playback to the artist
|
||||
private fun updatePlayButton(mode: PlaybackMode, binding: FragmentAlbumDetailBinding) {
|
||||
private fun updatePlayButton(
|
||||
mode: PlaybackMode,
|
||||
binding: FragmentAlbumDetailBinding
|
||||
) {
|
||||
playbackModel.currentParent.value?.let { parent ->
|
||||
if (mode == PlaybackMode.IN_ALBUM &&
|
||||
parent.id == detailModel.currentAlbum.value!!.id
|
||||
|
||||
@@ -105,7 +105,10 @@ class ArtistDetailFragment : Fragment() {
|
||||
// Update the play button depending on the current playback status
|
||||
// If playing this artist -> Make button show media controls
|
||||
// If not playing this artist -> Make button update playback to the artist
|
||||
private fun updatePlayButton(mode: PlaybackMode, binding: FragmentArtistDetailBinding) {
|
||||
private fun updatePlayButton(
|
||||
mode: PlaybackMode,
|
||||
binding: FragmentArtistDetailBinding
|
||||
) {
|
||||
playbackModel.currentParent.value?.let { parent ->
|
||||
if (mode == PlaybackMode.IN_ARTIST &&
|
||||
parent.id == detailModel.currentArtist.value!!.id
|
||||
@@ -123,7 +126,7 @@ class ArtistDetailFragment : Fragment() {
|
||||
binding.artistPlay.setImageResource(R.drawable.ic_play)
|
||||
|
||||
binding.artistPlay.setOnClickListener {
|
||||
playbackModel.play(detailModel.currentArtist.value!!, false)
|
||||
playbackModel.play(detailModel.currentAlbum.value!!, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ import coil.fetch.SourceResult
|
||||
import coil.size.Size
|
||||
import okio.buffer
|
||||
import okio.source
|
||||
import java.io.InputStream
|
||||
import org.oxycblt.auxio.R
|
||||
import java.io.InputStream
|
||||
|
||||
const val MOSAIC_BITMAP_SIZE = 512
|
||||
const val MOSAIC_BITMAP_INCREMENT = 256
|
||||
|
||||
@@ -61,13 +61,21 @@ class CompactPlaybackFragment : Fragment() {
|
||||
|
||||
// TODO: Fix the thing where the icons will animate on startup
|
||||
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(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
} else {
|
||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
}
|
||||
} else {
|
||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
if (it) {
|
||||
binding.playbackControls.setImageResource(R.drawable.ic_pause)
|
||||
} else {
|
||||
binding.playbackControls.setImageResource(R.drawable.ic_play)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,9 +88,9 @@ class CompactPlaybackFragment : Fragment() {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
|
||||
playbackModel.updateStaticIconStatus(true)
|
||||
playbackModel.resetAnimStatus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,14 @@ class PlaybackViewModel : ViewModel() {
|
||||
val isShuffling: LiveData<Boolean> get() = mIsShuffling
|
||||
|
||||
private val mShuffleSeed = MutableLiveData(-1L)
|
||||
val shuffleSeed: LiveData<Long> get() = mShuffleSeed
|
||||
|
||||
private val mIsSeeking = MutableLiveData(false)
|
||||
val isSeeking: LiveData<Boolean> get() = mIsSeeking
|
||||
|
||||
private var mCanAnimate = false
|
||||
val canAnimate: Boolean get() = mCanAnimate
|
||||
|
||||
// Formatted variants of the duration
|
||||
val formattedCurrentDuration = Transformations.map(mCurrentDuration) {
|
||||
it.toDuration()
|
||||
@@ -136,6 +140,8 @@ class PlaybackViewModel : ViewModel() {
|
||||
// Invert, not directly set the playing/shuffling status
|
||||
// Used by the toggle buttons in playback fragment.
|
||||
fun invertPlayingStatus() {
|
||||
mCanAnimate = true
|
||||
|
||||
mIsPlaying.value = !mIsPlaying.value!!
|
||||
}
|
||||
|
||||
@@ -183,6 +189,10 @@ class PlaybackViewModel : ViewModel() {
|
||||
updatePlayback(mQueue.value!![mCurrentIndex.value!!])
|
||||
}
|
||||
|
||||
fun resetAnimStatus() {
|
||||
mCanAnimate = false
|
||||
}
|
||||
|
||||
private fun updatePlayback(song: Song) {
|
||||
mCurrentSong.value = song
|
||||
mCurrentDuration.value = 0
|
||||
|
||||
Reference in New Issue
Block a user