mirror of https://github.com/M66B/FairEmail.git
Check if draft complete
This commit is contained in:
parent
e4ec609949
commit
341032fd33
|
@ -1489,11 +1489,17 @@ public class FragmentCompose extends FragmentEx {
|
||||||
} else {
|
} else {
|
||||||
// Existing draft
|
// Existing draft
|
||||||
result.account = db.account().getAccount(result.draft.account);
|
result.account = db.account().getAccount(result.draft.account);
|
||||||
|
|
||||||
if (!result.draft.content) {
|
if (!result.draft.content) {
|
||||||
if (result.draft.uid == null)
|
if (result.draft.uid == null)
|
||||||
throw new IllegalStateException("Draft without uid");
|
throw new IllegalStateException("Draft without uid");
|
||||||
EntityOperation.queue(context, db, result.draft, EntityOperation.BODY);
|
EntityOperation.queue(context, db, result.draft, EntityOperation.BODY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<EntityAttachment> attachments = db.attachment().getAttachments(result.draft.id);
|
||||||
|
for (EntityAttachment attachment : attachments)
|
||||||
|
if (!attachment.available)
|
||||||
|
EntityOperation.queue(context, db, result.draft, EntityOperation.ATTACHMENT, attachment.sequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
|
@ -1576,9 +1582,6 @@ 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) {
|
||||||
|
@ -1588,12 +1591,14 @@ public class FragmentCompose extends FragmentEx {
|
||||||
|
|
||||||
rvAttachment.setTag(downloading);
|
rvAttachment.setTag(downloading);
|
||||||
checkInternet();
|
checkInternet();
|
||||||
|
|
||||||
|
checkDraft(result.draft.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
db.message().liveMessage(result.draft.id).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
|
db.message().liveMessage(result.draft.id).observe(getViewLifecycleOwner(), new Observer<EntityMessage>() {
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(final EntityMessage draft) {
|
public void onChanged(EntityMessage draft) {
|
||||||
// Draft was deleted
|
// Draft was deleted
|
||||||
if (draft == null || draft.ui_hide)
|
if (draft == null || draft.ui_hide)
|
||||||
finish();
|
finish();
|
||||||
|
@ -1601,8 +1606,7 @@ public class FragmentCompose extends FragmentEx {
|
||||||
tvNoInternet.setTag(draft.content);
|
tvNoInternet.setTag(draft.content);
|
||||||
checkInternet();
|
checkInternet();
|
||||||
|
|
||||||
if (draft.content && state == State.NONE)
|
checkDraft(draft.id);
|
||||||
showDraft(result.draft);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1618,6 +1622,41 @@ public class FragmentCompose extends FragmentEx {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void checkDraft(long id) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong("id", id);
|
||||||
|
|
||||||
|
new SimpleTask<EntityMessage>() {
|
||||||
|
@Override
|
||||||
|
protected EntityMessage onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
long id = args.getLong("id");
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
|
||||||
|
EntityMessage draft = db.message().getMessage(id);
|
||||||
|
if (!draft.content)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
|
||||||
|
for (EntityAttachment attachment : attachments)
|
||||||
|
if (!attachment.available)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return draft;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onExecuted(Bundle args, EntityMessage draft) {
|
||||||
|
showDraft(draft);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
||||||
|
}
|
||||||
|
}.execute(this, args);
|
||||||
|
}
|
||||||
|
|
||||||
private void showDraft(EntityMessage draft) {
|
private void showDraft(EntityMessage draft) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("id", draft.id);
|
args.putLong("id", draft.id);
|
||||||
|
|
Loading…
Reference in New Issue