Added quick sync options

pull/202/head
M66B 3 years ago
parent 6457c76bcf
commit 32be7ba708

@ -2276,13 +2276,14 @@ class Core {
POP3Folder ifolder, POP3Store istore, State state) throws MessagingException, IOException {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sync_quick_pop = prefs.getBoolean("sync_quick_pop", true);
boolean notify_known = prefs.getBoolean("notify_known", false);
boolean pro = ActivityBilling.isPro(context);
boolean force = jargs.optBoolean(5, false);
EntityLog.log(context, account.name + " POP sync type=" + folder.type +
" force=" + force +
" quick=" + sync_quick_pop + " force=" + force +
" connected=" + (ifolder != null));
if (!EntityFolder.INBOX.equals(folder.type)) {
@ -2308,7 +2309,7 @@ class Core {
: Math.min(imessages.length, account.max_messages));
boolean sync = true;
if (!force &&
if (sync_quick_pop && !force &&
imessages.length > 0 && folder.last_sync_count != null &&
imessages.length == folder.last_sync_count) {
// Check if last message known as new messages indicator
@ -2613,6 +2614,7 @@ class Core {
keep_days++;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sync_quick_imap = prefs.getBoolean("sync_quick_imap", false);
boolean sync_nodate = prefs.getBoolean("sync_nodate", false);
boolean sync_unseen = prefs.getBoolean("sync_unseen", false);
boolean sync_flagged = prefs.getBoolean("sync_flagged", false);
@ -2622,7 +2624,7 @@ class Core {
boolean perform_expunge = prefs.getBoolean("perform_expunge", true);
Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days +
" force=" + force +
" quick=" + sync_quick_imap + " force=" + force +
" sync unseen=" + sync_unseen + " flagged=" + sync_flagged +
" delete unseen=" + delete_unseen + " kept=" + sync_kept);
@ -2700,6 +2702,10 @@ class Core {
Log.i(folder.name + " local old=" + old);
}
Message[] imessages;
long search;
Long[] ids;
if (modified || !sync_quick_imap || force) {
// Get list of local uids
final List<Long> uids = db.message().getUids(folder.id, sync_kept || force ? null : sync_time);
Log.i(folder.name + " local count=" + uids.size());
@ -2718,8 +2724,7 @@ class Core {
if (sync_flagged && flags.contains(Flags.Flag.FLAGGED))
searchTerm = new OrTerm(searchTerm, new FlagTerm(new Flags(Flags.Flag.FLAGGED), true));
long search = SystemClock.elapsedRealtime();
Message[] imessages;
search = SystemClock.elapsedRealtime();
if (sync_time == 0)
imessages = ifolder.getMessages();
else
@ -2737,9 +2742,9 @@ class Core {
stats.search_ms = (SystemClock.elapsedRealtime() - search);
Log.i(folder.name + " remote count=" + imessages.length + " search=" + stats.search_ms + " ms");
Long[] ids = new Long[imessages.length];
if (!modified) {
Log.i(folder.name + " quick check");
ids = new Long[imessages.length];
if (!modified && !(sync_quick_imap && !force)) {
Log.i(folder.name + " quick check count=" + imessages.length);
long fetch = SystemClock.elapsedRealtime();
FetchProfile fp = new FetchProfile();
@ -3072,6 +3077,28 @@ class Core {
}
}
}
} else {
List<Message> _imessages = new ArrayList<>();
List<Long> _ids = new ArrayList<>();
List<EntityMessage> messages = db.message().getMessagesWithoutContent(
folder.id, sync_kept || force ? null : sync_time);
if (messages != null) {
Log.i(folder.name + " needs content=" + messages.size());
for (EntityMessage message : messages) {
Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage != null) {
_imessages.add(imessage);
_ids.add(message.id);
}
}
}
search = SystemClock.elapsedRealtime();
imessages = _imessages.toArray(new Message[0]);
ids = _ids.toArray(new Long[0]);
}
// Delete not synchronized messages without uid
if (!EntityFolder.isOutgoing(folder.type)) {

@ -566,6 +566,13 @@ public interface DaoMessage {
" AND NOT uid IS NULL")
List<Long> getUids(long folder, Long received);
@Query("SELECT * FROM message" +
" WHERE folder = :folder" +
" AND (:received IS NULL OR received >= :received)" +
" AND NOT uid IS NULL" +
" AND NOT content")
List<EntityMessage> getMessagesWithoutContent(long folder, Long received);
@Query("SELECT uid FROM message" +
" WHERE folder = :folder" +
" AND NOT ui_busy IS NULL" +

@ -72,6 +72,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
private CheckBox[] cbDay;
private ImageButton ibSchedules;
private SwitchCompat swQuickSyncImap;
private SwitchCompat swQuickSyncPop;
private SwitchCompat swNodate;
private SwitchCompat swUnseen;
private SwitchCompat swFlagged;
@ -96,6 +98,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_quick_imap", "sync_quick_pop",
"sync_nodate", "sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "gmail_thread_id",
"sync_folders", "sync_shared_folders", "subscriptions",
"check_authentication", "check_reply_domain", "check_mx", "check_blocklist", "use_blocklist",
@ -133,6 +136,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
};
ibSchedules = view.findViewById(R.id.ibSchedules);
swQuickSyncImap = view.findViewById(R.id.swQuickSyncImap);
swQuickSyncPop = view.findViewById(R.id.swQuickSyncPop);
swNodate = view.findViewById(R.id.swNodate);
swUnseen = view.findViewById(R.id.swUnseen);
swFlagged = view.findViewById(R.id.swFlagged);
@ -260,6 +265,20 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
}
});
swQuickSyncImap.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_quick_imap", checked).apply();
}
});
swQuickSyncPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_quick_pop", checked).apply();
}
});
swNodate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -448,6 +467,8 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
for (int i = 0; i < 7; i++)
cbDay[i].setChecked(prefs.getBoolean("schedule_day" + i, true));
swQuickSyncImap.setChecked(prefs.getBoolean("sync_quick_imap", false));
swQuickSyncPop.setChecked(prefs.getBoolean("sync_quick_pop", true));
swNodate.setChecked(prefs.getBoolean("sync_nodate", false));
swUnseen.setChecked(prefs.getBoolean("sync_unseen", false));
swFlagged.setChecked(prefs.getBoolean("sync_flagged", false));

