Added option to poll folder list

This commit is contained in:
M66B 2021-12-07 08:30:51 +01:00
parent 98d87f5fe1
commit b019d17c06
5 changed files with 59 additions and 9 deletions

View File

@ -1970,16 +1970,21 @@ class Core {
}
static void onSynchronizeFolders(
Context context, EntityAccount account, Store istore,
State state, boolean force) throws MessagingException {
Context context, EntityAccount account, Store istore, State state,
boolean keep_alive, boolean force) throws MessagingException {
DB db = DB.getInstance(context);
if (account.protocol != EntityAccount.TYPE_IMAP)
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sync_folders = prefs.getBoolean("sync_folders", true);
boolean sync_folders_poll = prefs.getBoolean("sync_folders_poll", false);
boolean sync_shared_folders = prefs.getBoolean("sync_shared_folders", false);
Log.i(account.name + " sync folders=" + sync_folders + " shared=" + sync_shared_folders + " force=" + force);
Log.i(account.name + " sync folders=" + sync_folders + " poll=" + sync_folders_poll +
" shared=" + sync_shared_folders + " force=" + force);
if (force)
if (force || (keep_alive && sync_folders_poll))
sync_folders = true;
if (!sync_folders)
sync_shared_folders = false;
@ -2089,7 +2094,7 @@ class Core {
if (!sync_folders)
return;
Log.i("Start sync folders account=" + account.name);
EntityLog.log(context, "Start sync folders account=" + account.name);
// Get default folder
Folder defaultFolder = istore.getDefaultFolder();

View File

@ -83,6 +83,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private SwitchCompat swSyncKept;
private SwitchCompat swGmailThread;
private SwitchCompat swSyncFolders;
private SwitchCompat swSyncFoldersPoll;
private SwitchCompat swSyncSharedFolders;
private SwitchCompat swSubscriptions;
private SwitchCompat swTuneKeepAlive;
@ -103,7 +104,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
"enabled", "poll_interval", "auto_optimize", "schedule", "schedule_start", "schedule_end",
"sync_quick_imap", "sync_quick_pop",
"sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "gmail_thread_id",
"sync_folders", "sync_shared_folders", "subscriptions",
"sync_folders", "sync_folders_poll", "sync_shared_folders", "subscriptions",
"check_authentication", "check_reply_domain", "check_mx", "check_blocklist", "use_blocklist",
"tune_keep_alive"
};
@ -149,6 +150,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swSyncKept = view.findViewById(R.id.swSyncKept);
swGmailThread = view.findViewById(R.id.swGmailThread);
swSyncFolders = view.findViewById(R.id.swSyncFolders);
swSyncFoldersPoll = view.findViewById(R.id.swSyncFoldersPoll);
swSyncSharedFolders = view.findViewById(R.id.swSyncSharedFolders);
swSubscriptions = view.findViewById(R.id.swSubscriptions);
swTuneKeepAlive = view.findViewById(R.id.swTuneKeepAlive);
@ -330,6 +332,15 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_folders", checked).apply();
swSyncFoldersPoll.setEnabled(checked);
swSyncSharedFolders.setEnabled(checked);
}
});
swSyncFoldersPoll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_folders_poll", checked).apply();
}
});
@ -483,7 +494,10 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swSyncKept.setChecked(prefs.getBoolean("sync_kept", true));
swGmailThread.setChecked(prefs.getBoolean("gmail_thread_id", false));
swSyncFolders.setChecked(prefs.getBoolean("sync_folders", true));
swSyncFoldersPoll.setChecked(prefs.getBoolean("sync_folders_poll", false));
swSyncFoldersPoll.setEnabled(swSyncFolders.isChecked());
swSyncSharedFolders.setChecked(prefs.getBoolean("sync_shared_folders", false));
swSyncSharedFolders.setEnabled(swSyncFolders.isChecked());
swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false));
swTuneKeepAlive.setChecked(prefs.getBoolean("tune_keep_alive", true));
swCheckAuthentication.setChecked(prefs.getBoolean("check_authentication", true));

View File

@ -1533,8 +1533,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
});
// Update folder list
if (account.protocol == EntityAccount.TYPE_IMAP)
Core.onSynchronizeFolders(this, account, iservice.getStore(), state, force && !forced);
Core.onSynchronizeFolders(this,
account, iservice.getStore(), state,
false, force && !forced);
// Open synchronizing folders
List<EntityFolder> folders = db.folder().getFolders(account.id, false, true);
@ -2040,6 +2041,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
" poll count=" + folder.poll_count +
" factor=" + folder.poll_factor);
}
Core.onSynchronizeFolders(this,
account, iservice.getStore(), state,
true, false);
}
} catch (Throwable ex) {
if (tune) {

View File

@ -601,6 +601,31 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSyncFolders" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSyncFoldersPoll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sync_folders_poll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSyncFolders"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSyncFoldersPoll"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_poll_folders_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSyncFoldersPoll" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSyncSharedFolders"
android:layout_width="0dp"
@ -610,7 +635,7 @@
android:text="@string/title_advanced_sync_shared_folders"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSyncFolders"
app:layout_constraintTop_toBottomOf="@id/tvSyncFoldersPoll"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -351,6 +351,7 @@
<string name="title_advanced_kept_removed">Check if old messages were removed from the server</string>
<string name="title_advanced_gmail_thread">Gmail message grouping style for Gmail accounts</string>
<string name="title_advanced_sync_folders">Synchronize folder list</string>
<string name="title_advanced_sync_folders_poll">Actively synchronize folder list</string>
<string name="title_advanced_sync_shared_folders">Synchronize shared folder lists</string>
<string name="title_advanced_subscriptions">Manage folder subscriptions</string>
<string name="title_advanced_check_authentication">Check message authentication</string>
@ -713,6 +714,7 @@
<string name="title_advanced_sync_kept_hint">This will transfer extra data and consume extra battery power, especially if a lot of messages are stored on the device</string>
<string name="title_advanced_gmail_thread_hint">This only applies to newly received messages and can break existing groups</string>
<string name="title_advanced_sync_folders_hint">Disabling this will reduce data and battery usage somewhat, but will disable updating the list of folders too</string>
<string name="title_advanced_poll_folders_hint">Periodically synchronize the folder list in addition to after connecting to an account</string>
<string name="title_advanced_check_authentication_hint">This will check the results of DKIM, SPF and DMARC authentication as performed by the email server</string>
<string name="title_advanced_check_reply_hint">This will check if the domain name of the sender and the reply address are the same</string>
<string name="title_advanced_lookup_mx_hint">This will check if DNS MX records exist</string>