[Android] Widgets: fix a cover missing/duplication issue

Nicolas Pomepuy git at videolan.org
Wed May 18 09:57:58 UTC 2022


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu May 12 09:23:14 2022 +0200| [3d15c6819a82ebdca0e9990e431a325846b8a9bc] | committer: Duncan McNamara

Widgets: fix a cover missing/duplication issue

To fix that, a WidgetCache cover invalidation flag is added
and triggered when the widget size or widget theme is changed

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

 .../src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt        | 4 +++-
 .../vlc-android/src/org/videolan/vlc/widget/utils/WidgetCache.kt      | 4 ++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
index 5e4d8a447..6da69313f 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -174,6 +174,7 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
         if (size.first != 0 && size.second != 0 && (widgetCacheEntry.widget.width != size.first || widgetCacheEntry.widget.height != size.second)) {
             widgetCacheEntry.widget.width = size.first
             widgetCacheEntry.widget.height = size.second
+            widgetCacheEntry.currentCoverInvalidated = true
             log(appWidgetId, WidgetLogType.INFO, "Updating widget entry to: $widgetCacheEntry.widget")
 
             widgetRepository.updateWidget(widgetCacheEntry.widget)
@@ -286,7 +287,8 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
         if (forPreview) {
             displayCover(context, views, true, widgetType, widgetCacheEntry)
             views.setImageViewBitmap(R.id.cover, cutBitmapCover(widgetType, previewBitmap!!, widgetCacheEntry))
-        } else if (playing && widgetCacheEntry.currentMedia?.artworkMrl != widgetCacheEntry.currentCover) {
+        } else if (playing && (widgetCacheEntry.currentMedia?.artworkMrl != widgetCacheEntry.currentCover || widgetCacheEntry.currentCoverInvalidated)) {
+            widgetCacheEntry.currentCoverInvalidated = false
             widgetCacheEntry.currentCover = widgetCacheEntry.currentMedia?.artworkMrl
             if (!widgetCacheEntry.currentMedia?.artworkMrl.isNullOrEmpty()) {
                 log(appWidgetId, WidgetLogType.INFO, "Bugfix Refresh - Update cover: ${widgetCacheEntry.currentMedia?.artworkMrl} for ${widgetCacheEntry.widget.widgetId}")
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetCache.kt b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetCache.kt
index 7938a0ac7..6377b8e45 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetCache.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetCache.kt
@@ -38,7 +38,7 @@ object WidgetCache {
     }
 
     fun addEntry(widget: Widget): WidgetCacheEntry {
-        val widgetCacheEntry = WidgetCacheEntry(widget, )
+        val widgetCacheEntry = WidgetCacheEntry(widget, currentCoverInvalidated = true)
         entries.add(widgetCacheEntry)
         return widgetCacheEntry
     }
@@ -53,7 +53,7 @@ object WidgetCache {
 
 }
 
-data class WidgetCacheEntry(val widget: Widget, var currentMedia: MediaWrapper? = null, var currentCover: String? = null, var palette: Palette? = null, @ColorInt var foregroundColor: Int? = null, var playing: Boolean? = null) {
+data class WidgetCacheEntry(val widget: Widget, var currentMedia: MediaWrapper? = null, var currentCover: String? = null, var palette: Palette? = null, @ColorInt var foregroundColor: Int? = null, var playing: Boolean? = null, var currentCoverInvalidated:Boolean = false) {
     fun reset() {
         currentCover = null
         currentMedia = null



More information about the Android mailing list