Migrate to Glide (#1175)
* Replace Picasso library with Glide library tuskyapp#1082 * Replace Picasso library with Glide library tuskyapp#1082 * Update load emoji with glide * Update context used for Glide * Removed unused import * Replace deprecated SimpleTarget with CustomTarget * Fix crash at the view image fragment, remove override image size * Replace Single.create with Single.fromCallable * View image fragment refactor * Fix after merge * Try to load cached image first and show progress view on failure * Try to load cached image first and show progress view on failure
This commit is contained in:
parent
db51c23717
commit
76ce28980c
32 changed files with 260 additions and 322 deletions
|
@ -16,12 +16,16 @@ package com.keylesspalace.tusky.view
|
|||
|
||||
import android.content.Context
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import com.bumptech.glide.load.DataSource
|
||||
import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import com.keylesspalace.tusky.entity.Attachment
|
||||
|
||||
import com.keylesspalace.tusky.util.FocalPointUtil
|
||||
import com.squareup.picasso.Callback
|
||||
|
||||
/**
|
||||
* This is an extension of the standard android ImageView, which makes sure to update the custom
|
||||
|
@ -39,7 +43,7 @@ class MediaPreviewImageView
|
|||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : AppCompatImageView(context, attrs, defStyleAttr), Callback {
|
||||
) : AppCompatImageView(context, attrs, defStyleAttr),RequestListener<Drawable> {
|
||||
private var focus: Attachment.Focus? = null
|
||||
private var focalMatrix: Matrix? = null
|
||||
|
||||
|
@ -94,18 +98,16 @@ defStyleAttr: Int = 0
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the image is first succesfully loaded by Picasso, this function makes sure
|
||||
* that the custom matrix of this image is initialized if a focus point is set.
|
||||
*/
|
||||
override fun onSuccess() {
|
||||
onSizeChanged(width, height, width, height)
|
||||
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
// We do not handle the error here, instead it will be handled higher up the call chain.
|
||||
override fun onError() {
|
||||
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||
onSizeChanged(width, height, width, height)
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the size of the view changes, it calls the FocalPointUtil to update the
|
||||
* matrix if we have a set focal point. It then reassigns the matrix to this imageView.
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/* Copyright 2017 Andrew Dawson
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.view;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
|
||||
import com.squareup.picasso.Transformation;
|
||||
|
||||
public class RoundedTransformation implements Transformation {
|
||||
|
||||
private final float percent;
|
||||
|
||||
/** 100% would mean a perfectly round image **/
|
||||
public RoundedTransformation(final float percent) {
|
||||
this.percent = percent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap transform(Bitmap source) {
|
||||
|
||||
final int width = source.getWidth();
|
||||
final int height = source.getHeight();
|
||||
final int shorterSide;
|
||||
if (width > height) {
|
||||
shorterSide = height;
|
||||
} else {
|
||||
shorterSide = width;
|
||||
}
|
||||
|
||||
final float radius = shorterSide / 2 * percent / 100;
|
||||
|
||||
final Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
|
||||
|
||||
if (source != output) {
|
||||
source.recycle();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "rounded "+percent+"%";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue