[Android] Fix hiding "scan folder" menu if folder is scanned

Nicolas Pomepuy git at videolan.org
Tue Oct 8 16:21:06 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Oct  8 09:22:59 2019 +0200| [4d15600b70c082dc8ae7411d80b223b3ad85003d] | committer: Geoffrey Métais

Fix hiding "scan folder" menu if folder is scanned

Refs #1060

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

 vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt | 7 ++-----
 vlc-android/src/org/videolan/vlc/util/Strings.kt                  | 4 +---
 vlc-android/test/org/videolan/vlc/util/StringsTest.kt             | 6 ++----
 3 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
index 12d28cf8b..c172b427d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
@@ -8,10 +8,7 @@ import androidx.core.content.ContextCompat
 import org.videolan.medialibrary.interfaces.AbstractMedialibrary
 import org.videolan.vlc.MediaParsingService
 import org.videolan.vlc.VLCApplication
-import org.videolan.vlc.util.ACTION_DISCOVER
-import org.videolan.vlc.util.ACTION_DISCOVER_DEVICE
-import org.videolan.vlc.util.EXTRA_PATH
-import org.videolan.vlc.util.runIO
+import org.videolan.vlc.util.*
 
 object MedialibraryUtils {
 
@@ -36,7 +33,7 @@ object MedialibraryUtils {
         //scheme is supported => test if the parent is scanned
         var isScanned = false
         AbstractMedialibrary.getInstance().foldersList.forEach search@{
-            if (path.startsWith(Uri.parse(it).toString())) {
+            if (path.stripTrailingSlash().startsWith(Uri.parse(it).toString().stripTrailingSlash())) {
                 isScanned = true
                 return at search
             }
diff --git a/vlc-android/src/org/videolan/vlc/util/Strings.kt b/vlc-android/src/org/videolan/vlc/util/Strings.kt
index 65985dd26..20546133e 100644
--- a/vlc-android/src/org/videolan/vlc/util/Strings.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Strings.kt
@@ -26,9 +26,7 @@ import java.text.DecimalFormat
 
 private const val TAG = "VLC/UiTools/Strings"
 
-fun stripTrailingSlash(s: String): String {
-    return if (s.endsWith("/") && s.length > 1) s.substring(0, s.length - 1) else s
-}
+fun String.stripTrailingSlash() = if (endsWith("/") && length > 1) dropLast(1) else this
 
 //TODO: Remove this after convert the dependent code to kotlin
 fun startsWith(array: Array<String>, text: String) = array.any { text.startsWith(it)}
diff --git a/vlc-android/test/org/videolan/vlc/util/StringsTest.kt b/vlc-android/test/org/videolan/vlc/util/StringsTest.kt
index 3300bace4..7e1da15d7 100644
--- a/vlc-android/test/org/videolan/vlc/util/StringsTest.kt
+++ b/vlc-android/test/org/videolan/vlc/util/StringsTest.kt
@@ -10,11 +10,9 @@ class StringsTest {
 
     @Test
     fun stripTrailingSlash() {
-        var s = stripTrailingSlash("foo/")
-        assertEquals(s, "foo")
+        assertEquals("foo/".stripTrailingSlash(), "foo")
 
-        s = stripTrailingSlash("bar")
-        assertEquals(s, "bar")
+        assertEquals("bar".stripTrailingSlash(), "bar")
     }
 
     @Test



More information about the Android mailing list