Move play/pause animation code
Move the code responsible for the play/pause animation to the onCreateView function instead of onResume.
This commit is contained in:
parent
7f0042fd2f
commit
b9720286c3
5 changed files with 25 additions and 35 deletions
|
@ -56,6 +56,8 @@ class MainActivity : AppCompatActivity() {
|
|||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
|
||||
// If this intent is a valid view intent that has not been used already, give it
|
||||
// to PlaybackViewModel to be used later.
|
||||
if (intent != null) {
|
||||
val action = intent.action
|
||||
val isConsumed = intent.getBooleanExtra(KEY_INTENT_CONSUMED, false)
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.oxycblt.auxio.databinding.FragmentCompactPlaybackBinding
|
|||
import org.oxycblt.auxio.detail.DetailViewModel
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.ui.memberBinding
|
||||
|
||||
/**
|
||||
* A [Fragment] that displays the currently played song at a glance, with some basic controls.
|
||||
|
@ -24,13 +23,14 @@ import org.oxycblt.auxio.ui.memberBinding
|
|||
class CompactPlaybackFragment : Fragment() {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
private val detailModel: DetailViewModel by activityViewModels()
|
||||
private val binding by memberBinding(FragmentCompactPlaybackBinding::inflate)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val binding = FragmentCompactPlaybackBinding.inflate(inflater)
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
@ -55,6 +55,8 @@ class CompactPlaybackFragment : Fragment() {
|
|||
|
||||
// --- VIEWMODEL SETUP ---
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (song != null) {
|
||||
logD("Updating song display to ${song.name}")
|
||||
|
@ -64,20 +66,14 @@ class CompactPlaybackFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
logD("Fragment Created")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
binding.playbackPlayPause.setPlaying(it, playbackModel.canAnimate)
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
}
|
||||
|
||||
logD("Fragment Created")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.oxycblt.auxio.playback
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
|
@ -32,9 +31,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
playbackSong.isSelected = false
|
||||
}
|
||||
|
||||
private lateinit var accentColor: ColorStateList
|
||||
private lateinit var controlColor: ColorStateList
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
@ -44,8 +40,8 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
// Would require writing my own variant though to avoid index updates
|
||||
|
||||
val normalTextColor = binding.playbackDurationCurrent.currentTextColor
|
||||
accentColor = Accent.get().getStateList(requireContext())
|
||||
controlColor = R.color.control_color.toStateList(requireContext())
|
||||
val accentColor = Accent.get().getStateList(requireContext())
|
||||
val controlColor = R.color.control_color.toStateList(requireContext())
|
||||
|
||||
// Can't set the tint of a MenuItem below Android 8, so use icons instead.
|
||||
val iconQueueActive = R.drawable.ic_queue.toDrawable(requireContext())
|
||||
|
@ -82,6 +78,8 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
|
||||
// --- VIEWMODEL SETUP --
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.song.observe(viewLifecycleOwner) { song ->
|
||||
if (song != null) {
|
||||
logD("Updating song display to ${song.name}.")
|
||||
|
@ -158,6 +156,15 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
binding.playbackPlayPause.apply {
|
||||
backgroundTintList = if (it) accentColor else controlColor
|
||||
setPlaying(it, playbackModel.canAnimate)
|
||||
}
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
}
|
||||
|
||||
detailModel.navToItem.observe(viewLifecycleOwner) {
|
||||
if (it != null) {
|
||||
findNavController().navigateUp()
|
||||
|
@ -169,21 +176,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
|||
return binding.root
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
playbackModel.isPlaying.observe(viewLifecycleOwner) {
|
||||
binding.playbackPlayPause.apply {
|
||||
backgroundTintList = if (it) accentColor else controlColor
|
||||
setPlaying(it, playbackModel.canAnimate)
|
||||
}
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
// --- SEEK CALLBACKS ---
|
||||
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.oxycblt.auxio.ui.toStateList
|
|||
|
||||
/**
|
||||
* A [Fragment] that allows for the searching of the entire music library.
|
||||
* TODO: Add "Recent Searches" & No Results indicator
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class SearchFragment : Fragment() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--Animated icons derived from noice https://github.com/ashutoshgngwr/noice/ FIXME: Possible issue where a seam will appear on these icons at a certain size-->
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Animated 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"
|
||||
android:drawable="@drawable/ic_pause_large">
|
||||
|
|
Loading…
Reference in a new issue