Commit 83e2cb3f authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais

Set video thumbnail preference in cache

parent c9942e0f
......@@ -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
......
......@@ -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"
@ExperimentalCoroutinesApi
@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 {
......
......@@ -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
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment