mirror of https://github.com/M66B/FairEmail.git
Show image properties
This commit is contained in:
parent
2a0f3fe5c3
commit
07ad8c1227
|
@ -22,6 +22,7 @@ package eu.faircode.email;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.drawable.AnimatedImageDrawable;
|
import android.graphics.drawable.AnimatedImageDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
@ -44,6 +45,7 @@ import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -61,6 +63,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||||
private View view;
|
private View view;
|
||||||
private ImageView ivImage;
|
private ImageView ivImage;
|
||||||
private TextView tvCaption;
|
private TextView tvCaption;
|
||||||
|
private TextView tvProperties;
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
|
@ -68,6 +71,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||||
view = itemView.findViewById(R.id.clItem);
|
view = itemView.findViewById(R.id.clItem);
|
||||||
ivImage = itemView.findViewById(R.id.ivImage);
|
ivImage = itemView.findViewById(R.id.ivImage);
|
||||||
tvCaption = itemView.findViewById(R.id.tvCaption);
|
tvCaption = itemView.findViewById(R.id.tvCaption);
|
||||||
|
tvProperties = itemView.findViewById(R.id.tvProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void wire() {
|
private void wire() {
|
||||||
|
@ -83,28 +87,74 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
|
||||||
private void bindTo(EntityAttachment attachment) {
|
private void bindTo(EntityAttachment attachment) {
|
||||||
tvCaption.setText(attachment.name);
|
tvCaption.setText(attachment.name);
|
||||||
tvCaption.setVisibility(TextUtils.isEmpty(attachment.name) ? View.GONE : View.VISIBLE);
|
tvCaption.setVisibility(TextUtils.isEmpty(attachment.name) ? View.GONE : View.VISIBLE);
|
||||||
|
tvProperties.setVisibility(View.GONE);
|
||||||
|
|
||||||
if (attachment.available) {
|
if (attachment.available) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
Bundle args = new Bundle();
|
||||||
try {
|
args.putSerializable("file", attachment.getFile(context));
|
||||||
Drawable d = ImageHelper.getScaledDrawable(context,
|
args.putString("type", attachment.getMimeType());
|
||||||
attachment.getFile(context), attachment.getMimeType(),
|
args.putInt("max", context.getResources().getDisplayMetrics().widthPixels);
|
||||||
context.getResources().getDisplayMetrics().widthPixels);
|
|
||||||
ivImage.setImageDrawable(d);
|
new SimpleTask<Object>() {
|
||||||
if (d instanceof AnimatedImageDrawable)
|
@Override
|
||||||
((AnimatedImageDrawable) d).start();
|
protected void onPreExecute(Bundle args) {
|
||||||
return;
|
ivImage.setImageResource(R.drawable.twotone_hourglass_top_24);
|
||||||
} catch (Throwable ex) {
|
|
||||||
Log.w(ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bm = ImageHelper.decodeImage(
|
@Override
|
||||||
attachment.getFile(context), attachment.getMimeType(),
|
protected Object onExecute(Context context, Bundle args) throws Throwable {
|
||||||
context.getResources().getDisplayMetrics().widthPixels);
|
File file = (File) args.getSerializable("file");
|
||||||
if (bm == null)
|
String type = args.getString("type");
|
||||||
ivImage.setImageResource(R.drawable.twotone_broken_image_24);
|
int max = args.getInt("max");
|
||||||
else
|
|
||||||
ivImage.setImageBitmap(bm);
|
try {
|
||||||
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
|
options.inJustDecodeBounds = true;
|
||||||
|
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
|
||||||
|
args.putInt("width", options.outWidth);
|
||||||
|
args.putInt("height", options.outHeight);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
|
||||||
|
try {
|
||||||
|
return ImageHelper.getScaledDrawable(context, file, type, max);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImageHelper.decodeImage(file, type, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, Object image) {
|
||||||
|
if (image instanceof Drawable)
|
||||||
|
ivImage.setImageDrawable((Drawable) image);
|
||||||
|
else if (image instanceof Bitmap)
|
||||||
|
ivImage.setImageBitmap((Bitmap) image);
|
||||||
|
else
|
||||||
|
ivImage.setImageResource(R.drawable.twotone_broken_image_24);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P &&
|
||||||
|
image instanceof AnimatedImageDrawable)
|
||||||
|
((AnimatedImageDrawable) image).start();
|
||||||
|
|
||||||
|
int width = args.getInt("width");
|
||||||
|
int height = args.getInt("height");
|
||||||
|
if (width > 0 && height > 0) {
|
||||||
|
tvProperties.setText(String.format("%d \u00d7 %d", width, height));
|
||||||
|
tvProperties.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
tvCaption.setText(Log.formatThrowable(ex));
|
||||||
|
tvCaption.setVisibility(View.VISIBLE);
|
||||||
|
ivImage.setImageResource(R.drawable.twotone_broken_image_24);
|
||||||
|
}
|
||||||
|
}.execute(context, owner, args, "image:load");
|
||||||
} else
|
} else
|
||||||
ivImage.setImageResource(attachment.progress == null
|
ivImage.setImageResource(attachment.progress == null
|
||||||
? R.drawable.twotone_image_24 : R.drawable.twotone_hourglass_top_24);
|
? R.drawable.twotone_image_24 : R.drawable.twotone_hourglass_top_24);
|
||||||
|
|
|
@ -34,5 +34,17 @@
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/ivImage" />
|
app:layout_constraintTop_toBottomOf="@id/ivImage" />
|
||||||
|
|
||||||
|
<eu.faircode.email.FixedTextView
|
||||||
|
android:id="@+id/tvProperties"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:text="100 × 200"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
android:textSize="12sp"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
Loading…
Reference in New Issue