Browse Source

#116: Fix playback order to respect preference setting on albums fragment

technical/upgrade-exoplayer
Ryan Harg 3 years ago committed by Ryan Harg
parent
commit
a6b1730c4a
  1. 67
      app/src/main/java/audio/funkwhale/ffa/fragments/AlbumsFragment.kt
  2. 6
      app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt
  3. 1
      changes/changelog.d/116.bugfix

67
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.maybeLoad
import audio.funkwhale.ffa.utils.maybeNormalizeUrl import audio.funkwhale.ffa.utils.maybeNormalizeUrl
import audio.funkwhale.ffa.utils.onViewPager import audio.funkwhale.ffa.utils.onViewPager
import com.preference.PowerPreference
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -125,6 +126,12 @@ class AlbumsFragment : FFAFragment<Album, AlbumsAdapter>() {
): View { ): View {
_binding = FragmentAlbumsBinding.inflate(inflater) _binding = FragmentAlbumsBinding.inflate(inflater)
swiper = binding.swiper 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 return binding.root
} }
@ -147,6 +154,29 @@ class AlbumsFragment : FFAFragment<Album, AlbumsAdapter>() {
} }
binding.artist.text = artistName 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 { binding.play.setOnClickListener {
val loader = CircularProgressDrawable(requireContext()).apply { val loader = CircularProgressDrawable(requireContext()).apply {
@ -160,38 +190,21 @@ class AlbumsFragment : FFAFragment<Album, AlbumsAdapter>() {
binding.play.isClickable = false binding.play.isClickable = false
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
artistTracksRepository.fetch(Repository.Origin.Network.origin) val tracks = artistTracksRepository.fetch(Repository.Origin.Network.origin)
.map { it.data } .map { it.data }
.toList() .toList()
.flatten() .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 -> when (PowerPreference.getDefaultFile().getString("play_order")) {
if (coverHeight == null) { "in_order" -> CommandBus.send(Command.ReplaceQueue(tracks))
coverHeight = binding.cover.measuredHeight.toFloat() else -> CommandBus.send(Command.ReplaceQueue(tracks.shuffled()))
} }
binding.cover.translationY = (scrollY / 2).toFloat()
coverHeight?.let { height -> withContext(Main) {
binding.cover.alpha = (height - scrollY.toFloat()) / height binding.play.icon =
AppCompatResources.getDrawable(binding.root.context, R.drawable.play)
binding.play.isClickable = true
}
} }
} }
} }

6
app/src/main/java/audio/funkwhale/ffa/fragments/TracksFragment.kt

@ -129,6 +129,12 @@ class TracksFragment : FFAFragment<Track, TracksAdapter>() {
): View { ): View {
_binding = FragmentTracksBinding.inflate(inflater) _binding = FragmentTracksBinding.inflate(inflater)
swiper = binding.swiper 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 return binding.root
} }

1
changes/changelog.d/116.bugfix

@ -0,0 +1 @@
Fix playback order to respect preference setting on albums fragment
Loading…
Cancel
Save