diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index ee4f2c1e43..c809f6cfae 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -79,14 +79,16 @@ public abstract class DB extends RoomDatabase { sInstance = migrate(Room .databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) .setJournalMode(JournalMode.WRITE_AHEAD_LOGGING)); + return sInstance; } - public static DB getBlockingInstance(Context context) { - return migrate(Room - .databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) - .setJournalMode(JournalMode.WRITE_AHEAD_LOGGING) - .allowMainThreadQueries()); + @Override + public void beginTransaction() { + // This is a workaround for sqlite crashing on some devices + // Confusingly, the journal mode needs to be set to write ahead logging first for this to work + getOpenHelper().setWriteAheadLoggingEnabled(false); + super.beginTransaction(); } private static DB migrate(RoomDatabase.Builder builder) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index b7a11a46a1..6f118c2f38 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -900,15 +900,6 @@ public class FragmentCompose extends FragmentEx { String pbody = "
" + body.replaceAll("\\r?\\n", "
") + "
"; - // Check data - if (action == R.id.action_send) { - if (draft.identity == null) - throw new IllegalArgumentException(context.getString(R.string.title_from_missing)); - - if (draft.to == null && draft.cc == null && draft.bcc == null) - throw new IllegalArgumentException(context.getString(R.string.title_to_missing)); - } - try { db.beginTransaction(); @@ -940,6 +931,15 @@ public class FragmentCompose extends FragmentEx { db.message().updateMessage(draft); draft.write(context, pbody); + // Check data + if (action == R.id.action_send) { + if (draft.identity == null) + throw new IllegalArgumentException(context.getString(R.string.title_from_missing)); + + if (draft.to == null && draft.cc == null && draft.bcc == null) + throw new IllegalArgumentException(context.getString(R.string.title_to_missing)); + } + // Save message ID String msgid = draft.msgid;