use Picasso for directory thumbnails too
This commit is contained in:
parent
d22685b5ca
commit
723084b482
|
@ -4,10 +4,12 @@ import android.Manifest
|
|||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.os.Bundle
|
||||
import android.provider.MediaStore
|
||||
import android.support.v4.app.ActivityCompat
|
||||
import android.support.v7.widget.GridLayoutManager
|
||||
import android.util.DisplayMetrics
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.gson.Gson
|
||||
|
@ -49,9 +51,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
private var mCurrAsyncTask: GetDirectoriesAsynctask? = null
|
||||
|
||||
companion object {
|
||||
var thumbnailSize = 0
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
updateThumbnailSize()
|
||||
|
||||
mIsPickImageIntent = isPickImageIntent(intent)
|
||||
mIsPickVideoIntent = isPickVideoIntent(intent)
|
||||
|
@ -115,6 +122,17 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
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() {
|
||||
if (hasWriteStoragePermission()) {
|
||||
if (config.showAll)
|
||||
|
@ -216,11 +234,13 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
private fun increaseColumnCount() {
|
||||
config.dirColumnCnt = ++(directories_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
updateThumbnailSize()
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
config.dirColumnCnt = --(directories_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
updateThumbnailSize()
|
||||
}
|
||||
|
||||
private fun isPickImageIntent(intent: Intent) = isPickIntent(intent) && (hasImageContentData(intent) || isImageType(intent))
|
||||
|
|
|
@ -61,7 +61,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
mIsGetAnyIntent = getBooleanExtra(GET_ANY_INTENT, false)
|
||||
}
|
||||
|
||||
updateThumbnailWidth()
|
||||
updateThumbnailSize()
|
||||
media_refresh_layout.setOnRefreshListener({ getMedia() })
|
||||
mPath = intent.getStringExtra(DIRECTORY)
|
||||
mStoredAnimateGifs = config.animateGifs
|
||||
|
@ -99,10 +99,10 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
|
||||
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
updateThumbnailWidth()
|
||||
updateThumbnailSize()
|
||||
}
|
||||
|
||||
private fun updateThumbnailWidth() {
|
||||
private fun updateThumbnailSize() {
|
||||
val metrics = DisplayMetrics()
|
||||
windowManager.defaultDisplay.getMetrics(metrics)
|
||||
thumbnailSize = metrics.widthPixels / config.mediaColumnCnt
|
||||
|
@ -277,13 +277,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
private fun increaseColumnCount() {
|
||||
config.mediaColumnCnt = ++(media_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
updateThumbnailWidth()
|
||||
updateThumbnailSize()
|
||||
}
|
||||
|
||||
private fun reduceColumnCount() {
|
||||
config.mediaColumnCnt = --(media_grid.layoutManager as GridLayoutManager).spanCount
|
||||
invalidateOptionsMenu()
|
||||
updateThumbnailWidth()
|
||||
updateThumbnailSize()
|
||||
}
|
||||
|
||||
override fun deleteFiles(files: ArrayList<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
|
||||
|
@ -17,11 +16,13 @@ import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
|||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.MainActivity
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.dialogs.CopyDialog
|
||||
import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog
|
||||
import com.simplemobiletools.gallery.extensions.*
|
||||
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_tmb.view.*
|
||||
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
|
||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||
|
||||
val tmb = directory.thumbnail
|
||||
if (tmb.isGif()) {
|
||||
val path = directory.thumbnail
|
||||
if (path.isGif()) {
|
||||
if (animateGifs) {
|
||||
Glide.with(activity).load(tmb).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).placeholder(backgroundColor)
|
||||
.centerCrop().crossFade().into(dir_thumbnail)
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.asGif()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.placeholder(backgroundColor)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(dir_thumbnail)
|
||||
} else {
|
||||
Glide.with(activity).load(tmb).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(backgroundColor)
|
||||
.centerCrop().into(dir_thumbnail)
|
||||
Glide.with(activity)
|
||||
.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 {
|
||||
Glide.with(activity).load(tmb).diskCacheStrategy(DiskCacheStrategy.RESULT).placeholder(backgroundColor)
|
||||
.centerCrop().crossFade().into(dir_thumbnail)
|
||||
Picasso.with(activity)
|
||||
.load("file:$path")
|
||||
.resize(MainActivity.thumbnailSize, MainActivity.thumbnailSize)
|
||||
.centerCrop()
|
||||
.into(dir_thumbnail)
|
||||
}
|
||||
|
||||
setOnClickListener { viewClicked(multiSelector, directory, pos) }
|
||||
|
|
|
@ -7,7 +7,7 @@ import com.simplemobiletools.gallery.helpers.SORT_DESCENDING
|
|||
import java.io.Serializable
|
||||
|
||||
data class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val date_modified: Long, val date_taken: Long,
|
||||
var size: Long) : Serializable, Comparable<Directory> {
|
||||
var size: Long) : Serializable, Comparable<Directory> {
|
||||
companion object {
|
||||
private val serialVersionUID = -6553649863575455L
|
||||
var sorting: Int = 0
|
||||
|
|
Loading…
Reference in New Issue