From feba2894781d29326bf3bac98f8f11c7f263965b Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 22 Oct 2018 18:02:06 +0000 Subject: [PATCH] Allow swipe if target folders exists only --- .../eu/faircode/email/AdapterMessage.java | 6 ++-- .../java/eu/faircode/email/DaoFolder.java | 10 ++++-- .../eu/faircode/email/FragmentAccount.java | 4 +-- .../eu/faircode/email/FragmentMessages.java | 31 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 - 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index c0898e70..58bfe772 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -357,7 +357,7 @@ public class AdapterMessage extends PagedListAdapter 0 && show_expanded ? View.VISIBLE : View.GONE); - db.folder().liveFolders(message.account).removeObservers(owner); + db.folder().liveSystemFolders(message.account).removeObservers(owner); db.attachment().liveAttachments(message.id).removeObservers(owner); bnvActions.setTag(null); @@ -391,9 +391,9 @@ public class AdapterMessage extends PagedListAdapter>() { + db.folder().liveSystemFolders(message.account).observe(owner, new Observer>() { @Override - public void onChanged(@Nullable List folders) { + public void onChanged(@Nullable List folders) { if (bnvActions.hasTransientState()) { boolean hasJunk = false; boolean hasTrash = false; diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 3485a37c..cd96069b 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -55,6 +55,11 @@ public interface DaoFolder { " GROUP BY folder.id") LiveData> liveFolders(long account); + @Query("SELECT * FROM folder" + + " WHERE (:account < 0 OR folder.account = :account)" + + " AND type <> '" + EntityFolder.USER + "'") + LiveData> liveSystemFolders(long account); + @Query("SELECT folder.*, account.name AS accountName" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + @@ -118,9 +123,8 @@ public interface DaoFolder { @Query("UPDATE folder" + " SET type = '" + EntityFolder.USER + "'" + - " WHERE account = :account" + - " AND type = :type") - int setFolderUser(long account, String type); + " WHERE account = :account") + int setFoldersUser(long account); @Query("UPDATE folder" + " SET name = :name" + diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index b188add9..33104fc9 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -628,8 +628,6 @@ public class FragmentAccount extends FragmentEx { interval = "9"; if (synchronize && drafts == null) throw new Throwable(getContext().getString(R.string.title_no_drafts)); - if (synchronize && trash == null) - throw new Throwable(getContext().getString(R.string.title_no_trash)); if (Color.TRANSPARENT == color) color = null; @@ -731,8 +729,8 @@ public class FragmentAccount extends FragmentEx { folders.add(junk); } + db.folder().setFoldersUser(account.id); for (EntityFolder folder : folders) { - db.folder().setFolderUser(account.id, folder.type); EntityFolder existing = db.folder().getFolderByName(account.id, folder.name); if (existing == null) { folder.account = account.id; diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 9caf97cc..a1cf5c5b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -88,6 +88,8 @@ public class FragmentMessages extends FragmentEx { private long primary = -1; private boolean connected = false; private AdapterMessage adapter; + private List archives = new ArrayList<>(); + private List trashes = new ArrayList<>(); private AdapterMessage.ViewType viewType; private LiveData> messages = null; @@ -242,7 +244,13 @@ public class FragmentMessages extends FragmentEx { EntityFolder.OUTBOX.equals(message.folderType)) return 0; - return makeMovementFlags(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT); + int flags = 0; + if (archives.contains(message.account)) + flags |= ItemTouchHelper.RIGHT; + if (trashes.contains(message.account)) + flags |= ItemTouchHelper.LEFT; + + return makeMovementFlags(0, flags); } @Override @@ -583,8 +591,25 @@ public class FragmentMessages extends FragmentEx { break; } - // Messages - loadMessages(); + // Folders and messages + db.folder().liveSystemFolders(account).observe(getViewLifecycleOwner(), new Observer>() { + @Override + public void onChanged(List folders) { + if (folders == null) + folders = new ArrayList<>(); + + archives.clear(); + trashes.clear(); + + for (EntityFolder folder : folders) + if (EntityFolder.ARCHIVE.equals(folder.type)) + archives.add(folder.account); + else if (EntityFolder.TRASH.equals(folder.type)) + trashes.add(folder.account); + + loadMessages(); + } + }); if (viewType == AdapterMessage.ViewType.THREAD) { // Navigation diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ce7fc03c..09b96311 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -126,7 +126,6 @@ User name missing Password missing No drafts folder selected - No trash folder selected No primary account or no drafts folder No primary account or no archive folder This provider does not support push messages. Reception of new messages can be delayed.