Skip to content

Commit

Permalink
Merge pull request #314 from lucaxvi/shuffle
Browse files Browse the repository at this point in the history
Add shuffle all option in home menu - closes #313
  • Loading branch information
nift4 authored Nov 6, 2024
2 parents 4780feb + e37d2cc commit 8d1a527
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import org.akanework.gramophone.R
import org.akanework.gramophone.logic.ui.ItemHeightHelper
import org.akanework.gramophone.logic.ui.MyRecyclerView
import org.akanework.gramophone.ui.getAdapterType
import kotlin.random.Random

open class BaseDecorAdapter<T : BaseAdapter<*>>(
protected val adapter: T,
Expand Down Expand Up @@ -178,7 +177,6 @@ open class BaseDecorAdapter<T : BaseAdapter<*>>(
controller?.shuffleModeEnabled = true
list.takeIf { it.isNotEmpty() }?.also {
controller?.setMediaItems(it)
controller?.seekToDefaultPosition(Random.nextInt(0, it.size))
controller?.prepare()
controller?.play()
} ?: controller?.setMediaItems(listOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ class ViewPagerFragment : BaseFragment(true) {
R.id.settings -> {
(requireActivity() as MainActivity).startFragment(MainSettingsFragment())
}
R.id.shuffle -> {
val controller = (requireActivity() as MainActivity).getPlayer()
libraryViewModel.mediaItemList.value?.takeIf { it.isNotEmpty() }?.also {
controller?.shuffleModeEnabled = true
controller?.setMediaItems(it)
controller?.prepare()
controller?.play()
} ?: controller?.setMediaItems(listOf())
}

else -> throw IllegalStateException()
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/home_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@
android:icon="@drawable/ic_settings"
android:title="@string/home_menu_settings"
app:showAsAction="never" />
<item
android:id="@+id/shuffle"
android:icon="@drawable/ic_shuffle"
android:title="@string/home_menu_shuffle"
app:showAsAction="never" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- Translatable -->
<string name="home_menu_search">Search</string>
<string name="home_menu_settings">Settings</string>
<string name="home_menu_shuffle">Shuffle all</string>
<string name="home_menu_refresh">Refresh</string>
<string name="category_songs">Songs</string>
<string name="category_albums">Albums</string>
Expand Down

0 comments on commit 8d1a527

Please sign in to comment.