[Android] Allow removing a stream from the DB

Nicolas Pomepuy git at videolan.org
Tue Mar 24 09:41:05 CET 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Mar 17 08:51:46 2020 +0100| [c0004a84f36edfc4f79db859acb5447b2e354ad3] | committer: Nicolas Pomepuy

Allow removing a stream from the DB

Fixes #1228

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

 application/resources/src/main/res/values/strings.xml    |  1 +
 application/vlc-android/res/layout-v21/mrl_panel.xml     |  7 ++++---
 application/vlc-android/res/layout/mrl_panel.xml         |  7 ++++---
 .../src/org/videolan/vlc/gui/network/MRLPanelFragment.kt | 16 +++++++++++-----
 .../src/org/videolan/vlc/viewmodels/StreamsModel.kt      | 12 ++++++++++--
 5 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index a0e1b030c..19c9a2440 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -536,6 +536,7 @@
     <string name="back_quit_lock">Press Back again to quit video</string>
     <string name="playlist_deleted">Playlist deleted</string>
     <string name="file_deleted">File deleted</string>
+    <string name="stream_deleted">Stream deleted</string>
     <string name="no_subs_found">No subtitles in this directory</string>
     <string name="music_now_playing">Now Playing</string>
 
diff --git a/application/vlc-android/res/layout-v21/mrl_panel.xml b/application/vlc-android/res/layout-v21/mrl_panel.xml
index f3bafadc2..d3ef884dd 100644
--- a/application/vlc-android/res/layout-v21/mrl_panel.xml
+++ b/application/vlc-android/res/layout-v21/mrl_panel.xml
@@ -76,9 +76,10 @@
                 android:id="@+id/mrl_list"
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
-                android:layout_marginStart="4dp"
-                android:layout_marginTop="24dp"
-                android:layout_marginEnd="4dp"
+                    android:paddingStart="4dp"
+                    android:paddingTop="24dp"
+                    android:paddingEnd="4dp"
+                    android:clipToPadding="false"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
diff --git a/application/vlc-android/res/layout/mrl_panel.xml b/application/vlc-android/res/layout/mrl_panel.xml
index 8af9170e3..617a6ce6a 100644
--- a/application/vlc-android/res/layout/mrl_panel.xml
+++ b/application/vlc-android/res/layout/mrl_panel.xml
@@ -76,9 +76,10 @@
                 android:id="@+id/mrl_list"
                 android:layout_width="0dp"
                 android:layout_height="match_parent"
-                android:layout_marginStart="4dp"
-                android:layout_marginTop="24dp"
-                android:layout_marginEnd="4dp"
+                    android:paddingStart="4dp"
+                    android:paddingTop="24dp"
+                    android:paddingEnd="4dp"
+                    android:clipToPadding="false"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintEnd_toEndOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
index 9047d7674..cab78d9c7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
@@ -49,10 +49,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
 import kotlinx.coroutines.channels.actor
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
-import org.videolan.resources.CTX_ADD_TO_PLAYLIST
-import org.videolan.resources.CTX_APPEND
-import org.videolan.resources.CTX_COPY
-import org.videolan.resources.CTX_RENAME
+import org.videolan.resources.*
 import org.videolan.tools.Settings
 import org.videolan.tools.copy
 import org.videolan.tools.isValidUrl
@@ -174,7 +171,7 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
     }
 
     private fun showContext(position: Int) {
-        val flags = CTX_RENAME or CTX_APPEND or CTX_ADD_TO_PLAYLIST or CTX_COPY
+        val flags = CTX_RENAME or CTX_APPEND or CTX_ADD_TO_PLAYLIST or CTX_COPY or CTX_DELETE
         val media = viewModel.dataset.get(position)
         showContext(requireActivity(), this, position, media.title, flags)
     }
@@ -195,6 +192,15 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
                 requireContext().copy(media.title, media.location)
                 Snackbar.make(requireActivity().window.decorView.findViewById<View>(android.R.id.content), R.string.url_copied_to_clipboard, Snackbar.LENGTH_LONG).show()
             }
+            CTX_DELETE -> {
+                val media = viewModel.dataset.get(position)
+                viewModel.deletingMedia = media
+                UiTools.snackerWithCancel(editText, getString(R.string.stream_deleted), Runnable { viewModel.delete() }, Runnable {
+                    viewModel.deletingMedia = null
+                    viewModel.refresh()
+                })
+                viewModel.refresh()
+            }
         }
     }
 
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/StreamsModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/StreamsModel.kt
index b752bdf2a..debcc78e5 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/StreamsModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/StreamsModel.kt
@@ -29,11 +29,13 @@ import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
+import org.videolan.resources.util.getFromMl
 import org.videolan.tools.CoroutineContextProvider
 
 
 class StreamsModel(context: Context, coroutineContextProvider: CoroutineContextProvider = CoroutineContextProvider()) : MedialibraryModel<MediaWrapper>(context, coroutineContextProvider) {
-     val observableSearchText = ObservableField<String>()
+    var deletingMedia: MediaWrapper? = null
+    val observableSearchText = ObservableField<String>()
 
     init {
         if (medialibrary.isStarted) refresh()
@@ -41,7 +43,7 @@ class StreamsModel(context: Context, coroutineContextProvider: CoroutineContextP
 
 
     override suspend fun updateList() {
-        dataset.value = withContext(coroutineContextProvider.Default) { medialibrary.lastStreamsPlayed().toMutableList() }
+        dataset.value = withContext(coroutineContextProvider.Default) { medialibrary.lastStreamsPlayed().toMutableList().also { deletingMedia?.let { remove(it) } } }
     }
 
     fun rename(position: Int, name: String) {
@@ -50,6 +52,12 @@ class StreamsModel(context: Context, coroutineContextProvider: CoroutineContextP
         refresh()
     }
 
+    fun delete() {
+        deletingMedia?.let { media ->
+            viewModelScope.launch(Dispatchers.IO) { context.getFromMl { removeExternalMedia(media.id) } }
+            refresh()
+        }
+    }
     class Factory(private val context: Context) : ViewModelProvider.Factory {
         override fun <T : ViewModel> create(modelClass: Class<T>): T {
             @Suppress("UNCHECKED_CAST")



More information about the Android mailing list