[Android] Add a progress/played indicator to the file browser items

Nicolas Pomepuy git at videolan.org
Wed Mar 20 14:10:02 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Mar 11 14:04:18 2024 +0100| [228beefd5da6b616aa20bad0f2785c007c1dbe90] | committer: Duncan McNamara

Add a progress/played indicator to the file browser items

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

 .../rounded_corners_black_bottom_right.xml         | 31 +++++++++++++++
 .../vlc-android/res/layout/browser_item.xml        | 45 ++++++++++++++++++++++
 .../videolan/vlc/gui/browser/BaseBrowserAdapter.kt |  4 ++
 .../vlc/gui/browser/BrowserItemBindingContainer.kt | 18 +++++++++
 4 files changed, 98 insertions(+)

diff --git a/application/resources/src/main/res/drawable/rounded_corners_black_bottom_right.xml b/application/resources/src/main/res/drawable/rounded_corners_black_bottom_right.xml
new file mode 100644
index 0000000000..489634761f
--- /dev/null
+++ b/application/resources/src/main/res/drawable/rounded_corners_black_bottom_right.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ *************************************************************************
+  ~  rounded_corners_black_bottom_right.xml
+  ~ **************************************************************************
+  ~ Copyright © 2024 VLC authors and VideoLAN
+  ~ Author: Nicolas POMEPUY
+  ~ This program is free software; you can redistribute it and/or modify
+  ~ it under the terms of the GNU General Public License as published by
+  ~ the Free Software Foundation; either version 2 of the License, or
+  ~ (at your option) any later version.
+  ~
+  ~ This program is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  ~ GNU General Public License for more details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with this program; if not, write to the Free Software
+  ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+  ~ ***************************************************************************
+  ~
+  ~
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+        android:shape="rectangle">
+    <solid android:color="@color/orange500" />
+    <corners
+            android:bottomRightRadius="4dp"/>
+
+</shape>
\ No newline at end of file
diff --git a/application/vlc-android/res/layout/browser_item.xml b/application/vlc-android/res/layout/browser_item.xml
index f7d24e9f03..059028e191 100644
--- a/application/vlc-android/res/layout/browser_item.xml
+++ b/application/vlc-android/res/layout/browser_item.xml
@@ -43,6 +43,18 @@
                 name="favorite"
                 type="boolean" />
 
+        <variable
+                name="played"
+                type="boolean" />
+
+        <variable
+                name="max"
+                type="int" />
+
+        <variable
+                name="progress"
+                type="int" />
+
         <variable
                 name="protocol"
                 type="String" />
@@ -106,6 +118,19 @@
                 app:media="@{item}"
                 tools:srcCompat="@drawable/ic_am_folder" />
 
+        <ImageView
+                android:id="@+id/ml_item_seen"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:background="@drawable/rounded_corners_black_bottom_right"
+                android:padding="3dp"
+                android:visibility="@{played ? View.VISIBLE : View.GONE, default=gone}"
+                app:layout_constraintStart_toStartOf="@+id/item_icon"
+                app:layout_constraintTop_toTopOf="@+id/item_icon"
+                app:layout_goneMarginStart="4dp"
+                app:srcCompat="@drawable/ic_check"
+                tools:visibility="visible" />
+
         <TextView
                 android:id="@+id/dvi_icon"
                 android:layout_width="0dp"
@@ -200,5 +225,25 @@
                 app:layout_constraintTop_toTopOf="parent"
                 app:srcCompat="@drawable/ic_ban"
                 tools:visibility="visible" />
+
+        <ProgressBar
+                android:id="@+id/ml_item_progress"
+                style="@android:style/Widget.ProgressBar.Horizontal"
+                android:layout_width="0dp"
+                android:layout_height="3dp"
+                android:layout_marginStart="12dp"
+                android:layout_marginEnd="16dp"
+                android:indeterminate="false"
+                android:max="@{max}"
+                android:maxHeight="2dip"
+                android:minHeight="2dip"
+                android:progress="@{progress}"
+                android:progressDrawable="?attr/gridview_progressbar"
+                android:secondaryProgress="0"
+                android:visibility="@{progress == 0 || played ? View.GONE : View.VISIBLE}"
+                app:layout_constraintBottom_toBottomOf="@+id/item_icon"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintHorizontal_bias="0.0"
+                app:layout_constraintStart_toEndOf="@+id/item_icon" />
     </androidx.constraintlayout.widget.ConstraintLayout>
 </layout>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
index f207cad631..4e833be64f 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
@@ -157,6 +157,10 @@ open class BaseBrowserAdapter(val browserContainer: BrowserContainer<MediaLibrar
     private fun onBindMediaViewHolder(vh: MediaViewHolder, position: Int) {
         val media = getItem(position) as MediaWrapper
         val isFavorite = media.hasStateFlags(MediaLibraryItem.FLAG_FAVORITE)
+        val max = (media.length / 1000).toInt()
+        val progress = (media.displayTime / 1000).toInt()
+        vh.bindingContainer.setProgress(progress, max)
+        vh.bindingContainer.setIsPlayed(media.playCount > 0)
         vh.bindingContainer.setItem(media)
         vh.bindingContainer.setIsFavorite(isFavorite)
         val scheme = media.uri?.scheme ?: ""
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BrowserItemBindingContainer.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BrowserItemBindingContainer.kt
index 20705e4903..e5a45b3702 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BrowserItemBindingContainer.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BrowserItemBindingContainer.kt
@@ -106,6 +106,24 @@ class BrowserItemBindingContainer(val binding: ViewDataBinding) {
         }
     }
 
+    fun setIsPlayed(played:Boolean) {
+        when (binding) {
+            is CardBrowserItemBinding -> {}
+            is BrowserItemBinding -> binding.played = played
+            else -> throw IllegalStateException("Binding should be either a CardBrowserItemBinding or BrowserItemBinding")
+        }
+    }
+    fun setProgress(progress:Int, max: Int) {
+        when (binding) {
+            is CardBrowserItemBinding -> {}
+            is BrowserItemBinding -> {
+                binding.progress = progress
+                binding.max = max
+            }
+            else -> throw IllegalStateException("Binding should be either a CardBrowserItemBinding or BrowserItemBinding")
+        }
+    }
+
     fun setIsTv(isTv:Boolean) {
         when (binding) {
             is BrowserItemBinding -> binding.isTv = isTv



More information about the Android mailing list