use GifDrawables at thumbnails too

This commit is contained in:
tibbi 2017-10-28 13:27:50 +02:00
parent 1c3aab82ff
commit 4fedc05571
6 changed files with 58 additions and 58 deletions

View file

@ -125,11 +125,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
super.onResume()
config.isThirdPartyIntent = false
if (mStoredAnimateGifs != config.animateGifs) {
directories_grid.adapter?.notifyDataSetChanged()
(directories_grid.adapter as? DirectoryAdapter)?.apply {
animateGifs = config.animateGifs
notifyDataSetChanged()
}
}
if (mStoredCropThumbnails != config.cropThumbnails) {
directories_grid.adapter?.notifyDataSetChanged()
(directories_grid.adapter as? DirectoryAdapter)?.apply {
cropThumbnails = config.cropThumbnails
notifyDataSetChanged()
}
}
if (mStoredShowMediaCount != config.showMediaCount) {

View file

@ -89,12 +89,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun onResume() {
super.onResume()
if (mShowAll && mStoredAnimateGifs != config.animateGifs) {
media_grid.adapter?.notifyDataSetChanged()
if (mStoredAnimateGifs != config.animateGifs) {
(media_grid.adapter as? MediaAdapter)?.apply {
animateGifs = config.animateGifs
notifyDataSetChanged()
}
}
if (mStoredCropThumbnails != config.cropThumbnails) {
media_grid.adapter?.notifyDataSetChanged()
(media_grid.adapter as? MediaAdapter)?.apply {
cropThumbnails = config.cropThumbnails
notifyDataSetChanged()
}
}
if (mStoredScrollHorizontally != config.scrollHorizontally) {

View file

@ -30,11 +30,13 @@ import java.util.*
class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Directory>, val listener: DirOperationsListener?, val isPickIntent: Boolean,
val itemClick: (Directory) -> Unit) : RecyclerView.Adapter<DirectoryAdapter.ViewHolder>() {
val config = activity.config
private val config = activity.config
var actMode: ActionMode? = null
var primaryColor = config.primaryColor
var scrollVertically = !config.scrollHorizontally
var showMediaCount = config.showMediaCount
var animateGifs = config.animateGifs
var cropThumbnails = config.cropThumbnails
private val multiSelector = MultiSelector()
private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST
@ -353,7 +355,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val dir = dirs[position]
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollVertically, isListViewType, textColor, showMediaCount))
itemViews.put(position, holder.bindView(dir, pinnedFolders.contains(dir.path), scrollVertically, isListViewType, textColor, showMediaCount, animateGifs, cropThumbnails))
toggleItemSelection(selectedPositions.contains(position), position)
holder.itemView.tag = holder
}
@ -418,12 +420,13 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback,
val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) :
SwappingHolder(view, MultiSelector()) {
fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean, isListView: Boolean, textColor: Int, showMediaCount: Boolean): View {
fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean, isListView: Boolean, textColor: Int, showMediaCount: Boolean,
animateGifs: Boolean, cropThumbnails: Boolean): View {
itemView.apply {
dir_name.text = directory.name
dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
photo_cnt.text = directory.mediaCnt.toString()
activity.loadImage(directory.tmb, dir_thumbnail, scrollVertically)
activity.loadImage(directory.tmb, dir_thumbnail, scrollVertically, animateGifs, cropThumbnails)
dir_pin.beVisibleIf(isPinned)
dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path))
photo_cnt.beVisibleIf(showMediaCount)

View file

