mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-03 07:36:31 +02:00
Sync refactoring
This commit is contained in:
@@ -516,6 +516,10 @@ public class EntityOperation {
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid, boolean foreground, boolean force) {
|
||||
sync(context, fid, foreground, force, false);
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid, boolean foreground, boolean force, boolean outbox) {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
EntityFolder folder = db.folder().getFolder(fid);
|
||||
@@ -553,7 +557,10 @@ public class EntityOperation {
|
||||
db.folder().setFolderSyncState(fid, "requested");
|
||||
|
||||
if (folder.account == null) // Outbox
|
||||
ServiceSend.start(context);
|
||||
if (!outbox) {
|
||||
Log.e("outbox");
|
||||
ServiceSend.start(context);
|
||||
}
|
||||
}
|
||||
|
||||
static void subscribe(Context context, long fid, boolean subscribe) {
|
||||
|
||||
@@ -461,8 +461,9 @@ public class FragmentAccounts extends FragmentBase {
|
||||
throw new IllegalStateException(context.getString(R.string.title_no_internet));
|
||||
|
||||
boolean now = true;
|
||||
boolean force = args.getBoolean("force");
|
||||
boolean reload = false;
|
||||
boolean outbox = false;
|
||||
boolean force = args.getBoolean("force");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
@@ -484,7 +485,7 @@ public class FragmentAccounts extends FragmentBase {
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,7 +495,7 @@ public class FragmentAccounts extends FragmentBase {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
if (force)
|
||||
if (force || reload)
|
||||
ServiceSynchronize.reload(context, null, true, "refresh");
|
||||
else
|
||||
ServiceSynchronize.eval(context, "refresh");
|
||||
@@ -502,7 +503,7 @@ public class FragmentAccounts extends FragmentBase {
|
||||
if (outbox)
|
||||
ServiceSend.start(context);
|
||||
|
||||
if (!now && !args.getBoolean("force"))
|
||||
if (!now && !force)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||
|
||||
return null;
|
||||
|
||||
@@ -511,8 +511,9 @@ public class FragmentFolders extends FragmentBase {
|
||||
throw new IllegalStateException(context.getString(R.string.title_no_internet));
|
||||
|
||||
boolean now = true;
|
||||
boolean force = args.getBoolean("force");
|
||||
boolean reload = false;
|
||||
boolean outbox = false;
|
||||
boolean force = args.getBoolean("force");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
@@ -543,7 +544,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -553,7 +554,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
if (force)
|
||||
if (force || reload)
|
||||
ServiceSynchronize.reload(context, null, true, "refresh");
|
||||
else
|
||||
ServiceSynchronize.eval(context, "refresh");
|
||||
@@ -561,7 +562,7 @@ public class FragmentFolders extends FragmentBase {
|
||||
if (outbox)
|
||||
ServiceSend.start(context);
|
||||
|
||||
if (!now && !args.getBoolean("force"))
|
||||
if (!now && !force)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1764,6 +1764,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
throw new IllegalStateException(context.getString(R.string.title_no_internet));
|
||||
|
||||
boolean now = true;
|
||||
boolean reload = false;
|
||||
boolean outbox = false;
|
||||
boolean force = args.getBoolean("force");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
@@ -1782,14 +1784,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
}
|
||||
|
||||
for (EntityFolder folder : folders) {
|
||||
EntityOperation.sync(context, folder.id, true, force);
|
||||
EntityOperation.sync(context, folder.id, true, force, true);
|
||||
|
||||
if (folder.account != null) {
|
||||
if (folder.account == null)
|
||||
outbox = true;
|
||||
else {
|
||||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
reload = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1806,12 +1810,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
if (force)
|
||||
if (force || reload)
|
||||
ServiceSynchronize.reload(context, null, true, "refresh");
|
||||
else
|
||||
ServiceSynchronize.eval(context, "refresh");
|
||||
|
||||
if (!now && !args.getBoolean("force"))
|
||||
if (outbox)
|
||||
ServiceSend.start(context);
|
||||
|
||||
if (!now && !force)
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user