Improved manual sync logic

This commit is contained in:
M66B 2019-02-21 20:54:47 +01:00
parent da34af34f7
commit ec4fa1857d
2 changed files with 24 additions and 11 deletions

View File

@ -305,12 +305,16 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
now = "connected".equals(folder.state);
EntityOperation.sync(db, fid);
} else {
if (!internet || "connected".equals(db.account().getAccount(aid).state)) {
now = internet;
EntityOperation.sync(db, fid);
EntityAccount account = db.account().getAccount(aid);
if (account.ondemand) {
if (internet) {
now = true;
ServiceSynchronize.sync(context, fid);
} else
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
} else {
now = true;
ServiceSynchronize.sync(context, fid);
now = "connected".equals(account.state);
EntityOperation.sync(db, fid);
}
}
@ -330,7 +334,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
@Override
protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalStateException) {
if (ex instanceof IllegalArgumentException)
Snackbar.make(itemView, ex.getMessage(), Snackbar.LENGTH_LONG).show();
else if (ex instanceof IllegalStateException) {
Snackbar snackbar = Snackbar.make(itemView, ex.getMessage(), Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_enable, new View.OnClickListener() {
@Override

View File

@ -513,23 +513,30 @@ public class FragmentMessages extends FragmentBase {
}
boolean now = false;
boolean nointernet = false;
for (EntityFolder folder : folders)
if (folder.account == null) { // outbox
now = "connected".equals(folder.state);
EntityOperation.sync(db, folder.id);
} else {
EntityAccount account = db.account().getAccount(folder.account);
if (!internet || "connected".equals(account.state)) {
now = internet;
EntityOperation.sync(db, folder.id);
if (account.ondemand) {
if (internet) {
now = true;
ServiceSynchronize.sync(context, folder.id);
} else
nointernet = true;
} else {
now = true;
ServiceSynchronize.sync(context, folder.id);
now = "connected".equals(account.state);
EntityOperation.sync(db, folder.id);
}
}
db.setTransactionSuccessful();
if (nointernet)
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
return now;
} finally {
db.endTransaction();