Scroll QueueFragment on shuffle toggle

Scroll QueueFragment to the top when shuffle is toggled so that it does not flip out as much as it would otherwise.
This commit is contained in:
OxygenCobalt 2021-02-21 15:03:17 -07:00
parent 5de45eea0e
commit 299c47e9c3
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 15 additions and 5 deletions

View file

@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
// Since the activity is set to singleInstance [Given that there's only MainActivity]
// We have to manually push the intent whenever we get one so that the fragments
// can catch any file intents
// TODO: Improve this dumb chain system in one way or another
// TODO: If possible try to make this system completely
setIntent(intent)
}

View file

@ -68,13 +68,14 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
val userQueue: LiveData<MutableList<Song>> get() = mUserQueue
/** The current [PlaybackMode] that also determines the queue */
val mode: LiveData<PlaybackMode> get() = mMode
/** Whether playback is originating from the user-generated queue or not */
val isInUserQueue: LiveData<Boolean> = mIsInUserQueue
val isPlaying: LiveData<Boolean> get() = mIsPlaying
val isShuffling: LiveData<Boolean> get() = mIsShuffling
/** The current repeat mode, see [LoopMode] for more information */
val loopMode: LiveData<LoopMode> get() = mLoopMode
val isSeeking: LiveData<Boolean> get() = mIsSeeking
val canAnimate: Boolean get() = mCanAnimate

View file

@ -42,6 +42,7 @@ class QueueFragment : Fragment() {
val callback = QueueDragCallback(playbackModel)
val helper = ItemTouchHelper(callback)
val queueAdapter = QueueAdapter(helper, playbackModel)
var lastShuffle = playbackModel.isShuffling.value
callback.addQueueAdapter(queueAdapter)
@ -96,14 +97,22 @@ class QueueFragment : Fragment() {
queueAdapter.submitList(createQueueData())
}
playbackModel.isShuffling.observe(viewLifecycleOwner) {
if (it != lastShuffle) {
lastShuffle = it
binding.queueRecycler.scrollToPosition(0)
}
}
return binding.root
}
override fun onResume() {
super.onResume()
// QueueFragment shouldn't be handling file intents, as the effects it has on the recycler
// are really weird.
// QueueFragment shouldn't be handling file intents as it will cause the queue recycler
// to flip out
if (shouldHandleFileIntent()) {
findNavController().navigateUp()
}

View file

@ -14,4 +14,4 @@ Auxio is a local music player with a fast, reliable UI/UX without the many usele
- No internet connectivity whatsoever
- Kotlin from the ground-up
- Modular, feature-based architecture
- No rounded corners
- No rounded corners