[Android] Display favorites first on TV with a badge icon

Nicolas Pomepuy git at videolan.org
Mon Mar 7 09:36:06 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Mon Feb 28 14:36:07 2022 +0100| [ed9c0089dee2d28fe1f904b0c006ef7023205bee] | committer: Duncan McNamara

Display favorites first on TV with a badge icon

Fixes #1375

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

 .../src/main/res/drawable/ic_favorite_tv_badge.xml | 38 ++++++++++++++++++++++
 .../org/videolan/television/ui/CardPresenter.kt    |  5 +++
 .../videolan/television/viewmodel/MainTvModel.kt   | 16 ++++-----
 3 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/application/resources/src/main/res/drawable/ic_favorite_tv_badge.xml b/application/resources/src/main/res/drawable/ic_favorite_tv_badge.xml
new file mode 100644
index 000000000..ef18174db
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_favorite_tv_badge.xml
@@ -0,0 +1,38 @@
+<!--
+  ~ *************************************************************************
+  ~  ic_favorite_tv_badge.xml
+  ~ **************************************************************************
+  ~ Copyright © 2022 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.
+  ~ ***************************************************************************
+  ~
+  ~
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="36dp"
+    android:height="36dp"
+    android:viewportWidth="48"
+    android:viewportHeight="48">
+  <path
+      android:pathData="m24,8 l3.9375,12H40L30.3318,27.2968 34.5,40 24,32.0755 13.5,40 17.6682,27.2968 8,20h12.0625z"
+      android:strokeLineJoin="miter"
+      android:strokeWidth="1"
+      android:fillColor="@color/white"
+      android:strokeColor="#00000000"
+      android:fillType="evenOdd"
+      android:strokeLineCap="butt"/>
+</vector>
diff --git a/application/television/src/main/java/org/videolan/television/ui/CardPresenter.kt b/application/television/src/main/java/org/videolan/television/ui/CardPresenter.kt
index 9642c032b..0f12e6e49 100644
--- a/application/television/src/main/java/org/videolan/television/ui/CardPresenter.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/CardPresenter.kt
@@ -27,6 +27,7 @@ import android.graphics.drawable.BitmapDrawable
 import android.graphics.drawable.Drawable
 import android.net.Uri
 import android.os.Build
+import android.util.Log
 import android.view.View
 import android.view.ViewGroup
 import android.widget.ImageView
@@ -50,6 +51,8 @@ import org.videolan.tools.getLocaleLanguages
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.helpers.*
 
+
+public const val FAVORITE_FLAG = 1000
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@@ -76,6 +79,8 @@ class CardPresenter(private val context: Activity, private val isPoster: Boolean
         fun updateCardViewImage(item: MediaLibraryItem) {
             val noArt = item.artworkMrl.isNullOrEmpty()
             if (item is MediaWrapper) {
+                if (BuildConfig.DEBUG) Log.d("CardPresenter", "ITEM: ${item.title} // meta = ${item.hasFlag(FAVORITE_FLAG)}")
+                if (item.hasFlag(FAVORITE_FLAG)) cardView.badgeImage = ContextCompat.getDrawable(cardView.context, R.drawable.ic_favorite_tv_badge)
                 val group = item.type == MediaWrapper.TYPE_GROUP
                 val folder = item.type == MediaWrapper.TYPE_DIR
                 val video = item.type == MediaWrapper.TYPE_VIDEO
diff --git a/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt b/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
index 83b6d5272..038b69f18 100644
--- a/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
+++ b/application/television/src/main/java/org/videolan/television/viewmodel/MainTvModel.kt
@@ -40,6 +40,7 @@ import org.videolan.moviepedia.database.models.MediaMetadataWithImages
 import org.videolan.moviepedia.repository.MediaMetadataRepository
 import org.videolan.resources.*
 import org.videolan.resources.util.getFromMl
+import org.videolan.television.ui.FAVORITE_FLAG
 import org.videolan.television.ui.MainTvActivity
 import org.videolan.television.ui.NowPlayingDelegate
 import org.videolan.television.ui.audioplayer.AudioPlayerActivity
@@ -61,7 +62,6 @@ import org.videolan.vlc.repository.BrowserFavRepository
 import org.videolan.vlc.repository.DirectoryRepository
 import org.videolan.vlc.util.Permissions
 import org.videolan.vlc.util.convertFavorites
-import org.videolan.vlc.util.isSchemeFile
 import org.videolan.vlc.util.scanAllowed
 
 private const val NUM_ITEMS_PREVIEW = 5
@@ -229,6 +229,11 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
 
     private suspend fun updateBrowsers() {
         val list = mutableListOf<MediaLibraryItem>()
+        updatedFavoriteList.forEach {
+            it.description = it.uri.scheme
+            it.addFlags(FAVORITE_FLAG)
+            list.add(it)
+        }
         val directories = DirectoryRepository.getInstance(context).getMediaDirectoriesList(context).toMutableList()
         if (!showInternalStorage && directories.isNotEmpty()) directories.removeAt(0)
         directories.forEach { if (it.location.scanAllowed()) list.add(it) }
@@ -237,15 +242,6 @@ class MainTvModel(app: Application) : AndroidViewModel(app), Medialibrary.OnMedi
             list.add(DummyItem(HEADER_NETWORK, context.getString(R.string.network_browsing), null))
             list.add(DummyItem(HEADER_STREAM, context.getString(R.string.streams), null))
             list.add(DummyItem(HEADER_SERVER, context.getString(R.string.server_add_title), null))
-            updatedFavoriteList.forEach {
-                it.description = it.uri.scheme
-                list.add(it)
-            }
-        } else {
-            updatedFavoriteList.filter { it.uri.scheme.isSchemeFile() }.forEach {
-                it.description = it.uri.scheme
-                list.add(it)
-            }
         }
         (browsers as MutableLiveData).value = list
         delay(500L)



More information about the Android mailing list