update Commons and Glide

This commit is contained in:
tibbi 2017-07-01 00:04:31 +02:00
parent 33396362cb
commit 5b5f81fda5
8 changed files with 94 additions and 62 deletions

View File

@ -32,7 +32,7 @@ android {
}
dependencies {
compile 'com.simplemobiletools:commons:2.21.17'
compile 'com.simplemobiletools:commons:2.22.0'
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.6.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'

View File

@ -9,14 +9,14 @@ import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.support.v7.widget.GridLayoutManager
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.ViewGroup
import android.widget.FrameLayout
import com.bumptech.glide.Glide
import com.bumptech.glide.request.animation.GlideAnimation
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
@ -390,18 +390,22 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
val wantedWidth = wallpaperDesiredMinimumWidth
val wantedHeight = wallpaperDesiredMinimumHeight
val ratio = wantedWidth.toFloat() / wantedHeight
Glide.with(this)
.load(File(path))
.asBitmap()
val options = RequestOptions()
.override((wantedWidth * ratio).toInt(), wantedHeight)
.fitCenter()
Glide.with(this)
.asBitmap()
.load(File(path))
.apply(options)
.into(object : SimpleTarget<Bitmap>() {
override fun onResourceReady(bitmap: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) {
override fun onResourceReady(resource: Bitmap?, transition: Transition<in Bitmap>?) {
try {
WallpaperManager.getInstance(applicationContext).setBitmap(bitmap)
WallpaperManager.getInstance(applicationContext).setBitmap(resource)
setResult(Activity.RESULT_OK)
} catch (e: IOException) {
Log.e(TAG, "item click $e")
} catch (ignored: IOException) {
}
finish()

View File

@ -455,7 +455,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
}
fun stopLoad() {
Glide.clear(view.dir_thumbnail)
Glide.with(activity).clear(view.dir_thumbnail)
}
}

View File

@ -370,7 +370,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList<Medium>,
}
fun stopLoad() {
Glide.clear(view.medium_thumbnail)
Glide.with(activity).clear(view.medium_thumbnail)
}
}

View File

@ -15,7 +15,8 @@ import android.view.ViewConfiguration
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.signature.StringSignature
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.*
@ -262,8 +263,6 @@ fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback:
}
}
fun Activity.getFileSignature(path: String) = StringSignature(File(path).lastModified().toString())
fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean) {
target.isVerticalScrolling = verticalScroll
if (path.isImageFast() || path.isVideoFast()) {
@ -282,49 +281,55 @@ fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll:
}
fun Activity.loadPng(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext)
.load(path)
.asBitmap()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT)
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.format(DecodeFormat.PREFER_ARGB_8888)
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()
builder.into(target)
val builder = Glide.with(applicationContext)
.asBitmap()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
}
fun Activity.loadJpg(path: String, target: MySquareImageView) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
val builder = Glide.with(applicationContext)
.load(path)
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.crossFade()
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()
builder.into(target)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
}
fun Activity.loadAnimatedGif(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext)
.load(path)
.asGif()
.signature(getFileSignature(path))
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.NONE)
.crossFade()
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()
builder.into(target)
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 builder = Glide.with(applicationContext)
.load(path)
.asBitmap()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.DATA)
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter()
builder.into(target)
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> {

View File

@ -0,0 +1,6 @@
package com.simplemobiletools.gallery.extensions
import com.bumptech.glide.signature.ObjectKey
import java.io.File
fun String.getFileSignature() = ObjectKey(File(this).lastModified().toString())

View File

@ -7,15 +7,20 @@ import android.graphics.Color
import android.graphics.Matrix
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target
import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
@ -143,12 +148,15 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() {
if (medium.isGif()) {
Glide.with(this)
.load(medium.path)
.asGif()
.crossFade()
val options = RequestOptions()
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.LOW)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.diskCacheStrategy(DiskCacheStrategy.DATA)
Glide.with(this)
.asGif()
.load(medium.path)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(options)
.into(view.photo_view)
} else {
loadBitmap()
@ -160,31 +168,37 @@ class PhotoFragment : ViewPagerFragment() {
val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth
val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight
Glide.with(this)
.load(medium.path)
.asBitmap()
.signature(activity.getFileSignature(medium.path))
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
val options = RequestOptions()
.signature(medium.path.getFileSignature())
.format(DecodeFormat.PREFER_ARGB_8888)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.override(targetWidth, targetHeight)
.listener(object : RequestListener<String, Bitmap> {
override fun onException(e: Exception?, model: String?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
Glide.with(this)
.asBitmap()
.load(medium.path)
.apply(options)
.listener(object : RequestListener<Bitmap> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Bitmap>?, isFirstResource: Boolean): Boolean {
return false
}
override fun onResourceReady(resource: Bitmap, model: String?, target: Target<Bitmap>?, isFromMemoryCache: Boolean, isFirstResource: Boolean): Boolean {
override fun onResourceReady(resource: Bitmap?, model: Any?, target: Target<Bitmap>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
if (isFragmentVisible)
addZoomableView()
return false
}
}).into(view.photo_view)
} else {
Glide.with(this)
.load(medium.path)
.asBitmap()
.transform(GlideRotateTransformation(context, degrees))
.thumbnail(0.2f)
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(GlideRotateTransformation(context, degrees))
Glide.with(this)
.asBitmap()
.load(medium.path)
.thumbnail(0.2f)
.apply(options)
.into(view.photo_view)
}
}
@ -257,7 +271,9 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() {
super.onDestroyView()
Glide.clear(view.photo_view)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity.isDestroyed) {
Glide.with(context).clear(view.photo_view)
}
}
override fun onConfigurationChanged(newConfig: Configuration?) {

View File

@ -5,9 +5,9 @@ import android.graphics.Bitmap
import android.graphics.Matrix
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import java.security.MessageDigest
class GlideRotateTransformation(context: Context, val rotateRotationAngle: Float) : BitmapTransformation(context) {
override fun transform(pool: BitmapPool, bitmap: Bitmap, outWidth: Int, outHeight: Int): Bitmap {
if (rotateRotationAngle % 360 == 0f)
return bitmap
@ -17,5 +17,6 @@ class GlideRotateTransformation(context: Context, val rotateRotationAngle: Float
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.width, bitmap.height, matrix, true)
}
override fun getId() = "GlideRotateTransformation $rotateRotationAngle"
override fun updateDiskCacheKey(messageDigest: MessageDigest?) {
}
}