[Android] Add support for starting on a random track. Add shuffle to artist and genre overflow menus. Only show shuffle option if more than two tracks are present.
Robert Stone
git at videolan.org
Thu Aug 5 06:31:29 UTC 2021
vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Wed Jul 28 21:50:39 2021 -0700| [0f6a2260aca38f8061339475b0326c65111f273d] | committer: Nicolas Pomepuy
Add support for starting on a random track. Add shuffle to artist and genre overflow menus. Only show shuffle option if more than two tracks are present.
> https://code.videolan.org/videolan/vlc-android/commit/0f6a2260aca38f8061339475b0326c65111f273d
---
.../src/main/java/org/videolan/resources/Constants.kt | 2 +-
.../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt | 12 +++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index 5b9e8cdab..37101ae17 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -217,7 +217,7 @@ const val CTX_GO_TO_FOLDER = 1L shl 38
const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO or CTX_ADD_TO_PLAYLIST or CTX_SHARE
const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE or CTX_SHARE or CTX_GO_TO_FOLDER
const val CTX_AUDIO_FLAGS = CTX_PLAY or CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION
-const val CTX_PLAYLIST_ALBUM_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE or CTX_PLAY_SHUFFLE
+const val CTX_PLAYLIST_ALBUM_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE
const val CTX_PLAYLIST_ITEM_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_ADD_TO_PLAYLIST or CTX_INFORMATION or CTX_DELETE or CTX_SET_RINGTONE or CTX_SHARE
const val CTX_VIDEO_GROUP_FLAGS = CTX_APPEND or CTX_MARK_ALL_AS_PLAYED
const val CTX_FOLDER_FLAGS = CTX_PLAY or CTX_APPEND or CTX_ADD_TO_PLAYLIST or CTX_MARK_ALL_AS_PLAYED
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
index a9bdc349b..62b90002d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt
@@ -25,7 +25,6 @@ package org.videolan.vlc.gui.audio
import android.content.res.Configuration
import android.content.res.Resources
-import android.graphics.Rect
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
@@ -65,7 +64,9 @@ import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.util.getScreenWidth
import org.videolan.vlc.util.share
import org.videolan.vlc.viewmodels.MedialibraryViewModel
+import java.security.SecureRandom
import java.util.*
+import kotlin.math.min
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
@@ -356,7 +357,12 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {
val flags: Long = when (item.itemType) {
MediaLibraryItem.TYPE_MEDIA -> CTX_TRACK_FLAGS
- MediaLibraryItem.TYPE_PLAYLIST, MediaLibraryItem.TYPE_ALBUM -> CTX_PLAYLIST_ALBUM_FLAGS
+ MediaLibraryItem.TYPE_ARTIST, MediaLibraryItem.TYPE_GENRE -> {
+ if (item.tracksCount > 2) CTX_AUDIO_FLAGS or CTX_PLAY_SHUFFLE else CTX_AUDIO_FLAGS
+ }
+ MediaLibraryItem.TYPE_PLAYLIST, MediaLibraryItem.TYPE_ALBUM -> {
+ if (item.tracksCount > 2) CTX_PLAYLIST_ALBUM_FLAGS or CTX_PLAY_SHUFFLE else CTX_PLAYLIST_ALBUM_FLAGS
+ }
else -> CTX_AUDIO_FLAGS
}
if (actionMode == null) showContext(requireActivity(), this, position, item.title, flags)
@@ -380,7 +386,7 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
val media = getCurrentAdapter()?.getItem(position) ?: return
when (option) {
CTX_PLAY -> MediaUtils.playTracks(requireActivity(), media, 0)
- CTX_PLAY_SHUFFLE -> MediaUtils.playTracks(requireActivity(), media, 0, true)
+ CTX_PLAY_SHUFFLE -> MediaUtils.playTracks(requireActivity(), media, SecureRandom().nextInt(min(media.tracksCount, MEDIALIBRARY_PAGE_SIZE)), true)
CTX_INFORMATION -> showInfoDialog(media)
CTX_DELETE -> removeItem(media)
CTX_APPEND -> MediaUtils.appendMedia(requireActivity(), media.tracks)
More information about the Android
mailing list