load media thumbnails with Picasso

This commit is contained in:
tibbi 2017-03-17 21:22:57 +01:00
parent 07e15db08a
commit d22685b5ca
2 changed files with 40 additions and 10 deletions

View file

@ -3,10 +3,12 @@ package com.simplemobiletools.gallery.activities
import android.app.Activity
import android.app.WallpaperManager
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Bitmap
import android.net.Uri
import android.os.Bundle
import android.support.v7.widget.GridLayoutManager
import android.util.DisplayMetrics
import android.util.Log
import android.view.Menu
import android.view.MenuItem
@ -46,6 +48,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private var mLoadedInitialPhotos = false
private var mStoredAnimateGifs = true
companion object {
var thumbnailSize = 0
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_media)
@ -55,6 +61,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false)
}
updateThumbnailWidth()
media_refresh_layout.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY)
mStoredAnimateGifs = config.animateGifs
@ -90,6 +97,17 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
}
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
updateThumbnailWidth()
}
private fun updateThumbnailWidth() {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
thumbnailSize = metrics.widthPixels / config.mediaColumnCnt
}
private fun initializeGallery() {
if (isDirEmpty())
return
@ -259,11 +277,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun increaseColumnCount() {
config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailWidth()
}
private fun reduceColumnCount() {
config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu()
updateThumbnailWidth()
}
override fun deleteFiles(files: ArrayList<File>) {

View file

@ -9,7 +9,6 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
import com.bignerdranch.android.multiselector.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -18,10 +17,12 @@ import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.MediaActivity
import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.models.Medium
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.photo_video_item.view.*
import kotlinx.android.synthetic.main.photo_video_tmb.view.*
import java.io.File
@ -249,18 +250,27 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
val path = medium.path
if (medium.isGif()) {
if (animateGifs) {
Glide.with(activity).load(path).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(backgroundColor)
.centerCrop().crossFade().into(medium_thumbnail)
Glide.with(activity)
.load(path)
.asGif()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.centerCrop()
.crossFade()
.into(medium_thumbnail)
} else {
Glide.with(activity).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).placeholder(backgroundColor)
.centerCrop().into(medium_thumbnail)
Glide.with(activity)
.load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.centerCrop()
.into(medium_thumbnail)
}
} else if (medium.isPng()) {
Glide.with(activity).load(path).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
.placeholder(backgroundColor).centerCrop().into(medium_thumbnail)
} else {
Glide.with(activity).load(path).diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(backgroundColor)
.centerCrop().crossFade().into(medium_thumbnail)
Picasso.with(activity)
.load("file:$path")
.resize(MediaActivity.thumbnailSize, MediaActivity.thumbnailSize)
.centerCrop()
.into(medium_thumbnail)
}
setOnClickListener { viewClicked(multiSelector, medium, pos) }