Optimization

pull/213/head
M66B 2 years ago
parent 9ca6034855
commit 224525d88e

@ -2276,38 +2276,25 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
long id = Log.getDebugInfo(context, "main", R.string.title_debug_info_remark, null, null, args).id; long id = Log.getDebugInfo(context, "main", R.string.title_debug_info_remark, null, null, args).id;
if (send) { if (send) {
boolean sent = false;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
EntityMessage draft = db.message().getMessage(id); EntityMessage draft = db.message().getMessage(id);
if (draft != null) { if (draft != null) {
EntityFolder outbox = db.folder().getOutbox(); draft.folder = EntityFolder.getOutbox(context).id;
if (outbox == null) {
Log.w("Outbox missing");
outbox = EntityFolder.getOutbox();
outbox.id = db.folder().insertFolder(outbox);
}
draft.folder = outbox.id;
db.message().updateMessage(draft); db.message().updateMessage(draft);
EntityOperation.queue(context, draft, EntityOperation.SEND); EntityOperation.queue(context, draft, EntityOperation.SEND);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
sent = true; args.putBoolean("sent", true);
return null;
} }
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
if (sent) {
ToastEx.makeText(context, R.string.title_debug_info_send, Toast.LENGTH_LONG).show();
ServiceSend.start(context);
return null;
}
} }
return id; return id;
@ -2315,6 +2302,13 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
@Override @Override
protected void onExecuted(Bundle args, Long id) { protected void onExecuted(Bundle args, Long id) {
boolean sent = args.getBoolean("sent");
if (sent) {
ToastEx.makeText(ActivityView.this, R.string.title_debug_info_send, Toast.LENGTH_LONG).show();
ServiceSend.start(ActivityView.this);
return;
}
if (id == null) if (id == null)
return; return;
startActivity(new Intent(ActivityView.this, ActivityCompose.class) startActivity(new Intent(ActivityView.this, ActivityCompose.class)

@ -397,13 +397,23 @@ public class EntityFolder extends EntityOrder implements Serializable {
return result; return result;
} }
static EntityFolder getOutbox() { @NonNull
EntityFolder outbox = new EntityFolder(); static EntityFolder getOutbox(Context context) {
DB db = DB.getInstance(context);
EntityFolder outbox = db.folder().getOutbox();
if (outbox != null)
return outbox;
Log.w("Outbox missing");
outbox = new EntityFolder();
outbox.name = "OUTBOX"; outbox.name = "OUTBOX";
outbox.type = EntityFolder.OUTBOX; outbox.type = EntityFolder.OUTBOX;
outbox.synchronize = false; outbox.synchronize = false;
outbox.sync_days = 0; outbox.sync_days = 0;
outbox.keep_days = 0; outbox.keep_days = 0;
outbox.id = db.folder().insertFolder(outbox);
return outbox; return outbox;
} }

@ -1006,11 +1006,7 @@ public class EntityRule {
throw new IllegalArgumentException("Rule template not found name=" + rule.name); throw new IllegalArgumentException("Rule template not found name=" + rule.name);
} }
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = EntityFolder.getOutbox(context);
if (outbox == null) {
outbox = EntityFolder.getOutbox();
outbox.id = db.folder().insertFolder(outbox);
}
Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())}; Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())};

@ -7120,12 +7120,7 @@ public class FragmentCompose extends FragmentBase {
} }
} else if (action == R.id.action_send) { } else if (action == R.id.action_send) {
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = EntityFolder.getOutbox(context);
if (outbox == null) {
Log.w("Outbox missing");
outbox = EntityFolder.getOutbox();
outbox.id = db.folder().insertFolder(outbox);
}
// Delay sending message // Delay sending message
if (draft.ui_snoozed == null && send_delayed != 0) { if (draft.ui_snoozed == null && send_delayed != 0) {

@ -903,11 +903,7 @@ public class FragmentSetup extends FragmentBase implements SharedPreferences.OnS
try { try {
db.beginTransaction(); db.beginTransaction();
EntityFolder outbox = db.folder().getOutbox(); EntityFolder.getOutbox(context);
if (outbox == null) {
outbox = EntityFolder.getOutbox();
outbox.id = db.folder().insertFolder(outbox);
}
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {

@ -287,11 +287,7 @@ public class ServiceExternal extends Service {
if (to == null || to.length == 0) if (to == null || to.length == 0)
throw new IllegalArgumentException("No to recipients: " + toName); throw new IllegalArgumentException("No to recipients: " + toName);
EntityFolder outbox = db.folder().getOutbox(); EntityFolder outbox = EntityFolder.getOutbox(context);
if (outbox == null) {
outbox = EntityFolder.getOutbox();
outbox.id = db.folder().insertFolder(outbox);
}
Address[] from = new Address[]{ Address[] from = new Address[]{
new InternetAddress(identity.get(0).email, identity.get(0).name, StandardCharsets.UTF_8.name())}; new InternetAddress(identity.get(0).email, identity.get(0).name, StandardCharsets.UTF_8.name())};

Loading…
Cancel
Save