[Android] Add the browse parent option to play queue items

Nicolas Pomepuy git at videolan.org
Thu Aug 11 12:49:32 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Aug 11 07:54:28 2022 +0200| [6a45d2c341a160d909089d6609d627b65c9f7aa8] | committer: Duncan McNamara

Add the browse parent option to play queue items

> https://code.videolan.org/videolan/vlc-android/commit/6a45d2c341a160d909089d6609d627b65c9f7aa8
---

 .../vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt  | 12 ------------
 .../src/org/videolan/vlc/gui/HistoryFragment.kt           |  1 +
 .../src/org/videolan/vlc/gui/audio/AudioPlayer.kt         |  4 +++-
 .../src/org/videolan/vlc/gui/audio/BaseAudioBrowser.kt    |  1 +
 .../vlc-android/src/org/videolan/vlc/util/Kextensions.kt  | 15 +++++++++++++++
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
index 97adfdf5a..9858c1627 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/BaseFragment.kt
@@ -15,11 +15,9 @@ import androidx.lifecycle.lifecycleScope
 import com.google.android.material.floatingactionbutton.FloatingActionButton
 import kotlinx.coroutines.Job
 import kotlinx.coroutines.delay
-import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.TAG_ITEM
-import org.videolan.tools.retrieveParent
 import org.videolan.tools.setGone
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.browser.KEY_IN_MEDIALIB
@@ -119,16 +117,6 @@ abstract class BaseFragment : Fragment(), ActionMode.Callback {
         startActivity(i)
     }
 
-    protected fun showParentFolder(media: MediaWrapper) {
-        val parent = MLServiceLocator.getAbstractMediaWrapper(media.uri.retrieveParent()).apply {
-            type = MediaWrapper.TYPE_DIR
-        }
-        val intent = Intent(requireActivity().applicationContext, SecondaryActivity::class.java)
-        intent.putExtra(KEY_MEDIA, parent)
-        intent.putExtra("fragment", SecondaryActivity.FILE_BROWSER)
-        startActivity(intent)
-    }
-
     protected fun setRefreshing(refreshing: Boolean, action: ((loading: Boolean) -> Unit)? = null) {
         refreshJob = lifecycleScope.launchWhenStarted {
             if (refreshing) delay(300L)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
index 3c0704c5b..b9d4e6ec2 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HistoryFragment.kt
@@ -48,6 +48,7 @@ import org.videolan.vlc.interfaces.IRefreshable
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.util.launchWhenStarted
+import org.videolan.vlc.util.showParentFolder
 import org.videolan.vlc.viewmodels.HistoryModel
 
 private const val TAG = "VLC/HistoryFragment"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 0726f43fc..497198be4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -82,6 +82,7 @@ import org.videolan.vlc.media.PlaylistManager.Companion.hasMedia
 import org.videolan.vlc.util.TextUtils
 import org.videolan.vlc.util.launchWhenStarted
 import org.videolan.vlc.util.share
+import org.videolan.vlc.util.showParentFolder
 import org.videolan.vlc.viewmodels.BookmarkModel
 import org.videolan.vlc.viewmodels.PlaybackProgress
 import org.videolan.vlc.viewmodels.PlaylistModel
@@ -312,6 +313,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
                 }
                 CTX_STOP_AFTER_THIS -> playlistModel.stopAfter(position)
                 CTX_INFORMATION -> showInfoDialog(playlistAdapter.getItem(position))
+                CTX_GO_TO_FOLDER -> showParentFolder(playlistAdapter.getItem(position))
                 CTX_SHARE -> lifecycleScope.launch { (requireActivity() as AppCompatActivity).share(playlistAdapter.getItem(position)) }
             }
         }
@@ -326,7 +328,7 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
     override fun onPopupMenu(view: View, position: Int, item: MediaWrapper?) {
         val activity = activity
         if (activity === null || position >= playlistAdapter.itemCount) return
-        var flags = CTX_REMOVE_FROM_PLAYLIST or CTX_STOP_AFTER_THIS or CTX_INFORMATION
+        var flags = CTX_REMOVE_FROM_PLAYLIST or CTX_STOP_AFTER_THIS or CTX_INFORMATION or CTX_GO_TO_FOLDER
         if (item?.uri?.scheme != "content") flags = flags or CTX_ADD_TO_PLAYLIST or CTX_SHARE or CTX_SET_RINGTONE
         showContext(activity, ctxReceiver, position, item, flags)
     }
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 2587ff97c..ff72447d3 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
@@ -69,6 +69,7 @@ import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
 import org.videolan.vlc.util.getScreenWidth
 import org.videolan.vlc.util.share
+import org.videolan.vlc.util.showParentFolder
 import org.videolan.vlc.viewmodels.MedialibraryViewModel
 import java.security.SecureRandom
 import java.util.*
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 8b234a2c1..be456628b 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.collect
 import org.videolan.libvlc.Media
 import org.videolan.libvlc.interfaces.IMedia
 import org.videolan.libvlc.util.AndroidUtil
+import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
@@ -47,7 +48,10 @@ import org.videolan.resources.AndroidDevices
 import org.videolan.resources.util.getFromMl
 import org.videolan.tools.AppScope
 import org.videolan.tools.isStarted
+import org.videolan.tools.retrieveParent
 import org.videolan.vlc.R
+import org.videolan.vlc.gui.SecondaryActivity
+import org.videolan.vlc.gui.browser.KEY_MEDIA
 import java.io.File
 import java.lang.ref.WeakReference
 import java.net.URI
@@ -376,3 +380,14 @@ val View.scope : CoroutineScope
 fun <T> Flow<T>.launchWhenStarted(scope: LifecycleCoroutineScope): Job = scope.launchWhenStarted {
     collect() // tail-call
 }
+
+
+fun Fragment.showParentFolder(media: MediaWrapper) {
+    val parent = MLServiceLocator.getAbstractMediaWrapper(media.uri.retrieveParent()).apply {
+        type = MediaWrapper.TYPE_DIR
+    }
+    val intent = Intent(requireActivity().applicationContext, SecondaryActivity::class.java)
+    intent.putExtra(KEY_MEDIA, parent)
+    intent.putExtra("fragment", SecondaryActivity.FILE_BROWSER)
+    startActivity(intent)
+}
\ No newline at end of file



More information about the Android mailing list