Check internet on manual sync

pull/149/head
M66B 6 years ago
parent e917a53530
commit f746509b7b

@ -294,6 +294,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (!prefs.getBoolean("enabled", true))
throw new IllegalStateException(context.getString(R.string.title_sync_disabled));
boolean internet = (Helper.isMetered(context, true) != null);
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -301,13 +303,14 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
boolean now;
if (aid < 0) {
// outbox
now = ("connected".equals(folder.state));
now = (internet && "connected".equals(folder.state));
EntityOperation.sync(db, fid);
} else {
now = true;
if ("connected".equals(db.account().getAccount(aid).state))
if (!internet || "connected".equals(db.account().getAccount(aid).state)) {
now = internet;
EntityOperation.sync(db, fid);
else {
} else {
now = true;
db.folder().setFolderSyncState(folder.id, "requested");
ServiceSynchronize.sync(context, fid);
}

@ -495,6 +495,8 @@ public class FragmentMessages extends FragmentBase {
if (!prefs.getBoolean("enabled", true))
throw new IllegalStateException(context.getString(R.string.title_sync_disabled));
boolean internet = (Helper.isMetered(context, true) != null);
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -513,14 +515,15 @@ public class FragmentMessages extends FragmentBase {
boolean now = false;
for (EntityFolder folder : folders)
if (folder.account == null) { // outbox
now = ("connected".equals(folder.state));
now = (internet && "connected".equals(folder.state));
EntityOperation.sync(db, folder.id);
} else {
now = true;
EntityAccount account = db.account().getAccount(folder.account);
if ("connected".equals(account.state))
if (!internet || "connected".equals(account.state)) {
now = internet;
EntityOperation.sync(db, folder.id);
else {
} else {
now = true;
db.folder().setFolderSyncState(folder.id, "requested");
ServiceSynchronize.sync(context, folder.id);
}

Loading…
Cancel
Save