Fix song selection bug

Fix a bug where if a song is selected while shuffling it would not move that song to the beginning of the queue.
This commit is contained in:
OxygenCobalt
2021-02-15 14:27:03 -07:00
parent 6a273ab34d
commit 118172b7c8
4 changed files with 12 additions and 15 deletions
@@ -352,7 +352,7 @@ class PlaybackStateManager private constructor() {
* @param to The destination index.
*/
fun moveQueueItems(from: Int, to: Int): Boolean {
if (from > mUserQueue.size || from < 0 || to > mUserQueue.size || to < 0) {
if (from > mQueue.size || from < 0 || to > mQueue.size || to < 0) {
logE("Indices were out of bounds, did not move queue item")
return false
@@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import coil.Coil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.utils.invalidateDividers
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.logD
@@ -29,6 +30,7 @@ import org.oxycblt.auxio.ui.Accent
@Suppress("UNUSED")
class SettingsListFragment : PreferenceFragmentCompat() {
private val playbackModel: PlaybackViewModel by activityViewModels()
val settingsManager = SettingsManager.getInstance()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@@ -93,7 +95,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
}
SettingsManager.Keys.KEY_LIBRARY_DISPLAY_MODE -> {
setIcon(SettingsManager.getInstance().libraryDisplayMode.iconRes)
setIcon(settingsManager.libraryDisplayMode.iconRes)
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
setIcon(DisplayMode.valueOfOrFallback(value as String).iconRes)
@@ -150,7 +152,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
val recycler = RecyclerView(requireContext()).apply {
adapter = AccentAdapter {
if (it != Accent.get()) {
SettingsManager.getInstance().accent = it
settingsManager.accent = it
requireActivity().recreate()
}
@@ -158,6 +160,10 @@ class SettingsListFragment : PreferenceFragmentCompat() {
this@show.dismiss()
}
layoutManager = LinearLayoutManager(
requireContext(), LinearLayoutManager.HORIZONTAL, false
)
post {
// Combine the width of the recyclerview with the width of an item in order
// to center the currently selected accent.
@@ -169,15 +175,11 @@ class SettingsListFragment : PreferenceFragmentCompat() {
(width / 2) - childWidth
)
}
layoutManager = LinearLayoutManager(
requireContext()
).also { it.orientation = LinearLayoutManager.HORIZONTAL }
}
customView(view = recycler)
view.invalidateDividers(showTop = false, showBottom = false)
invalidateDividers(showTop = false, showBottom = false)
negativeButton(android.R.string.cancel)