From 8965d69b9915110f9883378f8f536926cc0a4706 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 23 May 2019 18:13:03 +0200 Subject: [PATCH] By default list subscribed folders only --- .../java/eu/faircode/email/AdapterFolder.java | 2 +- .../eu/faircode/email/AdapterMessage.java | 2 +- app/src/main/java/eu/faircode/email/Core.java | 88 +++++++++---------- .../java/eu/faircode/email/EntityFolder.java | 12 --- .../eu/faircode/email/FragmentMessages.java | 2 +- .../faircode/email/FragmentOptionsMisc.java | 2 +- .../main/res/layout/fragment_options_misc.xml | 14 +-- app/src/main/res/values/strings.xml | 1 - 8 files changed, 49 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 9251cc3ac7..249f5f8777 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -190,7 +190,7 @@ public class AdapterFolder extends RecyclerView.Adapter targets = new ArrayList<>(); for (EntityFolder folder : folders) - if (!folder.isHidden(context) && + if (!folder.hide && !folder.id.equals(message.folder) && (copy || (!EntityFolder.ARCHIVE.equals(folder.type) && diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index dabaee497e..63bec86aa4 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -772,7 +772,7 @@ class Core { DB db = DB.getInstance(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean subscribed_only = prefs.getBoolean("subscribed_only", false); + boolean subscribed_only = prefs.getBoolean("subscribed_only", true); Log.i("Start sync folders account=" + account.name); @@ -782,7 +782,14 @@ class Core { EntityLog.log(context, account.name + " folder separator=" + separator); // Get remote folders - Folder[] ifolders = defaultFolder.list("*"); + Folder[] ifolders = (subscribed_only + ? defaultFolder.listSubscribed("*") + : defaultFolder.list("*")); + if (subscribed_only && ifolders.length == 0) { + Log.i("No subscribed folders"); + ifolders = defaultFolder.list("*"); + } + Log.i("Remote folder count=" + ifolders.length + " separator=" + separator); // Get folder names @@ -829,46 +836,41 @@ class Core { folder = db.folder().getFolderByName(account.id, fullName); if (folder == null) { - if (!subscribed_only || subscribed) { - folder = new EntityFolder(); - folder.account = account.id; - folder.name = fullName; - folder.display = display; - folder.type = (EntityFolder.SYSTEM.equals(type) ? type : EntityFolder.USER); - folder.synchronize = false; - folder.subscribed = subscribed; - folder.poll = ("imap.gmail.com".equals(account.host)); - folder.sync_days = EntityFolder.DEFAULT_SYNC; - folder.keep_days = EntityFolder.DEFAULT_KEEP; - folder.id = db.folder().insertFolder(folder); - Log.i(folder.name + " added type=" + folder.type); - } + folder = new EntityFolder(); + folder.account = account.id; + folder.name = fullName; + folder.display = display; + folder.type = (EntityFolder.SYSTEM.equals(type) ? type : EntityFolder.USER); + folder.synchronize = false; + folder.subscribed = subscribed; + folder.poll = ("imap.gmail.com".equals(account.host)); + folder.sync_days = EntityFolder.DEFAULT_SYNC; + folder.keep_days = EntityFolder.DEFAULT_KEEP; + folder.id = db.folder().insertFolder(folder); + Log.i(folder.name + " added type=" + folder.type); } else { - if (!subscribed_only || subscribed) { - Log.i(folder.name + " exists type=" + folder.type); + Log.i(folder.name + " exists type=" + folder.type); - if (folder.subscribed == null || !folder.subscribed.equals(subscribed)) - db.folder().setFolderSubscribed(folder.id, subscribed); + if (folder.subscribed == null || !folder.subscribed.equals(subscribed)) + db.folder().setFolderSubscribed(folder.id, subscribed); - if (folder.display == null && display != null) { - db.folder().setFolderDisplay(folder.id, display); - EntityLog.log(context, account.name + ":" + folder.name + - " removed prefix display=" + display + " separator=" + separator); - } + if (folder.display == null && display != null) { + db.folder().setFolderDisplay(folder.id, display); + EntityLog.log(context, account.name + ":" + folder.name + + " removed prefix display=" + display + " separator=" + separator); + } - // Compatibility - if ("Inbox_sub".equals(folder.type)) - db.folder().setFolderType(folder.id, EntityFolder.USER); - else if (EntityFolder.USER.equals(folder.type) && EntityFolder.SYSTEM.equals(type)) + // Compatibility + if ("Inbox_sub".equals(folder.type)) + db.folder().setFolderType(folder.id, EntityFolder.USER); + else if (EntityFolder.USER.equals(folder.type) && EntityFolder.SYSTEM.equals(type)) + db.folder().setFolderType(folder.id, type); + else if (EntityFolder.SYSTEM.equals(folder.type) && EntityFolder.USER.equals(type)) + db.folder().setFolderType(folder.id, type); + else if (EntityFolder.INBOX.equals(type) && !EntityFolder.INBOX.equals(folder.type)) { + if (db.folder().getFolderByType(folder.account, EntityFolder.INBOX) == null) db.folder().setFolderType(folder.id, type); - else if (EntityFolder.SYSTEM.equals(folder.type) && EntityFolder.USER.equals(type)) - db.folder().setFolderType(folder.id, type); - else if (EntityFolder.INBOX.equals(type) && !EntityFolder.INBOX.equals(folder.type)) { - if (db.folder().getFolderByType(folder.account, EntityFolder.INBOX) == null) - db.folder().setFolderType(folder.id, type); - } - } else - db.folder().deleteFolder(folder.id); + } } db.setTransactionSuccessful(); } finally { @@ -876,13 +878,11 @@ class Core { Log.i("End sync folder"); } - if (!subscribed_only || subscribed) { - nameFolder.put(folder.name, folder); - String parentName = folder.getParentName(separator); - if (!parentFolders.containsKey(parentName)) - parentFolders.put(parentName, new ArrayList()); - parentFolders.get(parentName).add(folder); - } + nameFolder.put(folder.name, folder); + String parentName = folder.getParentName(separator); + if (!parentFolders.containsKey(parentName)) + parentFolders.put(parentName, new ArrayList()); + parentFolders.get(parentName).add(folder); } } diff --git a/app/src/main/java/eu/faircode/email/EntityFolder.java b/app/src/main/java/eu/faircode/email/EntityFolder.java index 4f1a71e818..7e1e551d80 100644 --- a/app/src/main/java/eu/faircode/email/EntityFolder.java +++ b/app/src/main/java/eu/faircode/email/EntityFolder.java @@ -20,10 +20,8 @@ package eu.faircode.email; */ import android.content.Context; -import android.content.SharedPreferences; import androidx.annotation.NonNull; -import androidx.preference.PreferenceManager; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Index; @@ -216,16 +214,6 @@ public class EntityFolder extends EntityOrder implements Serializable { return R.drawable.baseline_folder_24; } - boolean isHidden(Context context) { - if (hide) - return true; - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean subscriptions = prefs.getBoolean("subscriptions", false); - - return (subscriptions && subscribed != null && !subscribed); - } - String getDisplayName(Context context) { return (display == null ? Helper.localizeFolderName(context, name) : display); } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 945d50986b..7867fa9c3c 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -1392,7 +1392,7 @@ public class FragmentMessages extends FragmentBase { List targets = new ArrayList<>(); List folders = db.folder().getFolders(account.id); for (EntityFolder target : folders) - if (!target.isHidden(context) && + if (!target.hide && !EntityFolder.ARCHIVE.equals(target.type) && !EntityFolder.TRASH.equals(target.type) && !EntityFolder.JUNK.equals(target.type) && diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index 605da0880e..82c78caf40 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -252,7 +252,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swBadge.setChecked(prefs.getBoolean("badge", true)); swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false)); - swSubscribedOnly.setChecked(prefs.getBoolean("subscribed_only", false)); + swSubscribedOnly.setChecked(prefs.getBoolean("subscribed_only", true)); swEnglish.setChecked(prefs.getBoolean("english", false)); swAuthentication.setChecked(prefs.getBoolean("authentication", false)); swParanoid.setChecked(prefs.getBoolean("paranoid", true)); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index 3eb4bd9a3a..fc80ccf768 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -49,18 +49,6 @@ app:layout_constraintTop_toBottomOf="@id/tvBadgeHint" app:switchPadding="12dp" /> - - + app:layout_constraintTop_toBottomOf="@id/swSubscriptions" /> Group messages related to each other When disabled only names will be shown when available Note that starred messages will always be kept locally - Folders not subscribed to will be hidden Only available when message text was downloaded Automatically open message when there is just one message or just one unread message in a conversation