fix #168, do not autoplay gifs at thumbnails if chosen so

This commit is contained in:
tibbi 2017-03-01 23:21:20 +01:00
parent ec11041cda
commit f67ce86cf2
5 changed files with 35 additions and 10 deletions

View file

@ -47,6 +47,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private var mIsSetWallpaperIntent = false private var mIsSetWallpaperIntent = false
private var mIsThirdPartyIntent = false private var mIsThirdPartyIntent = false
private var mIsGettingDirs = false private var mIsGettingDirs = false
private var mStoredAnimateGifs = true
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
@ -65,6 +66,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
directories_holder.setOnRefreshListener({ getDirectories() }) directories_holder.setOnRefreshListener({ getDirectories() })
mDirs = ArrayList<Directory>() mDirs = ArrayList<Directory>()
mStoredAnimateGifs = config.animateGifs
storeStoragePaths() storeStoragePaths()
} }
@ -95,6 +97,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (mStoredAnimateGifs != config.animateGifs) {
mDirs.clear()
}
tryloadGallery() tryloadGallery()
} }
@ -104,6 +109,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
storeDirectories() storeDirectories()
directories_holder.isRefreshing = false directories_holder.isRefreshing = false
mIsGettingDirs = false mIsGettingDirs = false
mStoredAnimateGifs = config.animateGifs
} }
override fun onDestroy() { override fun onDestroy() {

View file

@ -44,6 +44,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private var mIsGettingMedia = false private var mIsGettingMedia = false
private var mShowAll = false private var mShowAll = false
private var mLoadedInitialPhotos = false private var mLoadedInitialPhotos = false
private var mStoredAnimateGifs = true
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -56,6 +57,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
media_holder.setOnRefreshListener({ getMedia() }) media_holder.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY) mPath = intent.getStringExtra(DIRECTORY)
mStoredAnimateGifs = config.animateGifs
mShowAll = config.showAll mShowAll = config.showAll
if (mShowAll) if (mShowAll)
supportActionBar?.setDisplayHomeAsUpEnabled(false) supportActionBar?.setDisplayHomeAsUpEnabled(false)
@ -63,6 +65,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (mShowAll && mStoredAnimateGifs != config.animateGifs) {
mMedia.clear()
}
tryloadGallery() tryloadGallery()
} }
@ -71,6 +76,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mCurrAsyncTask?.shouldStop = true mCurrAsyncTask?.shouldStop = true
mIsGettingMedia = false mIsGettingMedia = false
media_holder.isRefreshing = false media_holder.isRefreshing = false
mStoredAnimateGifs = config.animateGifs
} }
private fun tryloadGallery() { private fun tryloadGallery() {

View file

@ -15,10 +15,7 @@ import com.bumptech.glide.signature.StringSignature
import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.extensions.isAStorageRootFolder import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.isImageVideoGif
import com.simplemobiletools.commons.extensions.scanPaths
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.CopyDialog
@ -43,6 +40,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val markedItems = HashSet<Int>() val markedItems = HashSet<Int>()
var foregroundColor = 0 var foregroundColor = 0
var backgroundColor = 0 var backgroundColor = 0
var animateGifs = true
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
getProperView(itemView).isSelected = select getProperView(itemView).isSelected = select
@ -67,6 +65,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
init { init {
foregroundColor = config.primaryColor foregroundColor = config.primaryColor
backgroundColor = config.backgroundColor backgroundColor = config.backgroundColor
animateGifs = config.animateGifs
} }
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
@ -332,9 +331,14 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
val tmb = directory.thumbnail val tmb = directory.thumbnail
val timestampSignature = StringSignature(directory.date_modified.toString()) val timestampSignature = StringSignature(directory.date_modified.toString())
if (tmb.toLowerCase().endsWith(".gif")) { if (tmb.isGif()) {
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature) if (animateGifs) {
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.dir_thumbnail) Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.dir_thumbnail)
} else {
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().into(itemView.dir_thumbnail)
}
} else if (tmb.toLowerCase().endsWith(".png")) { } else if (tmb.toLowerCase().endsWith(".png")) {
Glide.with(activity).load(tmb).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT) Glide.with(activity).load(tmb).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.dir_thumbnail) .signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.dir_thumbnail)

View file

@ -39,6 +39,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val markedItems = HashSet<Int>() val markedItems = HashSet<Int>()
var foregroundColor = 0 var foregroundColor = 0
var backgroundColor = 0 var backgroundColor = 0
var animateGifs = true
fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) {
getProperView(itemView).isSelected = select getProperView(itemView).isSelected = select
@ -63,6 +64,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
init { init {
foregroundColor = config.primaryColor foregroundColor = config.primaryColor
backgroundColor = config.backgroundColor backgroundColor = config.backgroundColor
animateGifs = config.animateGifs
} }
val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) {
@ -242,7 +244,13 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val path = medium.path val path = medium.path
val timestampSignature = StringSignature(medium.date_modified.toString()) val timestampSignature = StringSignature(medium.date_modified.toString())
if (medium.isGif()) { if (medium.isGif()) {
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature).into(itemView.medium_thumbnail) if (animateGifs) {
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().crossFade().into(itemView.medium_thumbnail)
} else {
Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).signature(timestampSignature)
.placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail)
}
} else if (medium.isPng()) { } else if (medium.isPng()) {
Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT) Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
.signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail) .signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail)

View file

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.models package com.simplemobiletools.gallery.models
import com.simplemobiletools.commons.extensions.isGif
import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.gallery.helpers.SORT_BY_NAME import com.simplemobiletools.gallery.helpers.SORT_BY_NAME
import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE
@ -12,9 +13,9 @@ data class Medium(val name: String, var path: String, val isVideo: Boolean, val
var sorting: Int = 0 var sorting: Int = 0
} }
fun isGif() = path.toLowerCase().endsWith(".gif") fun isGif() = path.isGif()
fun isPng() = path.toLowerCase().endsWith(".png") fun isPng() = path.endsWith(".png", true)
fun isImage() = !isGif() && !isVideo fun isImage() = !isGif() && !isVideo