Simplification

This commit is contained in:
M66B
2021-01-23 09:28:51 +01:00
parent fb4d4d51f7
commit eba5b0f839
6 changed files with 20 additions and 22 deletions

View File

@@ -233,14 +233,13 @@ class ImageHelper {
boolean inline = prefs.getBoolean("inline_images", false);
final int px = Helper.dp2pixels(context, (zoom + 1) * 24);
final Resources.Theme theme = context.getTheme();
final Resources res = context.getResources();
try {
final AnnotatedSource a = new AnnotatedSource(source);
if (TextUtils.isEmpty(a.source)) {
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@@ -258,12 +257,12 @@ class ImageHelper {
EntityAttachment attachment = db.attachment().getAttachment(id, cid);
if (attachment == null) {
Log.i("Image not found CID=" + cid);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else if (!attachment.available) {
Log.i("Image not available CID=" + cid);
Drawable d = res.getDrawable(R.drawable.twotone_photo_library_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_photo_library_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@@ -276,7 +275,7 @@ class ImageHelper {
return d;
} catch (IOException ex) {
Log.w(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@@ -284,7 +283,7 @@ class ImageHelper {
Bitmap bm = decodeImage(attachment.getFile(context), scaleToPixels);
if (bm == null) {
Log.i("Image not decodable CID=" + cid);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
} else {
@@ -316,7 +315,7 @@ class ImageHelper {
return d;
} catch (IllegalArgumentException ex) {
Log.w(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@@ -362,7 +361,7 @@ class ImageHelper {
} catch (Throwable ex) {
// FileNotFound, Security
Log.w(ex);
Drawable d = context.getResources().getDrawable(R.drawable.twotone_broken_image_24);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}
@@ -370,7 +369,7 @@ class ImageHelper {
if (!show) {
// Show placeholder icon
int resid = (embedded || data ? R.drawable.twotone_photo_library_24 : R.drawable.twotone_image_24);
Drawable d = res.getDrawable(resid, theme);
Drawable d = context.getDrawable(resid);
d.setBounds(0, 0, px, px);
return d;
}
@@ -380,7 +379,7 @@ class ImageHelper {
if (cached != null || view == null) {
if (view == null)
if (cached == null) {
Drawable d = res.getDrawable(R.drawable.twotone_hourglass_top_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_hourglass_top_24);
d.setBounds(0, 0, px, px);
return d;
} else
@@ -391,7 +390,7 @@ class ImageHelper {
}
final LevelListDrawable lld = new LevelListDrawable();
Drawable wait = res.getDrawable(R.drawable.twotone_hourglass_top_24, theme);
Drawable wait = context.getDrawable(R.drawable.twotone_hourglass_top_24);
lld.addLevel(1, 1, wait);
lld.setBounds(0, 0, px, px);
lld.setLevel(1);
@@ -442,7 +441,7 @@ class ImageHelper {
int resid = (ex instanceof IOException && !(ex instanceof FileNotFoundException)
? R.drawable.twotone_cloud_off_24
: R.drawable.twotone_broken_image_24);
Drawable d = res.getDrawable(resid, theme);
Drawable d = context.getDrawable(resid);
d.setBounds(0, 0, px, px);
post(d, a.source);
}
@@ -478,7 +477,7 @@ class ImageHelper {
} catch (Throwable ex) {
Log.e(ex);
Drawable d = res.getDrawable(R.drawable.twotone_broken_image_24, theme);
Drawable d = context.getDrawable(R.drawable.twotone_broken_image_24);
d.setBounds(0, 0, px, px);
return d;
}