[Android] Enqueue tracks recursively when browsing locally

Nicolas Pomepuy git at videolan.org
Mon Feb 8 07:34:39 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Feb  4 11:35:44 2021 +0100| [c680beb0b796a727efe810439263ff857810771e] | committer: Nicolas Pomepuy

Enqueue tracks recursively when browsing locally

Fixes #200

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

 .../resources/src/main/res/values/strings.xml      |  1 +
 .../vlc/gui/AudioPlayerContainerActivity.kt        |  2 +-
 .../vlc/gui/browser/BaseBrowserFragment.kt         | 42 ++++++++++++++++------
 .../src/org/videolan/vlc/gui/helpers/UiTools.kt    |  5 +++
 .../vlc/viewmodels/browser/BrowserModel.kt         |  1 -
 5 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 8c4804601..b799d6905 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -781,5 +781,6 @@
     <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="no_sub_renderer">Subtitles are not yet supported while casting</string>
+    <string name="enqueuing">Loading your medias</string>
 
 </resources>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
index c2f6ae53a..294f600d9 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.kt
@@ -111,7 +111,7 @@ open class AudioPlayerContainerActivity : BaseActivity() {
 
     override fun getSnackAnchorView(): View? {
       return  if (::audioPlayerContainer.isInitialized && audioPlayerContainer.visibility != View.GONE && ::playerBehavior.isInitialized && playerBehavior.state == STATE_COLLAPSED)
-          audioPlayerContainer else if (::playerBehavior.isInitialized && playerBehavior.state == STATE_EXPANDED) findViewById(android.R.id.content) else findViewById(R.id.coordinator) ?: findViewById(android.R.id.content)
+          audioPlayerContainer else if (::playerBehavior.isInitialized && playerBehavior.state == STATE_EXPANDED) findViewById(android.R.id.content) else if (::playerBehavior.isInitialized) findViewById(R.id.coordinator) else findViewById(android.R.id.content)
     }
 
     override fun onCreate(savedInstanceState: Bundle?) {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index 7e139256e..8e5edf51c 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -78,6 +78,8 @@ private const val KEY_POSITION = "key_list"
 private const val MSG_SHOW_LOADING = 0
 internal const val MSG_HIDE_LOADING = 1
 private const val MSG_REFRESH = 3
+private const val MSG_SHOW_ENQUEUING = 4
+private const val MSG_HIDE_ENQUEUING = 5
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -315,6 +317,8 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
 
     class BrowserFragmentHandler(owner: BaseBrowserFragment) : WeakHandler<BaseBrowserFragment>(owner) {
 
+        private var enqueuingSnackbar: Snackbar? = null
+
         override fun handleMessage(msg: Message) {
             val fragment = owner ?: return
             when (msg.what) {
@@ -327,6 +331,17 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
                     removeMessages(MSG_REFRESH)
                     if (!fragment.isDetached) fragment.refresh()
                 }
+                MSG_SHOW_ENQUEUING -> {
+                    owner?.activity?.let {
+                        enqueuingSnackbar = UiTools.snackerMessageInfinite(it, it.getString(R.string.enqueuing))
+                    }
+                    enqueuingSnackbar?.show()
+
+                }
+                MSG_HIDE_ENQUEUING -> {
+                    enqueuingSnackbar?.dismiss()
+                    removeMessages(MSG_SHOW_ENQUEUING)
+                }
             }
         }
     }
@@ -351,17 +366,22 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
     }
 
     private fun playAll(mw: MediaWrapper?) {
-        var positionInPlaylist = 0
-        val mediaLocations = LinkedList<MediaWrapper>()
-        for (file in viewModel.dataset.getList())
-            if (file is MediaWrapper) {
-                if (file.type == MediaWrapper.TYPE_VIDEO || file.type == MediaWrapper.TYPE_AUDIO) {
-                    mediaLocations.add(file)
-                    if (mw != null && file.equals(mw))
-                        positionInPlaylist = mediaLocations.size - 1
-                }
+        lifecycleScope.launch {
+            var positionInPlaylist = 0
+            val mediaLocations = LinkedList<MediaWrapper>()
+            handler.sendEmptyMessageDelayed(MSG_SHOW_ENQUEUING, 1000)
+            withContext(Dispatchers.IO) {
+                val files = if (viewModel.url?.startsWith("file") == true) viewModel.provider.browseUrl(viewModel.url!!) else viewModel.dataset.getList()
+                for (file in files.filterIsInstance(MediaWrapper::class.java))
+                    if (file.type == MediaWrapper.TYPE_VIDEO || file.type == MediaWrapper.TYPE_AUDIO) {
+                        mediaLocations.add(file)
+                        if (mw != null && file.equals(mw))
+                            positionInPlaylist = mediaLocations.size - 1
+                    }
             }
-        activity?.let { MediaUtils.openList(it, mediaLocations, positionInPlaylist) }
+            handler.sendEmptyMessage(MSG_HIDE_ENQUEUING)
+            activity?.let { MediaUtils.openList(it, mediaLocations, positionInPlaylist) }
+        }
     }
 
     override fun enableSearchOption() = !isRootDirectory
@@ -603,7 +623,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
 
     private fun updateFab() {
         fabPlay?.let {
-            if (adapter.mediaCount > 0) {
+            if (adapter.mediaCount > 0 || viewModel.url?.startsWith("file") == true) {
                 it.show()
                 it.setOnClickListener(this)
             } else {
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
index 788950155..445814efb 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.kt
@@ -284,6 +284,11 @@ object UiTools {
             sHandler.postDelayed(action, DELETE_DURATION.toLong())
     }
 
+    fun snackerMessageInfinite(activity:Activity, message: String):Snackbar? {
+        val view = getSnackAnchorView(activity) ?: return null
+        return Snackbar.make(view, message, Snackbar.LENGTH_INDEFINITE)
+    }
+
     /**
      * Get a resource id from an attribute id.
      *
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index e480bb1d0..3e9c65273 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -25,7 +25,6 @@ import androidx.annotation.MainThread
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.map
 import androidx.lifecycle.viewModelScope
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi



More information about the Android mailing list