mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-10 19:13:03 +02:00
Background sync, simplifications
This commit is contained in:
@@ -293,7 +293,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityOperation.sync(context, fid);
|
||||
EntityOperation.sync(context, fid, true);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ public class EntityOperation {
|
||||
queue(context, db, message, name, jargs);
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid) {
|
||||
static void sync(Context context, long fid, boolean foreground) {
|
||||
DB db = DB.getInstance(context);
|
||||
if (db.operation().getOperationCount(fid, EntityOperation.SYNC) == 0) {
|
||||
|
||||
@@ -112,10 +112,10 @@ public class EntityOperation {
|
||||
|
||||
if (account == null) // Outbox
|
||||
ServiceSend.start(context);
|
||||
else if (!"connected".equals(account.state))
|
||||
else if (foreground && !"connected".equals(account.state))
|
||||
ServiceUI.process(context, fid);
|
||||
|
||||
Log.i("Queued sync folder=" + folder);
|
||||
Log.i("Queued sync folder=" + folder + " foreground=" + foreground);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -250,7 +250,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
|
||||
db.message().deleteMessagesBefore(id, keep_time, true);
|
||||
|
||||
EntityOperation.sync(context, folder.id);
|
||||
EntityOperation.sync(context, folder.id, true);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
@@ -299,7 +299,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
// Unified inbox
|
||||
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified();
|
||||
for (EntityFolder folder : folders)
|
||||
EntityOperation.sync(context, folder.id);
|
||||
EntityOperation.sync(context, folder.id, true);
|
||||
} else {
|
||||
// Folder list
|
||||
EntityAccount account = db.account().getAccount(aid);
|
||||
|
||||
@@ -508,11 +508,11 @@ public class FragmentMessages extends FragmentBase {
|
||||
if (fid < 0) {
|
||||
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified();
|
||||
for (EntityFolder folder : folders)
|
||||
EntityOperation.sync(context, folder.id);
|
||||
EntityOperation.sync(context, folder.id, true);
|
||||
} else {
|
||||
EntityFolder folder = db.folder().getFolder(fid);
|
||||
if (folder != null)
|
||||
EntityOperation.sync(context, folder.id);
|
||||
EntityOperation.sync(context, folder.id, true);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
@@ -49,7 +49,6 @@ import android.widget.TimePicker;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -260,25 +259,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
||||
|
||||
int[] values = getResources().getIntArray(R.array.downloadValues);
|
||||
prefs.edit().putInt("download", values[position]).apply();
|
||||
|
||||
Boolean metered = Helper.isMetered(getContext(), true);
|
||||
if (metered != null && metered)
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
List<EntityFolder> folders = db.folder().getSynchronizingFolders();
|
||||
for (EntityFolder folder : folders)
|
||||
EntityOperation.sync(context, folder.id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
||||
|
||||
}
|
||||
}.execute(FragmentOptions.this, new Bundle(), "download:sync");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -399,21 +399,5 @@ public class FragmentSetup extends FragmentBase {
|
||||
tvPermissionsDone.setTextColor(has ? textColorPrimary : colorWarning);
|
||||
tvPermissionsDone.setCompoundDrawablesWithIntrinsicBounds(has ? check : null, null, null, null);
|
||||
btnPermissions.setEnabled(!has);
|
||||
|
||||
if (has && !init)
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
for (EntityFolder folder : db.folder().getSynchronizingFolders())
|
||||
EntityOperation.sync(context, folder.id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
|
||||
}
|
||||
}.execute(FragmentSetup.this, new Bundle(), "setup:sync");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -581,7 +581,7 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
idler.start();
|
||||
idlers.add(idler);
|
||||
|
||||
EntityOperation.sync(this, folder.id);
|
||||
EntityOperation.sync(this, folder.id, false);
|
||||
} else
|
||||
folders.put(folder, null);
|
||||
|
||||
@@ -722,7 +722,7 @@ public class ServiceSynchronize extends LifecycleService {
|
||||
if (!folders.get(folder).isOpen())
|
||||
throw new FolderClosedException(folders.get(folder));
|
||||
} else
|
||||
EntityOperation.sync(this, folder.id);
|
||||
EntityOperation.sync(this, folder.id, false);
|
||||
|
||||
// Successfully connected: reset back off time
|
||||
backoff = CONNECT_BACKOFF_START;
|
||||
|
||||
Reference in New Issue
Block a user