use Picasso for directory thumbnails too

This commit is contained in:
tibbi 2017-03-17 21:36:19 +01:00
parent d22685b5ca
commit 723084b482
4 changed files with 50 additions and 18 deletions

View File

@ -4,10 +4,12 @@ import android.Manifest
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Configuration
import android.os.Bundle import android.os.Bundle
import android.provider.MediaStore import android.provider.MediaStore
import android.support.v4.app.ActivityCompat import android.support.v4.app.ActivityCompat
import android.support.v7.widget.GridLayoutManager import android.support.v7.widget.GridLayoutManager
import android.util.DisplayMetrics
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.google.gson.Gson import com.google.gson.Gson
@ -49,9 +51,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
companion object {
var thumbnailSize = 0
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
updateThumbnailSize()
mIsPickImageIntent = isPickImageIntent(intent) mIsPickImageIntent = isPickImageIntent(intent)
mIsPickVideoIntent = isPickVideoIntent(intent) mIsPickVideoIntent = isPickVideoIntent(intent)
@ -115,6 +122,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
config.isFirstRun = false config.isFirstRun = false
} }
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
updateThumbnailSize()
}
private fun updateThumbnailSize() {
val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics)
thumbnailSize = metrics.widthPixels / config.dirColumnCnt
}
private fun tryloadGallery() { private fun tryloadGallery() {
if (hasWriteStoragePermission()) { if (hasWriteStoragePermission()) {
if (config.showAll) if (config.showAll)
@ -216,11 +234,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun increaseColumnCount() { private fun increaseColumnCount() {
config.dirColumnCnt = ++(directories_grid.layoutManager as GridLayoutManager).spanCount config.dirColumnCnt = ++(directories_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu() invalidateOptionsMenu()
updateThumbnailSize()
} }
private fun reduceColumnCount() { private fun reduceColumnCount() {
config.dirColumnCnt = --(directories_grid.layoutManager as GridLayoutManager).spanCount config.dirColumnCnt = --(directories_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu() invalidateOptionsMenu()
updateThumbnailSize()
} }
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent)) private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))

View File

@ -61,7 +61,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false) mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false)
} }
updateThumbnailWidth() updateThumbnailSize()
media_refresh_layout.setOnRefreshListener({ getMedia() }) media_refresh_layout.setOnRefreshListener({ getMedia() })
mPath = intent.getStringExtra(DIRECTORY) mPath = intent.getStringExtra(DIRECTORY)
mStoredAnimateGifs = config.animateGifs mStoredAnimateGifs = config.animateGifs
@ -99,10 +99,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
override fun onConfigurationChanged(newConfig: Configuration?) { override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig) super.onConfigurationChanged(newConfig)
updateThumbnailWidth() updateThumbnailSize()
} }
private fun updateThumbnailWidth() { private fun updateThumbnailSize() {
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(metrics) windowManager.defaultDisplay.getMetrics(metrics)
thumbnailSize = metrics.widthPixels / config.mediaColumnCnt thumbnailSize = metrics.widthPixels / config.mediaColumnCnt
@ -277,13 +277,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun increaseColumnCount() { private fun increaseColumnCount() {
config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu() invalidateOptionsMenu()
updateThumbnailWidth() updateThumbnailSize()
} }
private fun reduceColumnCount() { private fun reduceColumnCount() {
config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount
invalidateOptionsMenu() invalidateOptionsMenu()
updateThumbnailWidth() updateThumbnailSize()
} }
override fun deleteFiles(files: ArrayList<File>) { 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.MultiSelector
import com.bignerdranch.android.multiselector.SwappingHolder import com.bignerdranch.android.multiselector.SwappingHolder
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.simplemobiletools.commons.asynctasks.CopyMoveTask import com.simplemobiletools.commons.asynctasks.CopyMoveTask
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -17,11 +16,13 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.MainActivity
import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.activities.SimpleActivity
import com.simplemobiletools.gallery.dialogs.CopyDialog import com.simplemobiletools.gallery.dialogs.CopyDialog
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.extensions.*
import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Directory
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.directory_item.view.* import kotlinx.android.synthetic.main.directory_item.view.*
import kotlinx.android.synthetic.main.directory_tmb.view.* import kotlinx.android.synthetic.main.directory_tmb.view.*
import java.io.File import java.io.File
@ -328,21 +329,32 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
toggleItemSelection(this, markedItems.contains(pos), pos) toggleItemSelection(this, markedItems.contains(pos), pos)
val tmb = directory.thumbnail val path = directory.thumbnail
if (tmb.isGif()) { if (path.isGif()) {
if (animateGifs) { if (animateGifs) {
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(backgroundColor) Glide.with(activity)
.centerCrop().crossFade().into(dir_thumbnail) .load(path)
.asGif()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(backgroundColor)
.centerCrop()
.crossFade()
.into(dir_thumbnail)
} else { } else {
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(backgroundColor) Glide.with(activity)
.centerCrop().into(dir_thumbnail) .load(path)
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(backgroundColor)
.centerCrop()
.into(dir_thumbnail)
} }
} else if (tmb.toLowerCase().endsWith(".png")) {
Glide.with(activity).load(tmb).asBitmap().format(DecodeFormat.PREFER_ARGB_8888).diskCacheStrategy(DiskCacheStrategy.RESULT)
.placeholder(backgroundColor).centerCrop().into(dir_thumbnail)
} else { } else {
Glide.with(activity).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(backgroundColor) Picasso.with(activity)
.centerCrop().crossFade().into(dir_thumbnail) .load("file:$path")
.resize(MainActivity.thumbnailSize, MainActivity.thumbnailSize)
.centerCrop()
.into(dir_thumbnail)
} }
setOnClickListener { viewClicked(multiSelector, directory, pos) } setOnClickListener { viewClicked(multiSelector, directory, pos) }