From f67ce86cf2da0e1e62f89a92ee7964c6b36feaf3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 1 Mar 2017 23:21:20 +0100 Subject: [PATCH] fix #168, do not autoplay gifs at thumbnails if chosen so --- .../gallery/activities/MainActivity.kt | 6 ++++++ .../gallery/activities/MediaActivity.kt | 6 ++++++ .../gallery/adapters/DirectoryAdapter.kt | 18 +++++++++++------- .../gallery/adapters/MediaAdapter.kt | 10 +++++++++- .../simplemobiletools/gallery/models/Medium.kt | 5 +++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index fd56dd882..c9ed83d95 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -47,6 +47,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mIsSetWallpaperIntent = false private var mIsThirdPartyIntent = false private var mIsGettingDirs = false + private var mStoredAnimateGifs = true private var mCurrAsyncTask: GetDirectoriesAsynctask? = null @@ -65,6 +66,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_holder.setOnRefreshListener({ getDirectories() }) mDirs = ArrayList() + mStoredAnimateGifs = config.animateGifs storeStoragePaths() } @@ -95,6 +97,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { override fun onResume() { super.onResume() + if (mStoredAnimateGifs != config.animateGifs) { + mDirs.clear() + } tryloadGallery() } @@ -104,6 +109,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { storeDirectories() directories_holder.isRefreshing = false mIsGettingDirs = false + mStoredAnimateGifs = config.animateGifs } override fun onDestroy() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 0e8868295..997918b67 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -44,6 +44,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { private var mIsGettingMedia = false private var mShowAll = false private var mLoadedInitialPhotos = false + private var mStoredAnimateGifs = true override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -56,6 +57,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_holder.setOnRefreshListener({ getMedia() }) mPath = intent.getStringExtra(DIRECTORY) + mStoredAnimateGifs = config.animateGifs mShowAll = config.showAll if (mShowAll) supportActionBar?.setDisplayHomeAsUpEnabled(false) @@ -63,6 +65,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun onResume() { super.onResume() + if (mShowAll && mStoredAnimateGifs != config.animateGifs) { + mMedia.clear() + } tryloadGallery() } @@ -71,6 +76,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mCurrAsyncTask?.shouldStop = true mIsGettingMedia = false media_holder.isRefreshing = false + mStoredAnimateGifs = config.animateGifs } private fun tryloadGallery() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 7a24b298f..59bd6b8a9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -15,10 +15,7 @@ import com.bumptech.glide.signature.StringSignature import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog -import com.simplemobiletools.commons.extensions.isAStorageRootFolder -import com.simplemobiletools.commons.extensions.isImageVideoGif -import com.simplemobiletools.commons.extensions.scanPaths -import com.simplemobiletools.commons.extensions.toast +import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.CopyDialog @@ -43,6 +40,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList() var foregroundColor = 0 var backgroundColor = 0 + var animateGifs = true fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { getProperView(itemView).isSelected = select @@ -67,6 +65,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList, val markedItems = HashSet() var foregroundColor = 0 var backgroundColor = 0 + var animateGifs = true fun toggleItemSelection(itemView: View, select: Boolean, pos: Int = -1) { getProperView(itemView).isSelected = select @@ -63,6 +64,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, init { foregroundColor = config.primaryColor backgroundColor = config.backgroundColor + animateGifs = config.animateGifs } val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { @@ -242,7 +244,13 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val path = medium.path val timestampSignature = StringSignature(medium.date_modified.toString()) 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()) { Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT) .signature(timestampSignature).placeholder(backgroundColor).centerCrop().into(itemView.medium_thumbnail) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index dd857bb5a..368816b69 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -1,5 +1,6 @@ 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_NAME 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 } - 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