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:
OxygenCobalt 2020-10-18 13:43:29 -06:00
parent 2811c83543
commit d01aa3ea4a
12 changed files with 50 additions and 22 deletions

View file

@ -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

View file

@ -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)
}
}
}

View file

@ -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

View file

@ -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()
}
}

View file

@ -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

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/background">
android:tint="@color/control_color">
<path
android:fillColor="@android:color/white"
android:pathData="m 7.5,6 h 3 v 12 h -3 z m 9,0 h -3 v 12 h 3 z" />

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="32dp"
android:height="32dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/background">

View file

@ -110,11 +110,12 @@
android:layout_height="0dp"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_marginEnd="@dimen/margin_tiny"
android:tint="@color/background"
android:background="@drawable/ui_circular_button"
android:backgroundTint="?android:attr/colorPrimary"
android:contentDescription="@string/description_play"
android:onClick="@{() -> playbackModel.play(album, false)}"
android:src="@drawable/ic_play"
android:onClick="@{() -> playbackModel.play(album, false)}"
app:layout_constraintBottom_toBottomOf="@+id/album_details"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toStartOf="@+id/album_shuffle"

View file

@ -98,7 +98,7 @@
app:layout_constraintTop_toBottomOf="@+id/artist_genre"
tools:text="2 Albums, 20 Songs" />
<!-- TODO: Improve these two buttons so that they don't look as cluttered -->
<!-- TODO: Improve these two buttons so that they dont look as cluttered -->
<ImageButton
android:id="@+id/artist_play"
style="@style/Widget.AppCompat.Button.Borderless"
@ -106,6 +106,7 @@
android:layout_height="0dp"
android:layout_marginTop="@dimen/margin_tiny"
android:layout_marginEnd="@dimen/margin_tiny"
android:tint="@color/background"
android:background="@drawable/ui_circular_button"
android:backgroundTint="?android:attr/colorPrimary"
android:contentDescription="@string/description_play"

View file

@ -91,12 +91,12 @@
android:layout_width="@dimen/size_play_pause_compact"
android:layout_height="@dimen/size_play_pause_compact"
android:background="@drawable/ui_unbounded_ripple"
android:tint="@color/control_color"
android:onClick="@{() -> playbackModel.invertPlayingStatus()}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/ic_play_to_pause"
android:tint="@color/control_color" />
tools:src="@drawable/ic_play_to_pause" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -14,6 +14,7 @@
<dimen name="margin_mid_small">10dp</dimen>
<dimen name="margin_medium">16dp</dimen>
<dimen name="margin_mid_large">24dp</dimen>
<dimen name="margin_play">26dp</dimen>
<dimen name="margin_large">32dp</dimen>
<dimen name="margin_huge">64dp</dimen>

View file

@ -24,6 +24,7 @@
<string name="label_sort_alpha_down">A-Z</string>
<string name="label_sort_alpha_up">Z-A</string>
<string name="label_shuffle">Shuffle</string>
<string name="label_play">Play</string>
<!-- Hint Namespace | EditText Hints -->
<string name="hint_search_library">Search Library…</string>