diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 30138c7b6c..5d6c13093c 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -68,9 +68,10 @@ public class AdapterFolder extends RecyclerView.Adapter> liveFolders(long account); @@ -71,14 +71,12 @@ public interface DaoFolder { " WHERE account = :account AND type = :type") EntityFolder getFolderByType(long account, String type); + @Query("SELECT * FROM folder WHERE account IS NULL AND type = '" + EntityFolder.TYPE_DRAFTS + "'") + EntityFolder getLocalDrafts(); + @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'") EntityFolder getOutbox(); - @Query("SELECT folder.* FROM folder" + - " JOIN account ON account.id = folder.account" + - " WHERE account.`primary` AND type = :type ") - EntityFolder getPrimaryFolder(String type); - @Insert(onConflict = OnConflictStrategy.REPLACE) long insertFolder(EntityFolder folder); diff --git a/app/src/main/java/eu/faircode/email/FragmentAbout.java b/app/src/main/java/eu/faircode/email/FragmentAbout.java index 9639c78fd1..a1809d92d2 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAbout.java +++ b/app/src/main/java/eu/faircode/email/FragmentAbout.java @@ -61,7 +61,7 @@ public class FragmentAbout extends FragmentEx { public void run() { try { DB db = DB.getInstance(getContext()); - EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); + EntityFolder drafts = db.folder().getLocalDrafts(); if (drafts != null) { StringBuilder info = Helper.getDebugInfo(); info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n"); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index bee52029b4..17c94910da 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -324,16 +324,15 @@ public class FragmentAccount extends FragmentEx { drafts = true; } } -/* + if (!drafts) { EntityFolder folder = new EntityFolder(); - folder.name = getContext().getString(R.string.title_local_drafts); + folder.name = getContext().getString(R.string.title_folder_local_drafts); folder.type = EntityFolder.TYPE_DRAFTS; folder.synchronize = false; folder.after = 0; folders.add(folder); } -*/ } finally { if (istore != null) istore.close(); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 11c486ed7f..d16a654266 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -51,7 +51,6 @@ import java.util.Date; import java.util.List; import javax.mail.Address; -import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import androidx.annotation.NonNull; @@ -515,9 +514,20 @@ public class FragmentCompose extends FragmentEx { // Get data EntityMessage draft = message.getMessage(id); EntityIdentity ident = identity.getIdentity(args.getLong("iid")); - EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); + if (ident == null) + throw new IllegalArgumentException(getContext().getString(R.string.title_from_missing)); + + EntityFolder drafts = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_DRAFTS); if (drafts == null) - throw new Throwable(getContext().getString(R.string.title_no_primary_drafts)); + drafts = db.folder().getLocalDrafts(); + if (drafts == null) { + drafts = new EntityFolder(); + drafts.name = getContext().getString(R.string.title_folder_local_drafts); + drafts.type = EntityFolder.TYPE_DRAFTS; + drafts.synchronize = false; + drafts.after = 0; + db.folder().insertFolder(drafts); + } long rid = args.getLong("rid", -1); String thread = args.getString("thread"); @@ -563,10 +573,8 @@ public class FragmentCompose extends FragmentEx { db.beginTransaction(); if ("send".equals(action)) { - if (draft.identity == null) - throw new MessagingException(getContext().getString(R.string.title_from_missing)); if (draft.to == null && draft.cc == null && draft.bcc == null) - throw new MessagingException(getContext().getString(R.string.title_to_missing)); + throw new IllegalArgumentException(getContext().getString(R.string.title_to_missing)); EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); @@ -583,7 +591,7 @@ public class FragmentCompose extends FragmentEx { else if ("trash".equals(action)) { EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); - EntityFolder trash = db.folder().getPrimaryFolder(EntityFolder.TYPE_TRASH); + EntityFolder trash = db.folder().getFolderByType(ident.account, EntityFolder.TYPE_TRASH); if (trash != null) { draft.id = null; draft.folder = trash.id; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index f3928884fa..21932c7b57 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -19,7 +19,6 @@ package eu.faircode.email; Copyright 2018 by Marcel Bokhorst (M66B) */ -import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.preference.PreferenceManager; @@ -37,9 +36,6 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; import androidx.lifecycle.LiveData; import androidx.lifecycle.Observer; -import androidx.loader.app.LoaderManager; -import androidx.loader.content.AsyncTaskLoader; -import androidx.loader.content.Loader; import androidx.paging.LivePagedListBuilder; import androidx.paging.PagedList; import androidx.recyclerview.widget.LinearLayoutManager; @@ -95,7 +91,6 @@ public class FragmentMessages extends FragmentEx { tvNoEmail.setVisibility(View.GONE); grpReady.setVisibility(View.GONE); pbWait.setVisibility(View.VISIBLE); - fab.setVisibility(View.GONE); return view; } @@ -150,45 +145,5 @@ public class FragmentMessages extends FragmentEx { } } }); - - LoaderManager.getInstance(this) - .restartLoader(ActivityView.LOADER_MESSAGES_INIT, new Bundle(), initLoaderCallbacks).forceLoad(); - } - - private static class InitLoader extends AsyncTaskLoader { - InitLoader(@NonNull Context context) { - super(context); - } - - @Nullable - @Override - public Bundle loadInBackground() { - Bundle result = new Bundle(); - try { - EntityFolder drafts = DB.getInstance(getContext()).folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); - result.putBoolean("drafts", drafts != null); - } catch (Throwable ex) { - Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex)); - result.putBoolean("drafts", false); - } - return result; - } } - - private LoaderManager.LoaderCallbacks initLoaderCallbacks = new LoaderManager.LoaderCallbacks() { - @NonNull - @Override - public Loader onCreateLoader(int id, @Nullable Bundle args) { - return new InitLoader(getContext()); - } - - @Override - public void onLoadFinished(@NonNull Loader loader, Bundle data) { - fab.setVisibility(data.getBoolean("drafts", false) ? View.VISIBLE : View.GONE); - } - - @Override - public void onLoaderReset(@NonNull Loader loader) { - } - }; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 941af0e358..f6583b6552 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,7 +67,6 @@ User name missing Password missing IDLE not supported - Local drafts Delete this account permanently? Delete this identity permanently? @@ -84,6 +83,7 @@ Spam Sent User + Local drafts Message thread No messages @@ -118,8 +118,6 @@ Save Send - No primary account or no drafts folder - Sender missing Recipient missing Draft trashed