[Android] Fix TV sorting race condition while browsing SMB

Nicolas Pomepuy git at videolan.org
Tue Jul 13 12:30:38 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Jul 12 13:29:34 2021 +0200| [da424c6f264101ef80d04d3691cdc5655b0f1315] | committer: Nicolas Pomepuy

Fix TV sorting race condition while browsing SMB

Fixes #2087

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

 .../org/videolan/vlc/providers/BrowserProvider.kt   |  2 --
 .../src/org/videolan/vlc/util/ModelsHelper.kt       | 21 ++++++++-------------
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
index 67b44eabd..16afdbb96 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -24,7 +24,6 @@ import android.content.Context
 import android.os.Handler
 import android.os.HandlerThread
 import android.os.Process
-import android.util.Log
 import androidx.collection.SimpleArrayMap
 import androidx.lifecycle.MutableLiveData
 import kotlinx.coroutines.*
@@ -45,7 +44,6 @@ import org.videolan.resources.VLCInstance
 import org.videolan.resources.util.HeaderProvider
 import org.videolan.tools.*
 import org.videolan.tools.livedata.LiveDataset
-import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.util.*
 import java.io.File
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 41c58eb95..9c35c7504 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -14,7 +14,6 @@ import org.videolan.resources.util.*
 import org.videolan.vlc.PlaybackService
 import kotlin.math.floor
 
-
 object ModelsHelper {
 
     suspend fun generateSections(sort: Int, items: List<MediaLibraryItem>) = withContext(Dispatchers.IO) {
@@ -263,23 +262,19 @@ val descComp by lazy {
 
 val tvAscComp by lazy {
     Comparator<MediaLibraryItem> { item1, item2 ->
-        if (item1?.title?.get(0)?.toLowerCase() == item2?.title?.get(0)?.toLowerCase()) {
-            val type1 = (item1 as MediaWrapper).type
-            val type2 = (item2 as MediaWrapper).type
-            if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
-            else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
-        }
+        val type1 = (item1 as? MediaWrapper)?.type
+        val type2 = (item2 as? MediaWrapper)?.type
+        if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
+        else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
         item1?.title?.toLowerCase()?.compareTo(item2?.title?.toLowerCase() ?: "") ?: -1
     }
 }
 val tvDescComp by lazy {
     Comparator<MediaLibraryItem> { item1, item2 ->
-        if (item1?.title?.get(0)?.toLowerCase() == item2?.title?.get(0)?.toLowerCase()) {
-            val type1 = (item1 as MediaWrapper).type
-            val type2 = (item2 as MediaWrapper).type
-            if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
-            else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
-        }
+        val type1 = (item1 as? MediaWrapper)?.type
+        val type2 = (item2 as? MediaWrapper)?.type
+        if (type1 == MediaWrapper.TYPE_DIR && type2 != MediaWrapper.TYPE_DIR) return at Comparator -1
+        else if (type1 != MediaWrapper.TYPE_DIR && type2 == MediaWrapper.TYPE_DIR) return at Comparator 1
         item2?.title?.toLowerCase()?.compareTo(item1?.title?.toLowerCase() ?: "") ?: -1
     }
 }
\ No newline at end of file



More information about the Android mailing list