[Android] Add go to artist/album to the track ctx

Nicolas Pomepuy git at videolan.org
Wed Nov 20 06:47:53 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 12 15:12:23 2024 +0200| [316e3b4c3b0bbf3393e89303164318ab45ba1f74] | committer: Duncan McNamara

Add go to artist/album to the track ctx

Fixes #3085

> https://code.videolan.org/videolan/vlc-android/commit/316e3b4c3b0bbf3393e89303164318ab45ba1f74
---

 application/resources/src/main/res/values/strings.xml |  2 ++
 .../org/videolan/vlc/gui/HeaderMediaListActivity.kt   | 10 ++++++++++
 .../org/videolan/vlc/gui/audio/BaseAudioBrowser.kt    | 19 +++++++++++++++++++
 .../src/org/videolan/vlc/gui/dialogs/ContextSheet.kt  |  2 ++
 .../src/org/videolan/vlc/util/ContextOption.kt        |  9 +++++----
 5 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index deb14cc4c5..bb40d79ea1 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -1014,6 +1014,8 @@
     <string name="audio_delay_bt">Audio delay set to %s ms for the bluetooth device</string>
     <string name="warning_stream_speed">Increasing playback speed over 1 for streams may cause stuttering</string>
     <string name="go_to_folder">Browse parent</string>
+    <string name="go_to_album">Go to album</string>
+    <string name="go_to_artist">Go to artist</string>
     <string name="create_shortcut">Create a launcher shortcut</string>
     <string name="no_sub_renderer">Subtitles are not yet supported while casting</string>
     <string name="enqueuing">Loading your media</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index be361202b1..ac47fe5ec9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -368,6 +368,7 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
                     if (item.isFavorite) add(CTX_FAV_REMOVE) else add(CTX_FAV_ADD)
                     if (media.type == MediaWrapper.TYPE_STREAM || (media.type == MediaWrapper.TYPE_ALL && isSchemeHttpOrHttps(media.uri.scheme)))
                         addAll(CTX_COPY, CTX_RENAME)
+                    if (media.type == MediaWrapper.TYPE_AUDIO) add(CTX_GO_TO_ARTIST)
                     else add(CTX_SHARE)
                 }
                 showContext(this, this, position, media, flags)
@@ -501,6 +502,15 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
                 media.isFavorite = option == CTX_FAV_ADD
             }
             CTX_ADD_SHORTCUT -> lifecycleScope.launch { createShortcut(media) }
+            CTX_GO_TO_ARTIST -> lifecycleScope.launch(Dispatchers.IO) {
+                val artist = if (media is Album) media.retrieveAlbumArtist() else (media as MediaWrapper).getArtistWrapper()
+                val i = Intent(this at HeaderMediaListActivity, SecondaryActivity::class.java)
+                i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUMS_SONGS)
+                i.putExtra(AudioBrowserFragment.TAG_ITEM, artist)
+                i.putExtra(ARTIST_FROM_ALBUM, true)
+                i.flags = i.flags or Intent.FLAG_ACTIVITY_NO_HISTORY
+                startActivity(i)
+            }
             else -> {}
         }
 
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 88ad66e6d7..8d9fe60ce1 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
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.audio
 
+import android.content.Intent
 import android.content.res.Configuration
 import android.content.res.Resources
 import android.os.Bundle
@@ -47,10 +48,14 @@ import kotlinx.coroutines.withContext
 import org.videolan.medialibrary.interfaces.media.*
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.*
+import org.videolan.resources.util.getFromMl
 import org.videolan.tools.*
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.ContentActivity
+import org.videolan.vlc.gui.HeaderMediaListActivity
+import org.videolan.vlc.gui.HeaderMediaListActivity.Companion.ARTIST_FROM_ALBUM
+import org.videolan.vlc.gui.SecondaryActivity
 import org.videolan.vlc.gui.browser.MediaBrowserFragment
 import org.videolan.vlc.gui.dialogs.CtxActionReceiver
 import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
@@ -442,6 +447,20 @@ abstract class BaseAudioBrowser<T : MedialibraryViewModel> : MediaBrowserFragmen
                 }
             }
             CTX_INFORMATION -> showInfoDialog(media)
