[Android] TV: Avoid unnecessary background image updates

Geoffrey Métais git at videolan.org
Wed Dec 19 11:31:59 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Dec 19 11:31:28 2018 +0100| [1ebf794569ba617e6d0736c76536a6a0cd917ee5] | committer: Geoffrey Métais

TV: Avoid unnecessary background image updates

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

 .../src/org/videolan/vlc/gui/tv/browser/CategoriesFragment.kt |  3 +++
 .../videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.kt    | 11 ++++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/CategoriesFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/CategoriesFragment.kt
index ab2bf16a4..7936bbbb6 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/CategoriesFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/CategoriesFragment.kt
@@ -81,9 +81,12 @@ open class CategoriesFragment<T : BaseModel<out MediaLibraryItem>> : BrowseSuppo
         restart = true
     }
 
+    private var currentArt : String? = null
     override fun onItemSelected(itemViewHolder: Presenter.ViewHolder?, item: Any?, rowViewHolder: RowPresenter.ViewHolder?, row: Row?) {
         if (item === null) return
         selecteditem = item as MediaWrapper
+        if (currentArt == item.artworkMrl) return
+        currentArt = item.artworkMrl
         TvUtil.updateBackground(backgroundManager, item)
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.kt
index 87bc2babb..fb69a6b02 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/MediaLibBrowserFragment.kt
@@ -28,11 +28,11 @@ import android.content.SharedPreferences
 import android.os.Build
 import android.os.Bundle
 import android.os.Parcelable
+import android.widget.ImageView
 import androidx.annotation.RequiresApi
+import androidx.core.content.ContextCompat
 import androidx.leanback.app.BackgroundManager
 import androidx.leanback.widget.*
-import androidx.core.content.ContextCompat
-import android.widget.ImageView
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.vlc.R
 import org.videolan.vlc.gui.tv.TvUtil
@@ -79,11 +79,16 @@ abstract class MediaLibBrowserFragment<T : BaseModel<out MediaLibraryItem>> : Gr
         mAdapter.setItems(list, TvUtil.diffCallback)
     }
 
+    private var currentArt : String? = null
     @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
     override fun onItemSelected(itemViewHolder: Presenter.ViewHolder?, item: Any?,
                                 rowViewHolder: RowPresenter.ViewHolder?, row: Row?) {
         mSelectedItem = item
-        item?.run { TvUtil.updateBackground(mBackgroundManager, this) }
+        (item as? MediaLibraryItem)?.run {
+            if (currentArt == artworkMrl) return at run
+            currentArt = artworkMrl
+            TvUtil.updateBackground(mBackgroundManager, this)
+        }
     }
 
     override fun onItemClicked(itemViewHolder: Presenter.ViewHolder?, item: Any?,



More information about the Android mailing list