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

View file

@ -455,7 +455,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList<Direc
} }
fun stopLoad() { 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() { 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.Glide
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy 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.Gson
import com.google.gson.reflect.TypeToken import com.google.gson.reflect.TypeToken
import com.simplemobiletools.commons.extensions.* 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) { fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll: Boolean) {
target.isVerticalScrolling = verticalScroll target.isVerticalScrolling = verticalScroll
if (path.isImageFast() || path.isVideoFast()) { if (path.isImageFast() || path.isVideoFast()) {
@ -282,49 +281,55 @@ fun Activity.loadImage(path: String, target: MySquareImageView, verticalScroll:
} }
fun Activity.loadPng(path: String, target: MySquareImageView) { fun Activity.loadPng(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext) val options = RequestOptions()
.load(path) .signature(path.getFileSignature())
.asBitmap() .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.format(DecodeFormat.PREFER_ARGB_8888) .format(DecodeFormat.PREFER_ARGB_8888)
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter() val builder = Glide.with(applicationContext)
builder.into(target) .asBitmap()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
} }
fun Activity.loadJpg(path: String, target: MySquareImageView) { fun Activity.loadJpg(path: String, target: MySquareImageView) {
val options = RequestOptions()
.signature(path.getFileSignature())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
val builder = Glide.with(applicationContext) val builder = Glide.with(applicationContext)
.load(path) .load(path)
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.crossFade()
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter() if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.into(target) builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
} }
fun Activity.loadAnimatedGif(path: String, target: MySquareImageView) { fun Activity.loadAnimatedGif(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext) val options = RequestOptions()
.load(path) .signature(path.getFileSignature())
.asGif()
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.crossFade()
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter() val builder = Glide.with(applicationContext)
builder.into(target) .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) { fun Activity.loadStaticGif(path: String, target: MySquareImageView) {
val builder = Glide.with(applicationContext) val options = RequestOptions()
.load(path) .signature(path.getFileSignature())
.asBitmap() .diskCacheStrategy(DiskCacheStrategy.DATA)
.signature(getFileSignature(path))
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
if (config.cropThumbnails) builder.centerCrop() else builder.fitCenter() val builder = Glide.with(applicationContext)
builder.into(target) .asBitmap()
.load(path)
if (config.cropThumbnails) options.centerCrop() else options.fitCenter()
builder.apply(options).into(target)
} }
fun Activity.getCachedDirectories(): ArrayList<Directory> { 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.Matrix
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.Priority import com.bumptech.glide.Priority
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.DecodeFormat import com.bumptech.glide.load.DecodeFormat
import com.bumptech.glide.load.engine.DiskCacheStrategy 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.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target import com.bumptech.glide.request.target.Target
import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
@ -143,12 +148,15 @@ class PhotoFragment : ViewPagerFragment() {
private fun loadImage() { private fun loadImage() {
if (medium.isGif()) { if (medium.isGif()) {
Glide.with(this) val options = RequestOptions()
.load(medium.path)
.asGif()
.crossFade()
.priority(if (isFragmentVisible) Priority.IMMEDIATE else Priority.LOW) .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) .into(view.photo_view)
} else { } else {
loadBitmap() loadBitmap()
@ -160,31 +168,37 @@ class PhotoFragment : ViewPagerFragment() {
val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth val targetWidth = if (ViewPagerActivity.screenWidth == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenWidth
val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight val targetHeight = if (ViewPagerActivity.screenHeight == 0) Target.SIZE_ORIGINAL else ViewPagerActivity.screenHeight
Glide.with(this) val options = RequestOptions()
.load(medium.path) .signature(medium.path.getFileSignature())
.asBitmap() .format(DecodeFormat.PREFER_ARGB_8888)
.signature(activity.getFileSignature(medium.path))
.format(if (medium.isPng()) DecodeFormat.PREFER_ARGB_8888 else DecodeFormat.PREFER_RGB_565)
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.override(targetWidth, targetHeight) .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 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) if (isFragmentVisible)
addZoomableView() addZoomableView()
return false return false
} }
}).into(view.photo_view) }).into(view.photo_view)
} else { } else {
Glide.with(this) val options = RequestOptions()
.load(medium.path)
.asBitmap()
.transform(GlideRotateTransformation(context, degrees))
.thumbnail(0.2f)
.diskCacheStrategy(DiskCacheStrategy.NONE) .diskCacheStrategy(DiskCacheStrategy.NONE)
.transform(GlideRotateTransformation(context, degrees))
Glide.with(this)
.asBitmap()
.load(medium.path)
.thumbnail(0.2f)
.apply(options)
.into(view.photo_view) .into(view.photo_view)
} }
} }
@ -257,7 +271,9 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.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?) { override fun onConfigurationChanged(newConfig: Configuration?) {

View file

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