Fixed showing inline images for downloaded drafts

This commit is contained in:
M66B 2019-01-06 14:11:53 +00:00
parent 43a1af4879
commit 02119e8ccb
1 changed files with 87 additions and 73 deletions

View File

@ -1562,6 +1562,9 @@ public class FragmentCompose extends FragmentEx {
adapter.set(attachments); adapter.set(attachments);
grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE); grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE);
if (result.draft.content)
showDraft(result.draft);
boolean downloading = false; boolean downloading = false;
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (attachment.progress != null) { if (attachment.progress != null) {
@ -1584,17 +1587,50 @@ public class FragmentCompose extends FragmentEx {
tvNoInternet.setTag(draft.content); tvNoInternet.setTag(draft.content);
checkInternet(); checkInternet();
if (draft.content && state == State.NONE) { if (draft.content && state == State.NONE)
state = State.LOADING; showDraft(result.draft);
}
}
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
// External app sending absolute file
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
};
private void showDraft(EntityMessage draft) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", result.draft.id); args.putLong("id", draft.id);
if (result.draft.replying != null) if (draft.replying != null)
args.putLong("reference", result.draft.replying); args.putLong("reference", draft.replying);
else if (result.draft.forwarding != null) else if (draft.forwarding != null)
args.putLong("reference", result.draft.forwarding); args.putLong("reference", draft.forwarding);
new SimpleTask<Spanned[]>() { new SimpleTask<Spanned[]>() {
@Override
protected void onPreExecute(Bundle args) {
state = State.LOADING;
}
@Override
protected void onPostExecute(Bundle args) {
state = State.LOADED;
autosave = true;
pbWait.setVisibility(View.GONE);
edit_bar.setVisibility(View.VISIBLE);
bottom_navigation.setVisibility(View.VISIBLE);
Helper.setViewsEnabled(view, true);
getActivity().invalidateOptionsMenu();
}
@Override @Override
protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable { protected Spanned[] onExecute(final Context context, Bundle args) throws Throwable {
long id = args.getLong("id"); long id = args.getLong("id");
@ -1620,18 +1656,9 @@ public class FragmentCompose extends FragmentEx {
etBody.setText(texts[0]); etBody.setText(texts[0]);
etBody.setSelection(0); etBody.setSelection(0);
etBody.setVisibility(View.VISIBLE); etBody.setVisibility(View.VISIBLE);
tvReference.setText(texts[1]); tvReference.setText(texts[1]);
state = State.LOADED;
autosave = true;
pbWait.setVisibility(View.GONE);
grpReference.setVisibility(texts[1] == null ? View.GONE : View.VISIBLE); grpReference.setVisibility(texts[1] == null ? View.GONE : View.VISIBLE);
edit_bar.setVisibility(View.VISIBLE);
bottom_navigation.setVisibility(View.VISIBLE);
Helper.setViewsEnabled(view, true);
getActivity().invalidateOptionsMenu();
new Handler().post(new Runnable() { new Handler().post(new Runnable() {
@Override @Override
@ -1652,20 +1679,6 @@ public class FragmentCompose extends FragmentEx {
} }
}.execute(FragmentCompose.this, args); }.execute(FragmentCompose.this, args);
} }
}
}
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
// External app sending absolute file
if (ex instanceof IllegalArgumentException)
Snackbar.make(view, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
}
};
private SimpleTask<EntityMessage> actionLoader = new SimpleTask<EntityMessage>() { private SimpleTask<EntityMessage> actionLoader = new SimpleTask<EntityMessage>() {
@Override @Override
@ -1921,11 +1934,12 @@ public class FragmentCompose extends FragmentEx {
private Html.ImageGetter cidGetter = new Html.ImageGetter() { private Html.ImageGetter cidGetter = new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
if (source != null && source.startsWith("cid")) { if (source != null && source.startsWith("cid:")) {
String[] cid = source.split(":"); DB db = DB.getInstance(getContext());
if (cid.length == 2 && cid[1].startsWith(BuildConfig.APPLICATION_ID)) { String cid = "<" + source.substring(4) + ">";
long id = Long.parseLong(cid[1].replace(BuildConfig.APPLICATION_ID + ".", "")); EntityAttachment attachment = db.attachment().getAttachment(working, cid);
File file = EntityAttachment.getFile(getContext(), id); if (attachment != null) {
File file = EntityAttachment.getFile(getContext(), attachment.id);
Drawable d = Drawable.createFromPath(file.getAbsolutePath()); Drawable d = Drawable.createFromPath(file.getAbsolutePath());
if (d != null) { if (d != null) {
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());