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:25:13 -07:00
parent 6a273ab34d
commit 118172b7c8
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 12 additions and 15 deletions

View file

@ -352,7 +352,7 @@ class PlaybackStateManager private constructor() {
* @param to The destination index. * @param to The destination index.
*/ */
fun moveQueueItems(from: Int, to: Int): Boolean { 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") logE("Indices were out of bounds, did not move queue item")
return false return false

View file

@ -13,6 +13,7 @@ import androidx.recyclerview.widget.RecyclerView
import coil.Coil import coil.Coil
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.utils.invalidateDividers
import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.logD import org.oxycblt.auxio.logD
@ -29,6 +30,7 @@ import org.oxycblt.auxio.ui.Accent
@Suppress("UNUSED") @Suppress("UNUSED")
class SettingsListFragment : PreferenceFragmentCompat() { class SettingsListFragment : PreferenceFragmentCompat() {
private val playbackModel: PlaybackViewModel by activityViewModels() private val playbackModel: PlaybackViewModel by activityViewModels()
val settingsManager = SettingsManager.getInstance()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -93,7 +95,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
} }
SettingsManager.Keys.KEY_LIBRARY_DISPLAY_MODE -> { SettingsManager.Keys.KEY_LIBRARY_DISPLAY_MODE -> {
setIcon(SettingsManager.getInstance().libraryDisplayMode.iconRes) setIcon(settingsManager.libraryDisplayMode.iconRes)
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value -> onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, value ->
setIcon(DisplayMode.valueOfOrFallback(value as String).iconRes) setIcon(DisplayMode.valueOfOrFallback(value as String).iconRes)
@ -150,7 +152,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
val recycler = RecyclerView(requireContext()).apply { val recycler = RecyclerView(requireContext()).apply {
adapter = AccentAdapter { adapter = AccentAdapter {
if (it != Accent.get()) { if (it != Accent.get()) {
SettingsManager.getInstance().accent = it settingsManager.accent = it
requireActivity().recreate() requireActivity().recreate()
} }
@ -158,6 +160,10 @@ class SettingsListFragment : PreferenceFragmentCompat() {
this@show.dismiss() this@show.dismiss()
} }
layoutManager = LinearLayoutManager(
requireContext(), LinearLayoutManager.HORIZONTAL, false
)
post { post {
// Combine the width of the recyclerview with the width of an item in order // Combine the width of the recyclerview with the width of an item in order
// to center the currently selected accent. // to center the currently selected accent.
@ -169,15 +175,11 @@ class SettingsListFragment : PreferenceFragmentCompat() {
(width / 2) - childWidth (width / 2) - childWidth
) )
} }
layoutManager = LinearLayoutManager(
requireContext()
).also { it.orientation = LinearLayoutManager.HORIZONTAL }
} }
customView(view = recycler) customView(view = recycler)
view.invalidateDividers(showTop = false, showBottom = false) invalidateDividers(showTop = false, showBottom = false)
negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)

View file

@ -47,15 +47,10 @@
<string name="setting_theme_auto">Automatică</string> <string name="setting_theme_auto">Automatică</string>
<string name="setting_theme_day">Clar</string> <string name="setting_theme_day">Clar</string>
<string name="setting_theme_night">Întunecat</string> <string name="setting_theme_night">Întunecat</string>
<string name="setting_accent">Accent</string> <string name="setting_accent">Culoare accentuată</string>
<string name="setting_accent_unknown">Unknown Accent</string>
<string name="setting_color_notif">Colorează notificarea</string> <string name="setting_color_notif">Colorează notificarea</string>
<string name="setting_quality_covers">Ignoră coperțile Media Store</string> <string name="setting_quality_covers">Ignoră coperțile Media Store</string>
<string name="setting_quality_covers_desc">Increases the quality of the album covers, but results in longer loading times and higher memory usage</string>
<string name="setting_use_alt_action">Use alternate notification action</string>
<string name="setting_use_alt_loop">Prefer repeat mode action</string>
<string name="setting_use_alt_shuffle">Prefer shuffle action</string>
<string name="setting_audio">Audio</string> <string name="setting_audio">Audio</string>
<string name="setting_audio_focus">Concentrare audio</string> <string name="setting_audio_focus">Concentrare audio</string>

View file

@ -23,7 +23,7 @@
<string name="label_sort">Sort</string> <string name="label_sort">Sort</string>
<string name="label_sort_none">Default</string> <string name="label_sort_none">Default</string>
<string name="label_sort_alpha_down">Ascending</string> <string name="label_sort_alpha_down">Ascending</string>
<string name="label_sort_alpha_up">Decending</string> <string name="label_sort_alpha_up">Descending</string>
<string name="label_play">Play</string> <string name="label_play">Play</string>
<string name="label_shuffle">Shuffle</string> <string name="label_shuffle">Shuffle</string>