@ -28,18 +28,21 @@ import java.util.*
class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>, val listener: MediaOperationsListener?, val isPickIntent: Boolean,
val allowMultiplePicks: Boolean, val itemClick: (Medium) -> Unit) : RecyclerView.Adapter<MediaAdapter.ViewHolder>() {
val multiSelector = MultiSelector()
val config = activity.config
val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
var skipConfirmationDialog = false
private val config = activity.config
var actMode: ActionMode? = null
var itemViews = SparseArray<View>()
val selectedPositions = HashSet<Int>()
var primaryColor = config.primaryColor
var textColor = config.textColor
var displayFilenames = config.displayFileNames
var scrollVertically = !config.scrollHorizontally
var animateGifs = config.animateGifs
var cropThumbnails = config.cropThumbnails
private val multiSelector = MultiSelector()
private val isListViewType = config.viewTypeFiles == VIEW_TYPE_LIST
private var skipConfirmationDialog = false
private var itemViews = SparseArray<View>()
private val selectedPositions = HashSet<Int>()
private var textColor = config.textColor
private var displayFilenames = config.displayFileNames
fun toggleItemSelection(select: Boolean, pos: Int) {
if (select) {
@ -284,7 +287,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollVertically, isListViewType, textColor))
itemViews.put(position, holder.bindView(media[position], displayFilenames, scrollVertically, isListViewType, textColor, animateGifs, cropThumbnails))
toggleItemSelection(selectedPositions.contains(position), position)
holder.itemView.tag = holder
}
@ -355,12 +358,13 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean,
val itemClick: (Medium) -> (Unit)) :
SwappingHolder(view, MultiSelector()) {
fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean, isListViewType: Boolean, textColor: Int): View {
fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean, isListViewType: Boolean, textColor: Int,
animateGifs: Boolean, cropThumbnails: Boolean): View {
itemView.apply {
play_outline.visibility = if (medium.video) View.VISIBLE else View.GONE
photo_name.beVisibleIf(displayFilenames || isListViewType)
photo_name.text = medium.name
activity.loadImage(medium.path, medium_thumbnail, scrollVertically)
activity.loadImage(medium.path, medium_thumbnail, scrollVertically, animateGifs, cropThumbnails)
if (isListViewType) {
photo_name.setTextColor(textColor)

View file

@ -6,6 +6,7 @@ import android.net.Uri
import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
@ -22,6 +23,7 @@ import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Directory
import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.views.MySquareImageView
import pl.droidsonroids.gif.GifDrawable
import java.io.File
import java.util.*
@ -199,24 +201,28 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
}
}
fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean) {
fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean, animateGifs: Boolean, cropThumbnails: Boolean) {
target.isVerticalScrolling = verticalScroll
if (path.isImageFast() || path.isVideoFast()) {
if (path.isPng()) {
loadPng(path, target)
loadPng(path, target, cropThumbnails)
} else {
loadJpg(path, target)
loadJpg(path, target, cropThumbnails)
}
} else if (path.isGif()) {
if (config.animateGifs) {
loadAnimatedGif(path, target)
val gifDrawable = GifDrawable(path)
target.setImageDrawable(gifDrawable)
if (animateGifs) {
gifDrawable.start()
} else {
loadStaticGif(path, target)
gifDrawable.stop()
}
target.scaleType = if (cropThumbnails) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
}
}
fun Activity.loadPng(path: String, target: MySquareImageView) {
fun Activity.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
@ -226,11 +232,11 @@ fun Activity.loadPng(path: String, target: MySquareImageView) {
.asBitmap()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
if (cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
}
fun Activity.loadJpg(path: String, target: MySquareImageView) {
fun Activity.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boolean) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
@ -238,36 +244,10 @@ fun Activity.loadJpg(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext)
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
if (cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
}
fun Activity.loadAnimatedGif(path: String, target: MySquareImageView) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.NONE)
val builder = Glide.with(applicationContext)
.asGif()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
}
fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.DATA)
val builder = Glide.with(applicationContext)
.asBitmap()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
}
fun Activity.getCachedDirectories(): ArrayList<Directory> {
val token = object : TypeToken<List<Directory>>() {}.type
return Gson().fromJson<ArrayList<Directory>>(config.directories, token) ?: ArrayList<Directory>(1)

View file

@ -9,7 +9,8 @@
<ImageView
android:id="@+id/gif_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent"
android:scaleType="fitCenter"/>
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/subsampling_view"