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

View File

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