[Android] Android TV: fix file description while browsing

Nicolas Pomepuy git at videolan.org
Thu Nov 12 13:56:26 CET 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Nov 10 10:24:25 2020 +0100| [189917a7f8bc7cd4e66b199fd3b51826603689bf] | committer: Nicolas Pomepuy

Android TV: fix file description while browsing

Fixes #1531
If the file size is available, it's displayed, else, no description is displayed

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

 .../videolan/television/ui/FileTvItemAdapter.kt    |  8 ++++++-
 .../org/videolan/vlc/providers/BrowserProvider.kt  | 26 +++++++++++++++++-----
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/FileTvItemAdapter.kt b/application/television/src/main/java/org/videolan/television/ui/FileTvItemAdapter.kt
index 1e63f01ec..ff05b7195 100644
--- a/application/television/src/main/java/org/videolan/television/ui/FileTvItemAdapter.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/FileTvItemAdapter.kt
@@ -167,7 +167,13 @@ class FileTvItemAdapter(private val eventsHandler: IEventsHandler<MediaLibraryIt
             if (item is MediaWrapper) {
                 if (item.type == MediaWrapper.TYPE_VIDEO) {
                     resolution = generateResolutionClass(item.width, item.height) ?: ""
-                    description = if (item.time == 0L) Tools.millisToString(item.length) else Tools.getProgressText(item)
+                    description = when {
+                        item.description?.isNotEmpty() == true -> item.description
+                        item.time != 0L -> Tools.getProgressText(item)
+                        item.time == 0L && item.length != 0L -> Tools.millisToString(item.length)
+                        else -> ""
+
+                    }
                     binding.badge = resolution
                     seen = item.seen
                     var max = 0
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 4ea8655c6..465442a95 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/BrowserProvider.kt
@@ -42,13 +42,11 @@ import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.Storage
 import org.videolan.resources.VLCInstance
 import org.videolan.resources.util.HeaderProvider
-import org.videolan.tools.AppScope
-import org.videolan.tools.CoroutineContextProvider
-import org.videolan.tools.DependencyProvider
-import org.videolan.tools.Settings
+import org.videolan.tools.*
 import org.videolan.tools.livedata.LiveDataset
 import org.videolan.vlc.R
 import org.videolan.vlc.util.*
+import java.io.File
 
 const val TAG = "VLC/BrowserProvider"
 
@@ -255,7 +253,18 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
                     val current = when (item.itemType) {
                         MediaLibraryItem.TYPE_MEDIA -> {
                             val mw = item as MediaWrapper
-                            if (mw.type != MediaWrapper.TYPE_DIR && mw.type != MediaWrapper.TYPE_PLAYLIST) continue at loop
+                            if (mw.type != MediaWrapper.TYPE_DIR && mw.type != MediaWrapper.TYPE_PLAYLIST){
+                                if (mw.length == 0L) {
+                                    parseMediaSize(mw)?.let {
+                                        withContext(coroutineContextProvider.Main) {
+                                            item.description = if (it == 0L) "" else it.readableFileSize()
+                                            descriptionUpdate.value = Pair(currentParsedPosition, item.description)
+                                        }
+                                    }
+
+                                }
+                                continue at loop
+                            }
                             if (mw.uri.scheme == "otg" || mw.uri.scheme == "content") continue at loop
                             mw
                         }
@@ -292,6 +301,13 @@ abstract class BrowserProvider(val context: Context, val dataset: LiveDataset<Me
         parsingJob = null
     }
 
+    private fun parseMediaSize(mw:MediaWrapper):Long? {
+        mw.uri?.path?.let {
+            return File(it).length()
+        }
+        return null
+    }
+
     fun hasSubfolders(media: MediaWrapper): Boolean = foldersContentMap.get(media)?.map { it as MediaWrapper }?.filter { it.type == MediaWrapper.TYPE_DIR }?.size ?: 0 > 0
     fun hasMedias(media: MediaWrapper): Boolean = foldersContentMap.get(media)?.map { it as MediaWrapper }?.filter { it.type != MediaWrapper.TYPE_DIR }?.size ?: 0 > 0
 



More information about the Android mailing list