From a6b1730c4aef269d62c3505b09b9f222eb53ee4d Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Fri, 22 Apr 2022 13:38:46 +0200 Subject: [PATCH] #116: Fix playback order to respect preference setting on albums fragment --- .../funkwhale/ffa/fragments/AlbumsFragment.kt | 67 +++++++++++-------- .../funkwhale/ffa/fragments/TracksFragment.kt | 6 ++ changes/changelog.d/116.bugfix | 1 + 3 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 changes/changelog.d/116.bugfix diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt index c671179..376a1dd 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt @@ -31,6 +31,7 @@ import audio.funkwhale.ffa.utils.CommandBus import audio.funkwhale.ffa.utils.maybeLoad import audio.funkwhale.ffa.utils.maybeNormalizeUrl import audio.funkwhale.ffa.utils.onViewPager +import com.preference.PowerPreference import com.squareup.picasso.Picasso import jp.wasabeef.picasso.transformations.RoundedCornersTransformation import kotlinx.coroutines.Dispatchers.IO @@ -125,6 +126,12 @@ class AlbumsFragment : FFAFragment() { ): View { _binding = FragmentAlbumsBinding.inflate(inflater) swiper = binding.swiper + + when (PowerPreference.getDefaultFile().getString("play_order")) { + "in_order" -> binding.play.text = getString(R.string.playback_play) + else -> binding.play.text = getString(R.string.playback_shuffle) + } + return binding.root } @@ -147,6 +154,29 @@ class AlbumsFragment : FFAFragment() { } binding.artist.text = artistName + } + + override fun onResume() { + super.onResume() + + var coverHeight: Float? = null + + binding.scroller.setOnScrollChangeListener { _: View?, _: Int, scrollY: Int, _: Int, _: Int -> + if (coverHeight == null) { + coverHeight = binding.cover.measuredHeight.toFloat() + } + + binding.cover.translationY = (scrollY / 2).toFloat() + + coverHeight?.let { height -> + binding.cover.alpha = (height - scrollY.toFloat()) / height + } + } + + when (PowerPreference.getDefaultFile().getString("play_order")) { + "in_order" -> binding.play.text = getString(R.string.playback_play) + else -> binding.play.text = getString(R.string.playback_shuffle) + } binding.play.setOnClickListener { val loader = CircularProgressDrawable(requireContext()).apply { @@ -160,38 +190,21 @@ class AlbumsFragment : FFAFragment() { binding.play.isClickable = false lifecycleScope.launch(IO) { - artistTracksRepository.fetch(Repository.Origin.Network.origin) + val tracks = artistTracksRepository.fetch(Repository.Origin.Network.origin) .map { it.data } .toList() .flatten() - .shuffled() - .also { - CommandBus.send(Command.ReplaceQueue(it)) - - withContext(Main) { - binding.play.icon = - AppCompatResources.getDrawable(binding.root.context, R.drawable.play) - binding.play.isClickable = true - } - } - } - } - } - - override fun onResume() { - super.onResume() - - var coverHeight: Float? = null - binding.scroller.setOnScrollChangeListener { _: View?, _: Int, scrollY: Int, _: Int, _: Int -> - if (coverHeight == null) { - coverHeight = binding.cover.measuredHeight.toFloat() - } - - binding.cover.translationY = (scrollY / 2).toFloat() + when (PowerPreference.getDefaultFile().getString("play_order")) { + "in_order" -> CommandBus.send(Command.ReplaceQueue(tracks)) + else -> CommandBus.send(Command.ReplaceQueue(tracks.shuffled())) + } - coverHeight?.let { height -> - binding.cover.alpha = (height - scrollY.toFloat()) / height + withContext(Main) { + binding.play.icon = + AppCompatResources.getDrawable(binding.root.context, R.drawable.play) + binding.play.isClickable = true + } } } } diff --git a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt index 231ce44..5e02657 100644 --- a/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt +++ b/app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt @@ -129,6 +129,12 @@ class TracksFragment : FFAFragment() { ): View { _binding = FragmentTracksBinding.inflate(inflater) swiper = binding.swiper + + when (PowerPreference.getDefaultFile().getString("play_order")) { + "in_order" -> binding.play.text = getString(R.string.playback_play) + else -> binding.play.text = getString(R.string.playback_shuffle) + } + return binding.root } diff --git a/changes/changelog.d/116.bugfix b/changes/changelog.d/116.bugfix new file mode 100644 index 0000000..f128d46 --- /dev/null +++ b/changes/changelog.d/116.bugfix @@ -0,0 +1 @@ +Fix playback order to respect preference setting on albums fragment \ No newline at end of file