[Android] Set video thumbnail preference in cache

Geoffrey Métais git at videolan.org
Fri May 17 09:38:12 CEST 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu May 16 17:40:25 2019 +0200| [83e2cb3ff03f2785fd50badb1d751871c35c12b2] | committer: Geoffrey Métais

Set video thumbnail preference in cache

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

 vlc-android/src/org/videolan/vlc/VLCApplication.kt           | 12 +++++-------
 vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt  | 11 +++++------
 .../src/org/videolan/vlc/gui/preferences/PreferencesVideo.kt |  3 +++
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.kt b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
index 3e4c870fd..264835205 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.kt
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.kt
@@ -28,14 +28,12 @@ import android.content.res.Configuration
 import android.content.res.Resources
 import android.os.Build
 import android.util.Log
-
 import androidx.collection.SimpleArrayMap
 import androidx.fragment.app.DialogFragment
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.ProcessLifecycleOwner
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
-
 import org.videolan.libvlc.Dialog
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.Medialibrary
@@ -45,14 +43,10 @@ import org.videolan.vlc.gui.helpers.AudioUtil
 import org.videolan.vlc.gui.helpers.BitmapCache
 import org.videolan.vlc.gui.helpers.NotificationHelper
 import org.videolan.vlc.gui.helpers.UiTools
-import org.videolan.vlc.util.Settings
-import org.videolan.vlc.util.Util
-import org.videolan.vlc.util.VLCInstance
 import org.videolan.vlc.util.*
-
 import java.lang.ref.WeakReference
 import java.lang.reflect.InvocationTargetException
-import java.util.Calendar
+import java.util.*
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -94,6 +88,7 @@ class VLCApplication : Application() {
         instance = this
     }
 
+    @TargetApi(Build.VERSION_CODES.O)
     override fun onCreate() {
         super.onCreate()
 
@@ -105,6 +100,7 @@ class VLCApplication : Application() {
                 // Set the locale for API < 24 and set application resources and direction for API >=24
                 UiTools.setLocale(appContext!!)
             })
+            showVideoThumbs = Settings.getInstance(baseContext).getBoolean("show_video_thumbnails", true)
 
             runIO(Runnable {
                 if (AndroidUtil.isOOrLater)
@@ -159,6 +155,8 @@ class VLCApplication : Application() {
 
         private var sDialogCounter = 0
 
+        var showVideoThumbs = true
+
         // Property to get the new locale only on restart to prevent change the locale partially on runtime
         var locale: String? = ""
             private set
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
index 574817f75..0e1e6e210 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/ImageLoader.kt
@@ -17,9 +17,7 @@ import androidx.databinding.DataBindingUtil
 import androidx.databinding.OnRebindCallback
 import androidx.databinding.ViewDataBinding
 import androidx.leanback.widget.ImageCardView
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
+import kotlinx.coroutines.*
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.vlc.BR
@@ -29,7 +27,6 @@ import org.videolan.vlc.databinding.AudioBrowserTvItemBinding
 import org.videolan.vlc.gui.tv.TvUtil
 import org.videolan.vlc.util.AppScope
 import org.videolan.vlc.util.HttpImageLoader
-import org.videolan.vlc.util.Settings
 import org.videolan.vlc.util.ThumbnailsProvider
 import org.videolan.vlc.util.ThumbnailsProvider.obtainBitmap
 
@@ -38,6 +35,8 @@ private val sMedialibrary = VLCApplication.mlInstance
 private var defaultImageWidth = 0
 private const val TAG = "ImageLoader"
 
+ at ExperimentalCoroutinesApi
+ at ObsoleteCoroutinesApi
 @MainThread
 @BindingAdapter("media")
 fun loadImage(v: View, item: MediaLibraryItem?) {
@@ -48,11 +47,11 @@ fun loadImage(v: View, item: MediaLibraryItem?) {
     if (item.itemType == MediaLibraryItem.TYPE_GENRE && !isForTV(binding)) {
         return
     }
-    if (item is MediaWrapper && item.type == MediaWrapper.TYPE_VIDEO && !Settings.getInstance(v.context).getBoolean("show_video_thumbnails", true)) {
+    val isMedia = item.itemType == MediaLibraryItem.TYPE_MEDIA
+    if (isMedia && (item as MediaWrapper).type == MediaWrapper.TYPE_VIDEO && !VLCApplication.showVideoThumbs) {
         updateImageView(UiTools.getDefaultVideoDrawable(v.context).bitmap, v, binding)
         return
     }
-    val isMedia = item.itemType == MediaLibraryItem.TYPE_MEDIA
     val isGroup = isMedia && (item as MediaWrapper).type == MediaWrapper.TYPE_GROUP
     val isFolder = !isMedia && item.itemType == MediaLibraryItem.TYPE_FOLDER;
     val cacheKey = when {
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.kt b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.kt
index a52258c48..4a58150ef 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesVideo.kt
@@ -24,10 +24,12 @@ package org.videolan.vlc.gui.preferences
 
 import android.os.Bundle
 import androidx.preference.Preference
+import androidx.preference.TwoStatePreference
 import kotlinx.coroutines.ExperimentalCoroutinesApi
 import kotlinx.coroutines.ObsoleteCoroutinesApi
 import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.vlc.R
+import org.videolan.vlc.VLCApplication
 
 @ObsoleteCoroutinesApi
 @ExperimentalCoroutinesApi
@@ -60,6 +62,7 @@ class PreferencesVideo : BasePreferenceFragment() {
                 return true
             }
             "show_video_thumbnails" -> {
+                VLCApplication.showVideoThumbs = (preference as TwoStatePreference).isChecked
                 (activity as PreferencesActivity).setRestart()
                 return true
             }



More information about the Android mailing list