[Android] Allow picking subtitles for media tht are not files
Nicolas Pomepuy
git at videolan.org
Tue Oct 13 14:27:27 CEST 2020
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Oct 8 10:26:38 2020 +0200| [51ff335465c86fa09a3ec2054c2257464e6529e7] | committer: Nicolas Pomepuy
Allow picking subtitles for media tht are not files
Fixes #1484
> https://code.videolan.org/videolan/vlc-android/commit/51ff335465c86fa09a3ec2054c2257464e6529e7
---
.../src/org/videolan/vlc/gui/browser/FilePickerFragment.kt | 10 +++++++++-
.../src/org/videolan/vlc/providers/FilePickerProvider.kt | 4 ++++
.../vlc-android/src/org/videolan/vlc/util/Browserutils.kt | 5 +++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.kt
index 8a8149ae0e..f9833317c6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/FilePickerFragment.kt
@@ -25,6 +25,7 @@ package org.videolan.vlc.gui.browser
import android.app.Activity
import android.content.Intent
+import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.core.net.toUri
@@ -43,6 +44,7 @@ import org.videolan.vlc.R
import org.videolan.vlc.gui.ContentActivity
import org.videolan.vlc.repository.DirectoryRepository
import org.videolan.vlc.util.FileUtils
+import org.videolan.vlc.util.isSchemeFile
import org.videolan.vlc.viewmodels.browser.BrowserModel
import org.videolan.vlc.viewmodels.browser.TYPE_PICKER
@@ -67,7 +69,13 @@ class FilePickerFragment : FileBrowserFragment(), BrowserContainer<MediaLibraryI
}
override fun setupBrowser() {
- viewModel = ViewModelProviders.of(this, BrowserModel.Factory(requireContext(), mrl, TYPE_PICKER, false)).get(BrowserModel::class.java)
+ //if scheme is not file, we want to allow picking anywhere
+ val url = try {
+ if (Uri.parse(mrl).scheme.isSchemeFile()) mrl else null
+ } catch (e: Exception) {
+ mrl
+ }
+ viewModel = ViewModelProviders.of(this, BrowserModel.Factory(requireContext(), url, TYPE_PICKER, false)).get(BrowserModel::class.java)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
index 556cd467e5..abf0734c68 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/FilePickerProvider.kt
@@ -21,6 +21,8 @@
package org.videolan.vlc.providers
import android.content.Context
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.libvlc.interfaces.IMedia
import org.videolan.libvlc.util.MediaBrowser
import org.videolan.medialibrary.MLServiceLocator
@@ -28,6 +30,8 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.tools.livedata.LiveDataset
+ at ExperimentalCoroutinesApi
+ at ObsoleteCoroutinesApi
class FilePickerProvider(context: Context, dataset: LiveDataset<MediaLibraryItem>, url: String?, showDummyCategory: Boolean = false) : FileBrowserProvider(context, dataset, url, true, false, showDummyCategory) {
override fun getFlags(interact : Boolean) = if (interact) MediaBrowser.Flag.NoSlavesAutodetect
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
index 5a45eaba27..a491bfdeed 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Browserutils.kt
@@ -36,6 +36,11 @@ fun String?.isSchemeNetwork() = when(this) {
else -> false
}
+fun String?.isSchemeFile() = when(this) {
+ "file", null -> true
+ else -> false
+}
+
fun convertFavorites(browserFavs: List<BrowserFav>?) = browserFavs?.filter {
it.uri.scheme != "file" || File(it.uri.path).exists()
}?.map { (uri, _, title, iconUrl) ->
More information about the Android
mailing list