From 5f77582bec9354d507cdc297f85bafbbd53a710f Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 3 Aug 2018 16:21:18 +0000 Subject: [PATCH] Create outbox on setup To make sure the event listener is started --- .../eu/faircode/email/FragmentCompose.java | 13 +---------- .../java/eu/faircode/email/FragmentSetup.java | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 2ae2f03d..54fb0a2e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -599,20 +599,9 @@ public class FragmentCompose extends Fragment { if (draft.to == null && draft.cc == null && draft.bcc == null) throw new MessagingException(getContext().getString(R.string.title_to_missing)); - // Get outbox - EntityFolder outbox = folder.getOutbox(); - if (outbox == null) { - outbox = new EntityFolder(); - outbox.name = "OUTBOX"; - outbox.type = EntityFolder.TYPE_OUTBOX; - outbox.synchronize = false; - outbox.after = 0; - outbox.id = folder.insertFolder(outbox); - } - // Build outgoing message EntityMessage out = new EntityMessage(); - out.folder = outbox.id; + out.folder = folder.getOutbox().id; out.identity = draft.identity; out.replying = draft.replying; out.thread = draft.thread; diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 90d768b2..0028f2f2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -37,6 +37,8 @@ import android.widget.ProgressBar; import android.widget.TextView; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class FragmentSetup extends Fragment { private Button btnAccount; @@ -48,6 +50,8 @@ public class FragmentSetup extends Fragment { private TextView tvIdentityDone; private TextView tvPermissionsDone; + private ExecutorService executor = Executors.newCachedThreadPool(); + private static final String[] permissions = new String[]{ Manifest.permission.READ_CONTACTS }; @@ -151,7 +155,7 @@ public class FragmentSetup extends Fragment { tvIdentityDone.setVisibility(View.INVISIBLE); tvPermissionsDone.setVisibility(View.INVISIBLE); - DB db = DB.getInstance(getContext()); + final DB db = DB.getInstance(getContext()); db.account().liveAccounts(true).observe(this, new Observer>() { @Override @@ -173,6 +177,22 @@ public class FragmentSetup extends Fragment { onRequestPermissionsResult(0, permissions, grantResults); + // Creat outbox + executor.submit(new Runnable() { + @Override + public void run() { + EntityFolder outbox = db.folder().getOutbox(); + if (outbox == null) { + outbox = new EntityFolder(); + outbox.name = "OUTBOX"; + outbox.type = EntityFolder.TYPE_OUTBOX; + outbox.synchronize = false; + outbox.after = 0; + outbox.id = db.folder().insertFolder(outbox); + } + } + }); + return view; }