[Android] Add a context action to play an album or a playlist in shuffle mode
Nicolas Pomepuy
git at videolan.org
Fri Apr 16 08:23:47 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Wed Apr 14 15:37:01 2021 +0200| [fdc371ca1064b90338f9950c58c4ba9bdf8d5479] | committer: Nicolas Pomepuy
Add a context action to play an album or a playlist in shuffle mode
Fixes #1825
> https://code.videolan.org/videolan/vlc-android/commit/fdc371ca1064b90338f9950c58c4ba9bdf8d5479
---
.../main/java/org/videolan/resources/Constants.kt | 3 +-
.../src/main/res/drawable/ic_ctx_shuffle.xml | 40 ++++++++++++++++++++++
.../resources/src/main/res/values/strings.xml | 1 +
.../org/videolan/vlc/gui/audio/BaseAudioBrowser.kt | 1 +
.../org/videolan/vlc/gui/dialogs/ContextSheet.kt | 1 +
.../src/org/videolan/vlc/media/MediaUtils.kt | 4 +--
6 files changed, 47 insertions(+), 3 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 542838cfa..c95f78089 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -181,6 +181,7 @@ const val CTX_INFORMATION = 1L shl 3
const val CTX_DELETE = 1L shl 4
const val CTX_DOWNLOAD_SUBTITLES = 1L shl 5
const val CTX_PLAY_FROM_START = 1L shl 6
+const val CTX_PLAY_SHUFFLE = 1L shl 7
const val CTX_PLAY = 1L shl 8
const val CTX_PLAY_NEXT = 1L shl 9
const val CTX_ADD_TO_PLAYLIST = 1L shl 10
@@ -211,7 +212,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 or CTX_MARK_AS_PLAYED
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
+const val CTX_PLAYLIST_ALBUM_FLAGS = CTX_AUDIO_FLAGS or CTX_DELETE or CTX_PLAY_SHUFFLE
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/resources/src/main/res/drawable/ic_ctx_shuffle.xml b/application/resources/src/main/res/drawable/ic_ctx_shuffle.xml
new file mode 100644
index 000000000..0871ca9bb
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_ctx_shuffle.xml
@@ -0,0 +1,40 @@
+<!--
+ ~ *************************************************************************
+ ~ ic_ctx_shuffle.xml
+ ~ **************************************************************************
+ ~ Copyright © 2021 VLC authors and VideoLAN
+ ~ Author: Nicolas POMEPUY
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program; if not, write to the Free Software
+ ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ ~ ***************************************************************************
+ ~
+ ~
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="40dp"
+ android:height="40dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:pathData="m14.4439,6c-0.4541,0.039 -0.623,0.6165 -0.2617,0.8944l0.7557,0.7557 -8.6451,8.6432C6.112,16.4741 6,16.7241 6,17.0002c0,0.5522 0.4476,0.9998 0.9998,0.9998 0.2762,0 0.526,-0.112 0.7069,-0.293l8.6451,-8.643 0.7499,0.7498c0,0 -0.0002,0.01 0.0098,0.01 0.2995,0.3652 0.8915,0.15 0.8866,-0.3222v-3.4994h-3.4994c-0.017,-0.0009 -0.0338,-0.0009 -0.0508,0zM6.9998,6C6.4476,6 6,6.4476 6,6.9999c0.0005,0.2684 0.1089,0.5252 0.3007,0.7128l-0.0098,0.01 2.8726,2.8725 1.4138,-1.4139 -2.7867,-2.7866c-0.1889,-0.2471 -0.4819,-0.392 -0.7928,-0.3924zM14.8189,13.4187 L13.405,14.8325 14.9302,16.3577 14.1862,17.1016c0,0 -0.0098,-0.0002 -0.0098,0.01 -0.3651,0.2995 -0.15,0.8915 0.3222,0.8866h3.4994v-3.4994c0.0009,-0.017 0.0009,-0.034 0,-0.051h0.002c-0.039,-0.4541 -0.6164,-0.623 -0.8944,-0.2617l-0.7616,0.7616z"
+ android:strokeAlpha="1"
+ android:strokeLineJoin="miter"
+ android:strokeWidth="0.99983621"
+ android:fillColor="#000000"
+ android:strokeColor="#00000000"
+ android:fillType="evenOdd"
+ android:fillAlpha="1"
+ android:strokeLineCap="butt"/>
+</vector>
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 65f3859d3..2c6b40008 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -119,6 +119,7 @@
<string name="shuffle_title">Shuffle mode</string>
<string name="shuffle">Shuffle Off</string>
<string name="shuffle_on">Shuffle On</string>
+ <string name="shuffle_play">Shuffle</string>
<string name="repeat_title">Repeat mode</string>
<string name="repeat">Repeat none</string>
<string name="repeat_single">Repeat single</string>
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 d7b256d22..6f8f19e15 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
@@ -377,6 +377,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_INFORMATION -> showInfoDialog(media)
CTX_DELETE -> removeItem(media)
CTX_APPEND -> MediaUtils.appendMedia(requireActivity(), media.tracks)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index 2354415c2..fbb115bbf 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -91,6 +91,7 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
if (flags and CTX_PLAY_ALL != 0L) add(Simple(CTX_PLAY_ALL, getString(R.string.play_all), R.drawable.ic_ctx_play_all))
if (flags and CTX_PLAY_AS_AUDIO != 0L) add(Simple(CTX_PLAY_AS_AUDIO, getString(R.string.play_as_audio), R.drawable.ic_ctx_play_as_audio))
if (flags and CTX_APPEND != 0L) add(Simple(CTX_APPEND, getString(R.string.append), R.drawable.ic_ctx_append))
+ if (flags and CTX_PLAY_SHUFFLE != 0L) add(Simple(CTX_PLAY_SHUFFLE, getString(R.string.shuffle_play), R.drawable.ic_ctx_shuffle))
if (flags and CTX_INFORMATION != 0L) add(Simple(CTX_INFORMATION, getString(R.string.info), R.drawable.ic_ctx_information))
if (flags and CTX_DOWNLOAD_SUBTITLES != 0L) add(Simple(CTX_DOWNLOAD_SUBTITLES, getString(R.string.download_subtitles), R.drawable.ic_ctx_download))
if (flags and CTX_PLAY_NEXT != 0L) add(Simple(CTX_PLAY_NEXT, getString(R.string.insert_next), R.drawable.ic_ctx_play_next))
diff --git a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
index ea8f3b7dc..73da95fd8 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/MediaUtils.kt
@@ -171,8 +171,8 @@ object MediaUtils {
}
}
- fun playTracks(context: Context, item: MediaLibraryItem, position: Int) = context.scope.launch {
- openList(context, withContext(Dispatchers.IO) { item.tracks }.toList(), position)
+ fun playTracks(context: Context, item: MediaLibraryItem, position: Int, shuffle:Boolean = false) = context.scope.launch {
+ openList(context, withContext(Dispatchers.IO) { item.tracks }.toList(), position, shuffle)
}
fun playAlbums(context: Context?, provider: MedialibraryProvider<Album>, position: Int, shuffle: Boolean) {
More information about the Android
mailing list