@ -372,6 +372,57 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvQuickSync"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_quick_sync"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvQuickSyncHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_quick_sync_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/tvQuickSync" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickSyncImap"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_imap"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvQuickSyncHint"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQuickSyncPop"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_pop3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swQuickSyncImap"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNodate"
android:layout_width="0dp"
@ -380,7 +431,7 @@
android:text="@string/title_advanced_no_date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAdvanced"
app:layout_constraintTop_toBottomOf="@id/swQuickSyncPop"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

@ -320,6 +320,7 @@
<string name="title_advanced_always">Always receive messages for these accounts</string>
<string name="title_advanced_schedule">Schedule</string>
<string name="title_advanced_advanced">Advanced</string>
<string name="title_advanced_quick_sync">Quick sync</string>
<string name="title_advanced_no_date">Messages without date</string>
<string name="title_advanced_unseen">All unread messages</string>
<string name="title_advanced_flagged">All starred messages</string>
@ -628,6 +629,7 @@
<string name="title_advanced_poll_hint">Periodically checking for new messages will compare local and remote messages every time, which is an expensive operation that may result in extra battery usage, especially if there are a lot of messages. Always receive will prevent this by continuously following changes.</string>
<string name="title_advanced_optimize_hint">This might change the sync frequency to save battery usage depending on the capabilities and behavior of the email servers</string>
<string name="title_advanced_schedule_hint">Tap on a time to set a time</string>
<string name="title_advanced_quick_sync_hint">This reduces data usage, but new messages might be missed if the email server doesn\'t follow the standards</string>
<string name="title_advanced_no_date_hint">Some providers store messages with an unknown, invalid or future date as messages without date</string>
<string name="title_advanced_unseen_hint">Some providers don\'t support this properly, which may cause synchronizing none or all messages</string>
<string name="title_advanced_deleted_unseen">When disabled, unread messages are kept on the device forever</string>

Loading…
Cancel
Save