mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-23 22:51:02 +00:00
Added fail-safe
This commit is contained in:
parent
9e352840a2
commit
c2537d1315
1 changed files with 78 additions and 74 deletions
|
@ -6429,91 +6429,95 @@ public class FragmentCompose extends FragmentBase {
|
||||||
rvAttachment.setTag(downloading);
|
rvAttachment.setTag(downloading);
|
||||||
checkInternet();
|
checkInternet();
|
||||||
|
|
||||||
boolean updated = false;
|
try {
|
||||||
Editable edit = etBody.getEditableText();
|
boolean updated = false;
|
||||||
ImageSpan[] spans = edit.getSpans(0, edit.length(), ImageSpan.class);
|
Editable edit = etBody.getEditableText();
|
||||||
if (spans == null)
|
ImageSpan[] spans = edit.getSpans(0, edit.length(), ImageSpan.class);
|
||||||
spans = new ImageSpan[0];
|
if (spans == null)
|
||||||
|
spans = new ImageSpan[0];
|
||||||
|
|
||||||
for (EntityAttachment attachment : attachments) {
|
for (EntityAttachment attachment : attachments) {
|
||||||
EntityAttachment prev = map.get(attachment.id);
|
EntityAttachment prev = map.get(attachment.id);
|
||||||
if (prev == null) // New attachment
|
if (prev == null) // New attachment
|
||||||
continue;
|
continue;
|
||||||
map.remove(attachment.id);
|
map.remove(attachment.id);
|
||||||
|
|
||||||
if (!prev.available && attachment.available) // Attachment downloaded
|
if (!prev.available && attachment.available) // Attachment downloaded
|
||||||
|
for (ImageSpan span : spans) {
|
||||||
|
String source = span.getSource();
|
||||||
|
if (source != null && source.startsWith("cid:")) {
|
||||||
|
String cid = "<" + source.substring(4) + ">";
|
||||||
|
if (cid.equals(attachment.cid)) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong("id", working);
|
||||||
|
args.putString("source", source);
|
||||||
|
args.putInt("zoom", zoom);
|
||||||
|
|
||||||
|
new SimpleTask<Drawable>() {
|
||||||
|
@Override
|
||||||
|
protected Drawable onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
long id = args.getLong("id");
|
||||||
|
String source = args.getString("source");
|
||||||
|
int zoom = args.getInt("zoom");
|
||||||
|
return ImageHelper.decodeImage(context, id, source, true, zoom, 1.0f, etBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, Drawable d) {
|
||||||
|
String source = args.getString("source");
|
||||||
|
Editable edit = etBody.getEditableText();
|
||||||
|
ImageSpan[] spans = edit.getSpans(0, edit.length(), ImageSpan.class);
|
||||||
|
for (ImageSpan span : spans)
|
||||||
|
if (source != null && source.equals(span.getSource())) {
|
||||||
|
int start = edit.getSpanStart(span);
|
||||||
|
int end = edit.getSpanEnd(span);
|
||||||
|
edit.removeSpan(span);
|
||||||
|
if (d == null)
|
||||||
|
edit.delete(start, end);
|
||||||
|
else
|
||||||
|
edit.setSpan(new ImageSpan(d, source), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
etBody.setText(edit);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
}.execute(FragmentCompose.this, args, "attachment:downloaded");
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (EntityAttachment removed : map.values())
|
||||||
for (ImageSpan span : spans) {
|
for (ImageSpan span : spans) {
|
||||||
String source = span.getSource();
|
String source = span.getSource();
|
||||||
if (source != null && source.startsWith("cid:")) {
|
if (source != null && source.startsWith("cid:")) {
|
||||||
String cid = "<" + source.substring(4) + ">";
|
String cid = "<" + source.substring(4) + ">";
|
||||||
if (cid.equals(attachment.cid)) {
|
if (cid.equals(removed.cid)) {
|
||||||
Bundle args = new Bundle();
|
updated = true;
|
||||||
args.putLong("id", working);
|
int start = edit.getSpanStart(span);
|
||||||
args.putString("source", source);
|
int end = edit.getSpanEnd(span);
|
||||||
args.putInt("zoom", zoom);
|
edit.removeSpan(span);
|
||||||
|
edit.delete(start, end);
|
||||||
new SimpleTask<Drawable>() {
|
|
||||||
@Override
|
|
||||||
protected Drawable onExecute(Context context, Bundle args) throws Throwable {
|
|
||||||
long id = args.getLong("id");
|
|
||||||
String source = args.getString("source");
|
|
||||||
int zoom = args.getInt("zoom");
|
|
||||||
return ImageHelper.decodeImage(context, id, source, true, zoom, 1.0f, etBody);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onExecuted(Bundle args, Drawable d) {
|
|
||||||
String source = args.getString("source");
|
|
||||||
Editable edit = etBody.getEditableText();
|
|
||||||
ImageSpan[] spans = edit.getSpans(0, edit.length(), ImageSpan.class);
|
|
||||||
for (ImageSpan span : spans)
|
|
||||||
if (source != null && source.equals(span.getSource())) {
|
|
||||||
int start = edit.getSpanStart(span);
|
|
||||||
int end = edit.getSpanEnd(span);
|
|
||||||
edit.removeSpan(span);
|
|
||||||
if (d == null)
|
|
||||||
edit.delete(start, end);
|
|
||||||
else
|
|
||||||
edit.setSpan(new ImageSpan(d, source), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
||||||
etBody.setText(edit);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onException(Bundle args, Throwable ex) {
|
|
||||||
// Ignored
|
|
||||||
}
|
|
||||||
}.execute(FragmentCompose.this, args, "attachment:downloaded");
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (updated)
|
||||||
|
etBody.setText(edit);
|
||||||
|
|
||||||
|
map.clear();
|
||||||
|
for (EntityAttachment attachment : attachments)
|
||||||
|
map.put(attachment.id, attachment);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EntityAttachment removed : map.values())
|
|
||||||
for (ImageSpan span : spans) {
|
|
||||||
String source = span.getSource();
|
|
||||||
if (source != null && source.startsWith("cid:")) {
|
|
||||||
String cid = "<" + source.substring(4) + ">";
|
|
||||||
if (cid.equals(removed.cid)) {
|
|
||||||
updated = true;
|
|
||||||
int start = edit.getSpanStart(span);
|
|
||||||
int end = edit.getSpanEnd(span);
|
|
||||||
edit.removeSpan(span);
|
|
||||||
edit.delete(start, end);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (updated)
|
|
||||||
etBody.setText(edit);
|
|
||||||
|
|
||||||
map.clear();
|
|
||||||
for (EntityAttachment attachment : attachments)
|
|
||||||
map.put(attachment.id, attachment);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue