[Android] Fix thread issue

Nicolas Pomepuy git at videolan.org
Tue Oct 1 15:57:02 CEST 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Sep 23 16:16:03 2019 +0200| [5ae4db698aa4c1ba7e60ae1eff89cc1050405d0d] | committer: Geoffrey Métais

Fix thread issue

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

 vlc-android/res/values/strings.xml                            |  1 -
 .../src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt   | 11 +++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 86831a98a..66ba6040b 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -732,7 +732,6 @@
     <string name="describe_crash">Please describe how this crash happened</string>
     <string name="favorite">Favorite</string>
     <string name="add_to_scanned">Scan this folder</string>
-    <string name="scanned_directory_added">%s added to your scanned folders</string>
     <string name="directory_not_scanned">This directory is not scanned</string>
     <string name="scanned_directory_added">%s added to your scanned directories</string>
     <string name="video_group_size_dialog_text">Number of characters used to group by name</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
index 0333bc98a..c55867872 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
@@ -32,12 +32,11 @@ import android.view.View
 import androidx.fragment.app.Fragment
 import androidx.lifecycle.Observer
 import androidx.lifecycle.ViewModelProviders
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.ObsoleteCoroutinesApi
-import kotlinx.coroutines.launch
+import kotlinx.coroutines.*
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.tools.isStarted
 import org.videolan.vlc.ExternalMonitor
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.helpers.MedialibraryUtils
@@ -45,6 +44,7 @@ import org.videolan.vlc.gui.helpers.hf.OtgAccess
 import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.browser.BrowserModel
 import org.videolan.vlc.viewmodels.browser.TYPE_FILE
+import java.lang.Runnable
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -152,7 +152,10 @@ open class FileBrowserFragment : BaseBrowserFragment() {
         val item = menu.findItem(R.id.ml_menu_save) ?: return
         item.isVisible = !isRootDirectory && mrl!!.startsWith("file")
         mrl?.let {
-            menu.findItem(R.id.ml_menu_scan)?.isVisible = !isRootDirectory && mrl!!.startsWith("file") && !MedialibraryUtils.isScanned(it)
+            launch {
+                val isScanned = withContext(Dispatchers.IO) { MedialibraryUtils.isScanned(it) }
+                if (isStarted()) menu.findItem(R.id.ml_menu_scan)?.isVisible = !isRootDirectory && mrl!!.startsWith("file") && !isScanned
+            }
         }
         runIO(Runnable {
             val isFavorite = mrl != null && browserFavRepository.browserFavExists(Uri.parse(mrl))



More information about the Android mailing list