Image improvements

pull/194/merge
M66B 4 years ago
parent 767c7bc16a
commit f9356bb646

@ -24,6 +24,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimatedImageDrawable; import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -95,14 +96,14 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
args.putString("type", attachment.getMimeType()); args.putString("type", attachment.getMimeType());
args.putInt("max", context.getResources().getDisplayMetrics().widthPixels); args.putInt("max", context.getResources().getDisplayMetrics().widthPixels);
new SimpleTask<Object>() { new SimpleTask<Drawable>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
ivImage.setImageResource(R.drawable.twotone_hourglass_top_24); ivImage.setImageResource(R.drawable.twotone_hourglass_top_24);
} }
@Override @Override
protected Object onExecute(Context context, Bundle args) throws Throwable { protected Drawable onExecute(Context context, Bundle args) throws Throwable {
File file = (File) args.getSerializable("file"); File file = (File) args.getSerializable("file");
String type = args.getString("type"); String type = args.getString("type");
int max = args.getInt("max"); int max = args.getInt("max");
@ -126,17 +127,18 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
Log.w(ex); Log.w(ex);
} }
return ImageHelper.decodeImage(file, type, max); Bitmap bm = ImageHelper.decodeImage(file, type, max);
if (bm == null)
return null;
return new BitmapDrawable(context.getResources(), bm);
} }
@Override @Override
protected void onExecuted(Bundle args, Object image) { protected void onExecuted(Bundle args, Drawable image) {
if (image instanceof Drawable) if (image == null)
ivImage.setImageDrawable((Drawable) image);
else if (image instanceof Bitmap)
ivImage.setImageBitmap((Bitmap) image);
else
ivImage.setImageResource(R.drawable.twotone_broken_image_24); ivImage.setImageResource(R.drawable.twotone_broken_image_24);
else
ivImage.setImageDrawable(image);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P &&
image instanceof AnimatedImageDrawable) image instanceof AnimatedImageDrawable)
@ -375,4 +377,9 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
holder.wire(); holder.wire();
} }
@Override
public void onViewRecycled(@NonNull AdapterImage.ViewHolder holder) {
holder.ivImage.setImageDrawable(null);
}
} }

Loading…
Cancel
Save