+            CTX_GO_TO_ALBUM -> lifecycleScope.launch(Dispatchers.IO) {
+                val i = Intent(activity, HeaderMediaListActivity::class.java)
+                i.putExtra(AudioBrowserFragment.TAG_ITEM, (media as MediaWrapper).getAlbumWrapper())
+                startActivity(i)
+            }
+            CTX_GO_TO_ARTIST -> lifecycleScope.launch(Dispatchers.IO) {
+                val artist = if (media is Album) media.retrieveAlbumArtist() else (media as MediaWrapper).getArtistWrapper()
+                val i = Intent(requireActivity(), SecondaryActivity::class.java)
+                i.putExtra(SecondaryActivity.KEY_FRAGMENT, SecondaryActivity.ALBUMS_SONGS)
+                i.putExtra(AudioBrowserFragment.TAG_ITEM, artist)
+                i.putExtra(ARTIST_FROM_ALBUM, true)
+                i.flags = i.flags or Intent.FLAG_ACTIVITY_NO_HISTORY
+                startActivity(i)
+            }
             CTX_DELETE -> removeItem(media)
             CTX_APPEND -> MediaUtils.appendMedia(requireActivity(), media.tracks)
             CTX_PLAY_NEXT -> MediaUtils.insertNext(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 0116eecd24..98d3c95af4 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
@@ -119,6 +119,8 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
         if (flags.contains(CTX_PLAY_NEXT)) add(Simple(CTX_PLAY_NEXT, getString(R.string.insert_next), R.drawable.ic_play_next))
         if (flags.contains(CTX_DOWNLOAD_SUBTITLES)) add(Simple(CTX_DOWNLOAD_SUBTITLES, getString(R.string.download_subtitles), R.drawable.ic_download_subtitles))
         if (flags.contains(CTX_INFORMATION)) add(Simple(CTX_INFORMATION, getString(R.string.info), R.drawable.ic_information))
+        if (flags.contains(CTX_GO_TO_ALBUM)) add(Simple(CTX_GO_TO_ALBUM, getString(R.string.go_to_album), R.drawable.ic_album))
+        if (flags.contains(CTX_GO_TO_ARTIST)) add(Simple(CTX_GO_TO_ARTIST, getString(R.string.go_to_artist), R.drawable.ic_no_artist))
         if (flags.contains(CTX_ADD_TO_PLAYLIST)) add(Simple(CTX_ADD_TO_PLAYLIST, getString(R.string.add_to_playlist), R.drawable.ic_add_to_playlist))
         if (flags.contains(CTX_SET_RINGTONE) && AndroidDevices.isPhone) add(Simple(CTX_SET_RINGTONE, getString(R.string.set_song), R.drawable.ic_set_ringtone))
         if (flags.contains(CTX_FAV_ADD)) add(Simple(CTX_FAV_ADD, getString(R.string.favorites_add), R.drawable.ic_fav_add))
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ContextOption.kt b/application/vlc-android/src/org/videolan/vlc/util/ContextOption.kt
index c3dd157cbf..f3b8098406 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ContextOption.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ContextOption.kt
@@ -59,7 +59,9 @@ enum class ContextOption : Flag {
     CTX_SET_RINGTONE,
     CTX_SHARE,
     CTX_STOP_AFTER_THIS,
-    CTX_UNGROUP;
+    CTX_UNGROUP,
+    CTX_GO_TO_ALBUM,
+    CTX_GO_TO_ARTIST;
 
     override fun toLong() = 1L shl this.ordinal
 
@@ -75,7 +77,7 @@ enum class ContextOption : Flag {
         }
 
         fun createCtxTrackFlags() = createBaseFlags().apply {
-            addAll(CTX_DELETE, CTX_GO_TO_FOLDER, CTX_INFORMATION, CTX_PLAY_ALL, CTX_PLAY_NEXT)
+            addAll(CTX_DELETE, CTX_GO_TO_FOLDER, CTX_INFORMATION, CTX_GO_TO_ALBUM, CTX_GO_TO_ARTIST, CTX_PLAY_ALL, CTX_PLAY_NEXT)
             addAll(CTX_SET_RINGTONE, CTX_SHARE)
         }
 
@@ -84,8 +86,7 @@ enum class ContextOption : Flag {
         }
 
         fun createCtxPlaylistAlbumFlags() = createCtxAudioFlags().apply {
-            add(CTX_DELETE)
-            add(CTX_RENAME)
+            addAll(CTX_DELETE, CTX_RENAME, CTX_GO_TO_ARTIST)
         }
 
         fun createCtxPlaylistItemFlags() = createBaseFlags().apply {



More information about the Android mailing list