reuse the function for loading directory and media thumbnails, dont copy paste
This commit is contained in:
parent
32c768a2e5
commit
4f1689965a
|
@ -9,12 +9,14 @@ 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.engine.DiskCacheStrategy
|
||||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.extensions.isAStorageRootFolder
|
||||
import com.simplemobiletools.commons.extensions.isImageVideoGif
|
||||
import com.simplemobiletools.commons.extensions.needsStupidWritePermissions
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.MainActivity
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
|
@ -22,7 +24,6 @@ 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,39 +329,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
photo_cnt.text = directory.mediaCnt.toString()
|
||||
dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE
|
||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||
|
||||
val path = directory.thumbnail
|
||||
if (path.isGif()) {
|
||||
if (animateGifs) {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.asGif()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(dir_thumbnail)
|
||||
} else {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.into(dir_thumbnail)
|
||||
}
|
||||
} else if (path.isVideoFast()) {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(dir_thumbnail)
|
||||
} else {
|
||||
Picasso.with(activity)
|
||||
.load("file:$path")
|
||||
.resize(MainActivity.thumbnailSize, MainActivity.thumbnailSize)
|
||||
.centerCrop()
|
||||
.into(dir_thumbnail)
|
||||
}
|
||||
activity.loadImage(directory.thumbnail, MainActivity.thumbnailSize, dir_thumbnail)
|
||||
|
||||
setOnClickListener { viewClicked(multiSelector, directory, pos) }
|
||||
setOnLongClickListener {
|
||||
|
|
|
@ -9,13 +9,11 @@ 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.engine.DiskCacheStrategy
|
||||
import com.simplemobiletools.commons.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.dialogs.PropertiesDialog
|
||||
import com.simplemobiletools.commons.dialogs.RenameItemDialog
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.isVideoFast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.MediaActivity
|
||||
|
@ -23,7 +21,6 @@ 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
|
||||
|
@ -247,39 +244,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
|
|||
photo_name.beVisibleIf(displayFilenames)
|
||||
photo_name.text = medium.name
|
||||
toggleItemSelection(this, markedItems.contains(pos), pos)
|
||||
|
||||
val path = medium.path
|
||||
if (medium.isGif()) {
|
||||
if (animateGifs) {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.asGif()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(medium_thumbnail)
|
||||
} else {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.into(medium_thumbnail)
|
||||
}
|
||||
} else if (path.isVideoFast()) {
|
||||
Glide.with(activity)
|
||||
.load(path)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(medium_thumbnail)
|
||||
} else {
|
||||
Picasso.with(activity)
|
||||
.load("file:$path")
|
||||
.resize(MediaActivity.thumbnailSize, MediaActivity.thumbnailSize)
|
||||
.centerCrop()
|
||||
.into(medium_thumbnail)
|
||||
}
|
||||
activity.loadImage(medium.path, MediaActivity.thumbnailSize, medium_thumbnail)
|
||||
|
||||
setOnClickListener { viewClicked(multiSelector, medium, pos) }
|
||||
setOnLongClickListener {
|
||||
|
|
|
@ -10,15 +10,20 @@ import android.view.KeyCharacterMap
|
|||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.ViewConfiguration
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.gallery.BuildConfig
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||
import com.simplemobiletools.gallery.adapters.MediaAdapter
|
||||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||
import com.simplemobiletools.gallery.helpers.REQUEST_EDIT_IMAGE
|
||||
import com.simplemobiletools.gallery.helpers.REQUEST_SET_WALLPAPER
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import com.simplemobiletools.gallery.views.MyImageView
|
||||
import com.squareup.picasso.Picasso
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
@ -180,3 +185,37 @@ fun SimpleActivity.removeNoMedia(path: String, callback: () -> Unit) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.loadImage(path: String, size: Int, target: MyImageView) {
|
||||
if (path.isGif()) {
|
||||
if (MediaAdapter.animateGifs) {
|
||||
Glide.with(this)
|
||||
.load(path)
|
||||
.asGif()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(target)
|
||||
} else {
|
||||
Glide.with(this)
|
||||
.load(path)
|
||||
.asBitmap()
|
||||
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
|
||||
.centerCrop()
|
||||
.into(target)
|
||||
}
|
||||
} else if (path.isVideoFast()) {
|
||||
Glide.with(this)
|
||||
.load(path)
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESULT)
|
||||
.centerCrop()
|
||||
.crossFade()
|
||||
.into(target)
|
||||
} else {
|
||||
Picasso.with(this)
|
||||
.load("file:$path")
|
||||
.resize(size, size)
|
||||
.centerCrop()
|
||||
.into(target)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue