Added option to synchronize subscribed folders only

pull/156/head
M66B 6 years ago
parent e5d91ac619
commit 50bcc79a0d

@ -771,6 +771,9 @@ class Core {
static void onSynchronizeFolders(Context context, EntityAccount account, Store istore, State state) throws MessagingException {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean subscribed_only = prefs.getBoolean("subscribed_only", false);
Log.i("Start sync folders account=" + account.name);
// Get default folder
@ -802,7 +805,6 @@ class Core {
names.add(folder.name);
Log.i("Local folder count=" + names.size());
Map<String, EntityFolder> nameFolder = new HashMap<>();
Map<String, List<EntityFolder>> parentFolders = new HashMap<>();
for (Folder ifolder : ifolders) {
@ -811,8 +813,8 @@ class Core {
String[] attr = ((IMAPFolder) ifolder).getAttributes();
String type = EntityFolder.getType(attr, fullName);
EntityLog.log(context, account.name + ":" + fullName +
" attrs=" + TextUtils.join(" ", attr) + " type=" + type);
Log.i(account.name + ":" + fullName + " subscribed=" + subscribed +
" type=" + type + " attrs=" + TextUtils.join(" ", attr));
if (type != null) {
names.remove(fullName);
@ -827,41 +829,46 @@ class Core {
folder = db.folder().getFolderByName(account.id, fullName);
if (folder == null) {
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);
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);
}
} else {
Log.i(folder.name + " exists type=" + folder.type);
if (!subscribed_only || subscribed) {
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))
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)
// 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
db.folder().deleteFolder(folder.id);
}
db.setTransactionSuccessful();
} finally {

@ -46,6 +46,7 @@ import java.text.SimpleDateFormat;
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swBadge;
private SwitchCompat swSubscriptions;
private SwitchCompat swSubscribedOnly;
private SwitchCompat swEnglish;
private SwitchCompat swAuthentication;
private SwitchCompat swParanoid;
@ -60,7 +61,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvLastCleanup;
private final static String[] RESET_OPTIONS = new String[]{
"badge", "subscriptions", "english", "authentication", "paranoid", "cache_lists", "watchdog", "updates", "crash_reports", "debug"
"badge", "subscriptions", "subscribed_only", "english", "authentication", "paranoid", "cache_lists", "watchdog", "updates", "crash_reports", "debug"
};
private final static String[] RESET_QUESTIONS = new String[]{
@ -79,6 +80,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swBadge = view.findViewById(R.id.swBadge);
swSubscriptions = view.findViewById(R.id.swSubscriptions);
swSubscribedOnly = view.findViewById(R.id.swSubscribedOnly);
swEnglish = view.findViewById(R.id.swEnglish);
swAuthentication = view.findViewById(R.id.swAuthentication);
swParanoid = view.findViewById(R.id.swParanoid);
@ -113,6 +115,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swSubscribedOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subscribed_only", checked).apply();
ServiceSynchronize.reload(getContext(), "subscribed_only");
}
});
swEnglish.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -242,6 +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));
swEnglish.setChecked(prefs.getBoolean("english", false));
swAuthentication.setChecked(prefs.getBoolean("authentication", false));
swParanoid.setChecked(prefs.getBoolean("paranoid", true));

@ -62,7 +62,7 @@
app:layout_constraintTop_toBottomOf="@id/swSubscriptions" />
<TextView
android:id="@+id/tvNotifyPreviewPro"
android:id="@+id/tvSubscriptionPro"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
@ -73,6 +73,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSubscriptionsHint" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSubscribedOnly"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sync_subscribed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSubscriptionPro"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swEnglish"
android:layout_width="match_parent"
@ -80,7 +90,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_advanced_english"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewPro"
app:layout_constraintTop_toBottomOf="@id/swSubscribedOnly"
app:switchPadding="12dp" />
<TextView

@ -221,6 +221,7 @@
<string name="title_advanced_badge">Show launcher icon with number of new messages</string>
<string name="title_advanced_subscriptions">Manage folder subscriptions</string>
<string name="title_advanced_sync_subscribed">Synchronize subscribed folders only</string>
<string name="title_advanced_english">Force English language</string>
<string name="title_advanced_authentication">Show a warning when the receiving server could not authenticate the message</string>
<string name="title_advanced_paranoid">Extra privacy features</string>

Loading…
Cancel
Save