From c93fc6227119718d60ae65e8b817b99f037495c1 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 20 Feb 2021 08:17:32 +0100 Subject: [PATCH] Let child folders inherit parent folder properties --- app/src/main/java/eu/faircode/email/Core.java | 27 +++++++++++++++---- .../email/FragmentOptionsSynchronize.java | 14 +--------- .../layout/fragment_options_synchronize.xml | 13 +-------- app/src/main/res/values/strings.xml | 1 - 4 files changed, 24 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index 3b4503808f..dc2d9b2924 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -1686,7 +1686,6 @@ class Core { boolean sync_folders = (prefs.getBoolean("sync_folders", true) || force); boolean sync_shared_folders = prefs.getBoolean("sync_shared_folders", false); boolean subscriptions = prefs.getBoolean("subscriptions", false); - boolean sync_subscribed = prefs.getBoolean("sync_subscribed", false); // Get folder names boolean drafts = false; @@ -1890,18 +1889,36 @@ class Core { folder = db.folder().getFolderByName(account.id, fullName); if (folder == null) { + EntityFolder parent = null; + int sep = fullName.lastIndexOf(account.separator); + if (sep > 0) { + parent = db.folder().getFolderByName(account.id, fullName.substring(0, sep)); + if (parent != null && !EntityFolder.USER.equals(parent.type)) + parent = null; + } + folder = new EntityFolder(); folder.account = account.id; folder.name = fullName; folder.type = (EntityFolder.SYSTEM.equals(type) ? type : EntityFolder.USER); - folder.synchronize = (subscribed && subscriptions && sync_subscribed); folder.subscribed = subscribed; - folder.poll = true; - folder.sync_days = EntityFolder.DEFAULT_SYNC; - folder.keep_days = EntityFolder.DEFAULT_KEEP; folder.selectable = selectable; folder.inferiors = inferiors; + folder.setProperties(); folder.setSpecials(account); + + if (parent != null) { + folder.synchronize = parent.synchronize; + folder.poll = parent.poll; + folder.poll_factor = parent.poll_factor; + folder.download = parent.download; + folder.auto_classify_source = parent.auto_classify_source; + folder.auto_classify_target = parent.auto_classify_target; + folder.unified = parent.unified; + folder.navigation = parent.navigation; + folder.notify = parent.notify; + } + folder.id = db.folder().insertFolder(folder); Log.i(folder.name + " added type=" + folder.type + " sync=" + folder.synchronize); if (folder.synchronize) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java index 0cee9c4d98..a6527ede58 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSynchronize.java @@ -81,7 +81,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr private SwitchCompat swSyncFolders; private SwitchCompat swSyncSharedFolders; private SwitchCompat swSubscriptions; - private SwitchCompat swSyncSubscribed; private SwitchCompat swCheckMx; private SwitchCompat swTuneKeepAlive; private Group grpExempted; @@ -91,7 +90,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr private final static String[] RESET_OPTIONS = new String[]{ "enabled", "poll_interval", "auto_optimize", "schedule", "schedule_start", "schedule_end", "sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "gmail_thread_id", - "sync_folders", "sync_shared_folders", "subscriptions", "sync_subscribed", + "sync_folders", "sync_shared_folders", "subscriptions", "check_mx", "tune_keep_alive" }; @@ -135,7 +134,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr swSyncFolders = view.findViewById(R.id.swSyncFolders); swSyncSharedFolders = view.findViewById(R.id.swSyncSharedFolders); swSubscriptions = view.findViewById(R.id.swSubscriptions); - swSyncSubscribed = view.findViewById(R.id.swSyncSubscribed); swCheckMx = view.findViewById(R.id.swCheckMx); swTuneKeepAlive = view.findViewById(R.id.swTuneKeepAlive); grpExempted = view.findViewById(R.id.grpExempted); @@ -308,14 +306,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { prefs.edit().putBoolean("subscriptions", checked).apply(); - swSyncSubscribed.setEnabled(checked); - } - }); - - swSyncSubscribed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("sync_subscribed", checked).apply(); } }); @@ -419,8 +409,6 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr swSyncSharedFolders.setChecked(prefs.getBoolean("sync_shared_folders", false)); swSyncSharedFolders.setEnabled(swSyncFolders.isChecked()); swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false)); - swSyncSubscribed.setChecked(prefs.getBoolean("sync_subscribed", false)); - swSyncSubscribed.setEnabled(swSubscriptions.isChecked()); swCheckMx.setChecked(prefs.getBoolean("check_mx", false)); swTuneKeepAlive.setChecked(prefs.getBoolean("tune_keep_alive", true)); } diff --git a/app/src/main/res/layout/fragment_options_synchronize.xml b/app/src/main/res/layout/fragment_options_synchronize.xml index caed4518b2..6639bba401 100644 --- a/app/src/main/res/layout/fragment_options_synchronize.xml +++ b/app/src/main/res/layout/fragment_options_synchronize.xml @@ -493,17 +493,6 @@ app:layout_constraintTop_toBottomOf="@id/swSyncSharedFolders" app:switchPadding="12dp" /> - - Synchronize folder list Synchronize shared folder lists Manage folder subscriptions - Automatically synchronize subscribed folders Check sender email addresses on synchronizing messages Automatically tune the keep-alive interval