Use linked drafts folder

Fixes #28
This commit is contained in:
M66B 2018-08-08 11:21:19 +00:00
parent 94f0e866e1
commit 93f75af745
8 changed files with 28 additions and 70 deletions

View File

@ -68,9 +68,10 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ivSync = itemView.findViewById(R.id.ivSync); ivSync = itemView.findViewById(R.id.ivSync);
} }
private void wire() { private void wire(boolean properties) {
itemView.setOnClickListener(this); itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this); if (properties)
itemView.setOnLongClickListener(this);
} }
private void unwire() { private void unwire() {
@ -249,7 +250,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
TupleFolderEx folder = filtered.get(position); TupleFolderEx folder = filtered.get(position);
holder.bindTo(folder); holder.bindTo(folder);
holder.wire(folder.account != null);
holder.wire();
} }
} }

View File

@ -43,7 +43,7 @@ public class ApplicationEx extends Application {
DB db = null; DB db = null;
try { try {
db = DB.getBlockingInstance(ApplicationEx.this); db = DB.getBlockingInstance(ApplicationEx.this);
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); EntityFolder drafts = db.folder().getLocalDrafts();
if (drafts != null) { if (drafts != null) {
Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode"); Address to = new InternetAddress("marcel+email@faircode.eu", "FairCode");
String body = ex + "\n" + Log.getStackTraceString(ex); String body = ex + "\n" + Log.getStackTraceString(ex);

View File

@ -45,7 +45,7 @@ public interface DaoFolder {
" FROM folder" + " FROM folder" +
" LEFT JOIN account ON account.id = folder.account" + " LEFT JOIN account ON account.id = folder.account" +
" LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" + " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
" WHERE folder.account = :account" + " WHERE folder.account = :account OR folder.account IS NULL" +
" GROUP BY folder.id") " GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(long account); LiveData<List<TupleFolderEx>> liveFolders(long account);
@ -71,14 +71,12 @@ public interface DaoFolder {
" WHERE account = :account AND type = :type") " WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String 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 + "'") @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'")
EntityFolder getOutbox(); 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) @Insert(onConflict = OnConflictStrategy.REPLACE)
long insertFolder(EntityFolder folder); long insertFolder(EntityFolder folder);

View File

@ -61,7 +61,7 @@ public class FragmentAbout extends FragmentEx {
public void run() { public void run() {
try { try {
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
EntityFolder drafts = db.folder().getPrimaryFolder(EntityFolder.TYPE_DRAFTS); EntityFolder drafts = db.folder().getLocalDrafts();
if (drafts != null) { if (drafts != null) {
StringBuilder info = Helper.getDebugInfo(); StringBuilder info = Helper.getDebugInfo();
info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n"); info.insert(0, getString(R.string.title_debug_info_remark) + "\n\n\n\n");

View File

@ -324,16 +324,15 @@ public class FragmentAccount extends FragmentEx {
drafts = true; drafts = true;
} }
} }
/*
if (!drafts) { if (!drafts) {
EntityFolder folder = new EntityFolder(); 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.type = EntityFolder.TYPE_DRAFTS;
folder.synchronize = false; folder.synchronize = false;
folder.after = 0; folder.after = 0;
folders.add(folder); folders.add(folder);
} }
*/
} finally { } finally {
if (istore != null) if (istore != null)
istore.close(); istore.close();

View File

@ -51,7 +51,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -515,9 +514,20 @@ public class FragmentCompose extends FragmentEx {
// Get data // Get data
EntityMessage draft = message.getMessage(id); EntityMessage draft = message.getMessage(id);
EntityIdentity ident = identity.getIdentity(args.getLong("iid")); 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) 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); long rid = args.getLong("rid", -1);
String thread = args.getString("thread"); String thread = args.getString("thread");
@ -563,10 +573,8 @@ public class FragmentCompose extends FragmentEx {
db.beginTransaction(); db.beginTransaction();
if ("send".equals(action)) { 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) 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); EntityOperation.queue(getContext(), draft, EntityOperation.DELETE);
@ -583,7 +591,7 @@ public class FragmentCompose extends FragmentEx {
else if ("trash".equals(action)) { else if ("trash".equals(action)) {
EntityOperation.queue(getContext(), draft, EntityOperation.DELETE); 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) { if (trash != null) {
draft.id = null; draft.id = null;
draft.folder = trash.id; draft.folder = trash.id;

View File

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B) Copyright 2018 by Marcel Bokhorst (M66B)
*/ */
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -37,9 +36,6 @@ import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; 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.LivePagedListBuilder;
import androidx.paging.PagedList; import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
@ -95,7 +91,6 @@ public class FragmentMessages extends FragmentEx {
tvNoEmail.setVisibility(View.GONE); tvNoEmail.setVisibility(View.GONE);
grpReady.setVisibility(View.GONE); grpReady.setVisibility(View.GONE);
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
fab.setVisibility(View.GONE);
return view; 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<Bundle> {
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<Bundle>() {
@NonNull
@Override
public Loader<Bundle> onCreateLoader(int id, @Nullable Bundle args) {
return new InitLoader(getContext());
}
@Override
public void onLoadFinished(@NonNull Loader<Bundle> loader, Bundle data) {
fab.setVisibility(data.getBoolean("drafts", false) ? View.VISIBLE : View.GONE);
}
@Override
public void onLoaderReset(@NonNull Loader<Bundle> loader) {
}
};
} }

View File

@ -67,7 +67,6 @@
<string name="title_no_user">User name missing</string> <string name="title_no_user">User name missing</string>
<string name="title_no_password">Password missing</string> <string name="title_no_password">Password missing</string>
<string name="title_no_idle">IDLE not supported</string> <string name="title_no_idle">IDLE not supported</string>
<string name="title_local_drafts">Local drafts</string>
<string name="title_account_delete">Delete this account permanently?</string> <string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string> <string name="title_identity_delete">Delete this identity permanently?</string>
@ -84,6 +83,7 @@
<string name="title_folder_junk">Spam</string> <string name="title_folder_junk">Spam</string>
<string name="title_folder_sent">Sent</string> <string name="title_folder_sent">Sent</string>
<string name="title_folder_user">User</string> <string name="title_folder_user">User</string>
<string name="title_folder_local_drafts">Local drafts</string>
<string name="title_folder_thread">Message thread</string> <string name="title_folder_thread">Message thread</string>
<string name="title_no_messages">No messages</string> <string name="title_no_messages">No messages</string>
@ -118,8 +118,6 @@
<string name="title_save">Save</string> <string name="title_save">Save</string>
<string name="title_send">Send</string> <string name="title_send">Send</string>
<string name="title_no_primary_drafts">No primary account or no drafts folder</string>
<string name="title_from_missing">Sender missing</string> <string name="title_from_missing">Sender missing</string>
<string name="title_to_missing">Recipient missing</string> <string name="title_to_missing">Recipient missing</string>
<string name="title_draft_trashed">Draft trashed</string> <string name="title_draft_trashed">Draft trashed</string>