Check for images in original message text

This commit is contained in:
M66B 2019-08-21 17:59:42 +02:00
parent 1128f52f58
commit e42c941300
1 changed files with 21 additions and 22 deletions

View File

@ -2386,8 +2386,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private SimpleTask<SpannableStringBuilder> bodyTask = new SimpleTask<SpannableStringBuilder>() {
@Override
protected SpannableStringBuilder onExecute(final Context context, final Bundle args) throws IOException {
final TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
final boolean show_images = args.getBoolean("show_images");
TupleMessageEx message = (TupleMessageEx) args.getSerializable("message");
boolean show_images = args.getBoolean("show_images");
boolean show_quotes = args.getBoolean("show_quotes");
int zoom = args.getInt("zoom");
@ -2399,9 +2399,27 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return null;
String body = Helper.readText(file);
Document document = Jsoup.parse(body);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false);
boolean has_images = false;
for (Element img : document.select("img")) {
if (inline) {
String src = img.attr("src");
if (!src.startsWith("cid:")) {
has_images = true;
break;
}
} else {
has_images = true;
break;
}
}
args.putBoolean("has_images", has_images);
if (!show_quotes) {
Document document = Jsoup.parse(body);
for (Element quote : document.select("blockquote"))
quote.html("&#8230;");
body = document.html();
@ -2448,25 +2466,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
builder.getSpanFlags(squote));
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean inline = prefs.getBoolean("inline_images", false);
boolean has_images;
ImageSpan[] spans = builder.getSpans(0, body.length(), ImageSpan.class);
if (inline) {
has_images = false;
for (ImageSpan span : spans) {
String source = span.getSource();
if (source == null || !source.startsWith("cid:")) {
has_images = true;
break;
}
}
} else
has_images = spans.length > 0;
args.putBoolean("has_images", has_images);
return builder;
}