Account specific reload

pull/169/head
M66B 6 years ago
parent 657e1eeaf2
commit c09b82fc85

@ -351,7 +351,7 @@ public class ActivityEML extends ActivityBase {
} }
EntityOperation.sync(context, inbox.id, true); EntityOperation.sync(context, inbox.id, true);
ServiceSynchronize.eval(context, false, "EML"); ServiceSynchronize.eval(context, "EML");
} }
return account.name + "/" + inbox.name; return account.name + "/" + inbox.name;

@ -97,7 +97,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
startActivity(view); startActivity(view);
} }
ServiceSynchronize.eval(ActivityMain.this, false, "main"); ServiceSynchronize.eval(ActivityMain.this, "main");
ServiceSend.watchdog(ActivityMain.this); ServiceSend.watchdog(ActivityMain.this);
} else } else
startActivity(new Intent(ActivityMain.this, ActivitySetup.class)); startActivity(new Intent(ActivityMain.this, ActivitySetup.class));

@ -382,7 +382,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
handleImport(data, this.password); handleImport(data, this.password);
break; break;
case REQUEST_IMPORT_OAUTH: case REQUEST_IMPORT_OAUTH:
ServiceSynchronize.eval(this, false, "import/oauth"); ServiceSynchronize.eval(this, "import/oauth");
break; break;
case REQUEST_IMPORT_CERTIFICATE: case REQUEST_IMPORT_CERTIFICATE:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
@ -1013,7 +1013,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
} }
} }
ServiceSynchronize.eval(ActivitySetup.this, false, "import"); ServiceSynchronize.eval(ActivitySetup.this, "import");
} }
@Override @Override

@ -272,7 +272,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
@Override @Override
protected void onExecuted(Bundle args, Boolean sync) { protected void onExecuted(Bundle args, Boolean sync) {
ServiceSynchronize.eval(context, false, "account sync=" + sync); ServiceSynchronize.eval(context, "account sync=" + sync);
} }
@Override @Override

@ -282,7 +282,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment"); ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }

@ -544,6 +544,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
private void onActionProperty(int property, boolean enabled) { private void onActionProperty(int property, boolean enabled) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", folder.id); args.putLong("id", folder.id);
args.putLong("account", folder.account);
args.putInt("property", property); args.putInt("property", property);
args.putBoolean("enabled", enabled); args.putBoolean("enabled", enabled);
@ -551,6 +552,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
long aid = args.getLong("account");
int property = args.getInt("property"); int property = args.getInt("property");
boolean enabled = args.getBoolean("enabled"); boolean enabled = args.getBoolean("enabled");
@ -567,7 +569,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
break; break;
case R.string.title_synchronize_enabled: case R.string.title_synchronize_enabled:
db.folder().setFolderSynchronize(id, enabled); db.folder().setFolderSynchronize(id, enabled);
ServiceSynchronize.eval(context, true, "folder sync=" + enabled); ServiceSynchronize.reload(context, aid, "folder sync=" + enabled);
break; break;
default: default:
throw new IllegalArgumentException("Unknown folder property=" + property); throw new IllegalArgumentException("Unknown folder property=" + property);
@ -595,7 +597,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
boolean subscribed = args.getBoolean("subscribed"); boolean subscribed = args.getBoolean("subscribed");
EntityOperation.subscribe(context, id, subscribed); EntityOperation.subscribe(context, id, subscribed);
ServiceSynchronize.eval(context, false, "subscribed=" + subscribed); ServiceSynchronize.eval(context, "subscribed=" + subscribed);
return null; return null;
} }

@ -171,7 +171,7 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment"); ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }

@ -2134,7 +2134,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "doubletap"); ServiceSynchronize.eval(context, "doubletap");
return null; return null;
} }
@ -2298,7 +2298,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "flag"); ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@ -2551,7 +2551,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment"); ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }
@ -2722,7 +2722,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment"); ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }
@ -2967,7 +2967,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "outbox/drafts"); ServiceSynchronize.eval(context, "outbox/drafts");
if (message.identity != null) { if (message.identity != null) {
// Identity can be deleted // Identity can be deleted
@ -3266,7 +3266,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "seen"); ServiceSynchronize.eval(context, "seen");
return null; return null;
} }
@ -3404,7 +3404,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "resync"); ServiceSynchronize.eval(context, "resync");
return null; return null;
} }
@ -3582,7 +3582,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "headers"); ServiceSynchronize.eval(context, "headers");
return null; return null;
} }
@ -3622,7 +3622,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "raw"); ServiceSynchronize.eval(context, "raw");
return null; return null;
} }
@ -4575,7 +4575,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "keywords"); ServiceSynchronize.eval(context, "keywords");
return null; return null;
} }
@ -4650,7 +4650,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "keyword=" + keyword); ServiceSynchronize.eval(context, "keyword=" + keyword);
return null; return null;
} }

@ -1098,7 +1098,7 @@ public class FragmentAccount extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "save account"); ServiceSynchronize.eval(context, "save account");
if (!synchronize) { if (!synchronize) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
@ -1426,7 +1426,7 @@ public class FragmentAccount extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.account().setAccountTbd(id); db.account().setAccountTbd(id);
ServiceSynchronize.eval(context, false, "delete account"); ServiceSynchronize.eval(context, "delete account");
return null; return null;
} }

@ -338,7 +338,7 @@ public class FragmentAccounts extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "refresh/accounts"); ServiceSynchronize.eval(context, "refresh/accounts");
if (outbox) if (outbox)
ServiceSend.start(context); ServiceSend.start(context);

@ -3060,7 +3060,7 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "compose/draft"); ServiceSynchronize.eval(context, "compose/draft");
return data; return data;
} }
@ -3595,7 +3595,7 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "compose/action"); ServiceSynchronize.eval(context, "compose/action");
if (action == R.id.action_send && draft.ui_snoozed != null) { if (action == R.id.action_send && draft.ui_snoozed != null) {
Log.i("Delayed send id=" + draft.id + " at " + new Date(draft.ui_snoozed)); Log.i("Delayed send id=" + draft.id + " at " + new Date(draft.ui_snoozed));

@ -505,7 +505,10 @@ public class FragmentFolder extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, reload, "save folder"); if (reload)
ServiceSynchronize.reload(context, aid, "save folder");
else
ServiceSynchronize.eval(context, "save folder");
return false; return false;
} }
@ -546,15 +549,30 @@ public class FragmentFolder extends FragmentBase {
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
EntityFolder folder;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
int count = db.operation().getOperationCount(id, null); try {
db.beginTransaction();
folder = db.folder().getFolder(id);
if (folder == null)
return null;
int count = db.operation().getOperationCount(folder.id, null);
if (count > 0) if (count > 0)
throw new IllegalArgumentException( throw new IllegalArgumentException(
context.getResources().getQuantityString( context.getResources().getQuantityString(
R.plurals.title_notification_operations, count, count)); R.plurals.title_notification_operations, count, count));
db.folder().setFolderTbd(id);
ServiceSynchronize.eval(context, true, "delete folder"); db.folder().setFolderTbd(folder.id);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.reload(context, folder.account, "delete folder");
return null; return null;
} }

@ -348,7 +348,11 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, aid > 0, "refresh/folders"); if (aid < 0)
ServiceSynchronize.eval(context, "refresh/folders");
else
ServiceSynchronize.reload(context, aid, "refresh/folders");
if (outbox) if (outbox)
ServiceSend.start(context); ServiceSend.start(context);
@ -516,7 +520,7 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "refresh/folder"); ServiceSynchronize.eval(context, "refresh/folder");
if (!now) if (!now)
throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
@ -608,7 +612,7 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete"); ServiceSynchronize.eval(context, "delete");
return null; return null;
} }

@ -383,7 +383,7 @@ public class FragmentGmail extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "Gmail"); ServiceSynchronize.eval(context, "Gmail");
return null; return null;
} }

@ -1192,7 +1192,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "refresh"); ServiceSynchronize.eval(context, "refresh");
if (!now) if (!now)
throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
@ -2031,7 +2031,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "seen"); ServiceSynchronize.eval(context, "seen");
return null; return null;
} }
@ -2166,7 +2166,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "flag"); ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@ -3485,7 +3485,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "expand"); ServiceSynchronize.eval(context, "expand");
return null; return null;
} }
@ -3626,7 +3626,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move"); ServiceSynchronize.eval(context, "move");
return null; return null;
} }
@ -3750,7 +3750,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move"); ServiceSynchronize.eval(context, "move");
} }
}, "messages:movetimeout"); }, "messages:movetimeout");
thread.setPriority(THREAD_PRIORITY_BACKGROUND); thread.setPriority(THREAD_PRIORITY_BACKGROUND);
@ -4728,7 +4728,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete"); ServiceSynchronize.eval(context, "delete");
return null; return null;
} }
@ -4765,7 +4765,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete"); ServiceSynchronize.eval(context, "delete");
return null; return null;
} }
@ -4802,7 +4802,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move"); ServiceSynchronize.eval(context, "move");
return null; return null;
} }
@ -4863,7 +4863,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}); });
ServiceSynchronize.eval(context, false, "flag"); ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@ -5016,7 +5016,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "copy"); ServiceSynchronize.eval(context, "copy");
return result; return result;
} }
@ -5201,7 +5201,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete"); ServiceSynchronize.eval(context, "delete");
return null; return null;
} }

@ -106,7 +106,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("enabled", checked).apply(); prefs.edit().putBoolean("enabled", checked).apply();
ServiceSynchronize.eval(getContext(), false, "enabled=" + checked); ServiceSynchronize.eval(getContext(), "enabled=" + checked);
} }
}); });
@ -121,7 +121,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
adapterView.setTag(value); adapterView.setTag(value);
prefs.edit().putInt("poll_interval", value).apply(); prefs.edit().putInt("poll_interval", value).apply();
if (value == 0) if (value == 0)
ServiceSynchronize.eval(getContext(), false, "poll_interval"); ServiceSynchronize.eval(getContext(), "poll_interval");
WorkerPoll.init(getContext()); WorkerPoll.init(getContext());
} }
} }
@ -130,7 +130,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
public void onNothingSelected(AdapterView<?> adapterView) { public void onNothingSelected(AdapterView<?> adapterView) {
adapterView.setTag(null); adapterView.setTag(null);
prefs.edit().remove("poll_interval").apply(); prefs.edit().remove("poll_interval").apply();
ServiceSynchronize.eval(getContext(), false, "poll_interval"); ServiceSynchronize.eval(getContext(), "poll_interval");
WorkerPoll.init(getContext()); WorkerPoll.init(getContext());
} }
}); });
@ -172,7 +172,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_unseen", checked).apply(); prefs.edit().putBoolean("sync_unseen", checked).apply();
ServiceSynchronize.eval(getContext(), true, "sync_unseen=" + checked); ServiceSynchronize.reload(getContext(), -1, "sync_unseen=" + checked);
} }
}); });
@ -180,7 +180,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_flagged", checked).apply(); prefs.edit().putBoolean("sync_flagged", checked).apply();
ServiceSynchronize.eval(getContext(), true, "sync_flagged=" + checked); ServiceSynchronize.reload(getContext(), -1, "sync_flagged=" + checked);
} }
}); });
@ -188,7 +188,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("delete_unseen", checked).apply(); prefs.edit().putBoolean("delete_unseen", checked).apply();
ServiceSynchronize.eval(getContext(), true, "delete_unseen=" + checked); ServiceSynchronize.reload(getContext(), -1, "delete_unseen=" + checked);
} }
}); });
@ -196,7 +196,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_kept", checked).apply(); prefs.edit().putBoolean("sync_kept", checked).apply();
ServiceSynchronize.eval(getContext(), true, "sync_kept=" + checked); ServiceSynchronize.reload(getContext(), -1, "sync_kept=" + checked);
} }
}); });
@ -204,7 +204,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sync_folders", checked).apply(); prefs.edit().putBoolean("sync_folders", checked).apply();
ServiceSynchronize.eval(getContext(), true, "sync_folders=" + checked); ServiceSynchronize.reload(getContext(), -1, "sync_folders=" + checked);
} }
}); });
@ -221,7 +221,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("subscribed_only", checked).apply(); prefs.edit().putBoolean("subscribed_only", checked).apply();
ServiceSynchronize.eval(getContext(), true, "subscribed_only"); ServiceSynchronize.reload(getContext(), -1, "subscribed_only");
} }
}); });

@ -374,7 +374,7 @@ public class FragmentPop extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "save account"); ServiceSynchronize.eval(context, "save account");
if (!synchronize) { if (!synchronize) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
@ -562,7 +562,7 @@ public class FragmentPop extends FragmentBase {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.account().setAccountTbd(id); db.account().setAccountTbd(id);
ServiceSynchronize.eval(context, false, "delete account"); ServiceSynchronize.eval(context, "delete account");
return null; return null;
} }

@ -350,7 +350,7 @@ public class FragmentQuickSetup extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "quick setup"); ServiceSynchronize.eval(context, "quick setup");
return null; return null;
} }

@ -643,7 +643,7 @@ public class Log {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "debuginfo"); ServiceSynchronize.eval(context, "debuginfo");
return draft; return draft;
} }

@ -103,7 +103,7 @@ public class ServiceExternal extends Service {
boolean previous = prefs.getBoolean("enabled", true); boolean previous = prefs.getBoolean("enabled", true);
if (!enabled.equals(previous)) { if (!enabled.equals(previous)) {
prefs.edit().putBoolean("enabled", enabled).apply(); prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.eval(this, false, "external"); ServiceSynchronize.eval(this, "external");
} }
} else { } else {
final Context context = getApplicationContext(); final Context context = getApplicationContext();
@ -114,7 +114,7 @@ public class ServiceExternal extends Service {
EntityAccount account = db.account().getAccount(accountName); EntityAccount account = db.account().getAccount(accountName);
if (account != null) { if (account != null) {
db.account().setAccountSynchronize(account.id, enabled); db.account().setAccountSynchronize(account.id, enabled);
ServiceSynchronize.eval(context, false, "account enabled=" + enabled); ServiceSynchronize.eval(context, "account enabled=" + enabled);
} }
} }
}); });

@ -470,7 +470,7 @@ public class ServiceSend extends ServiceBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceSend.this, false, "sent"); ServiceSynchronize.eval(ServiceSend.this, "sent");
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + message.identity, 1); nm.cancel("send:" + message.identity, 1);

@ -121,25 +121,25 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private ConnectionHelper.NetworkState lastNetworkState = null; private ConnectionHelper.NetworkState lastNetworkState = null;
private List<TupleAccountState> lastAccountStates = null; private List<TupleAccountState> lastAccountStates = null;
private void post(boolean reload) { private void postReload(Long reload) {
post(reload, lastNetworkState, lastAccountStates); post(reload, lastNetworkState, lastAccountStates);
} }
private void post(ConnectionHelper.NetworkState networkState) { private void post(ConnectionHelper.NetworkState networkState) {
lastNetworkState = networkState; lastNetworkState = networkState;
post(false, lastNetworkState, lastAccountStates); post(null, lastNetworkState, lastAccountStates);
} }
private void post(List<TupleAccountState> accountStates) { private void post(List<TupleAccountState> accountStates) {
lastAccountStates = accountStates; lastAccountStates = accountStates;
post(false, lastNetworkState, lastAccountStates); post(null, lastNetworkState, lastAccountStates);
} }
private void postDestroy() { private void postDestroy() {
postValue(null); postValue(null);
} }
private void post(boolean reload, ConnectionHelper.NetworkState networkState, List<TupleAccountState> accountStates) { private void post(Long reload, ConnectionHelper.NetworkState networkState, List<TupleAccountState> accountStates) {
if (Looper.myLooper() == Looper.getMainLooper()) if (Looper.myLooper() == Looper.getMainLooper())
_post(reload, networkState, accountStates); _post(reload, networkState, accountStates);
else { else {
@ -154,7 +154,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
} }
private void _post(boolean reload, ConnectionHelper.NetworkState networkState, List<TupleAccountState> accountStates) { private void _post(Long reload, ConnectionHelper.NetworkState networkState, List<TupleAccountState> accountStates) {
if (networkState != null && accountStates != null) { if (networkState != null && accountStates != null) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
boolean enabled = prefs.getBoolean("enabled", true); boolean enabled = prefs.getBoolean("enabled", true);
@ -168,7 +168,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
for (TupleAccountState accountState : accountStates) for (TupleAccountState accountState : accountStates)
result.add(new TupleAccountNetworkState( result.add(new TupleAccountNetworkState(
enabled && pollInterval == 0 && scheduled, enabled && pollInterval == 0 && scheduled,
reload, reload != null && (reload < 0 || accountState.id.equals(reload)),
networkState, networkState,
accountState)); accountState));
postValue(result); postValue(result);
@ -531,9 +531,9 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (PREF_EVAL.contains(key)) if (PREF_EVAL.contains(key))
liveAccountNetworkState.post(false); liveAccountNetworkState.postReload(null);
else if (PREF_RELOAD.contains(key)) else if (PREF_RELOAD.contains(key))
liveAccountNetworkState.post(true); liveAccountNetworkState.postReload(-1L);
} }
@Override @Override
@ -601,17 +601,19 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
try { try {
switch (action) { switch (action) {
case "eval": case "eval":
boolean reload = intent.getBooleanExtra("reload", false); Long reload = null;
liveAccountNetworkState.post(reload); if (intent.hasExtra("reload"))
reload = intent.getLongExtra("reload", -1);
liveAccountNetworkState.postReload(reload);
break; break;
case "alarm": case "alarm":
schedule(this); schedule(this);
eval(this, false, "alarm"); eval(this, "alarm");
break; break;
case "reset": case "reset":
eval(this, true, "reset"); reload(this, -1, "reset");
break; break;
default: default:
@ -805,7 +807,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
String name = e.getFolder().getFullName(); String name = e.getFolder().getFullName();
Log.i("Folder created=" + name); Log.i("Folder created=" + name);
if (db.folder().getFolderByName(account.id, name) == null) if (db.folder().getFolderByName(account.id, name) == null)
eval(ServiceSynchronize.this, true, "folder created"); reload(ServiceSynchronize.this, account.id, "folder created");
} finally { } finally {
wlFolder.release(); wlFolder.release();
} }
@ -823,7 +825,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
int count = db.folder().renameFolder(account.id, old, name); int count = db.folder().renameFolder(account.id, old, name);
Log.i("Renamed to " + name + " count=" + count); Log.i("Renamed to " + name + " count=" + count);
if (count == 0) if (count == 0)
eval(ServiceSynchronize.this, true, "folder renamed"); reload(ServiceSynchronize.this, account.id, "folder renamed");
} finally { } finally {
wlFolder.release(); wlFolder.release();
} }
@ -837,7 +839,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
String name = e.getFolder().getFullName(); String name = e.getFolder().getFullName();
Log.i("Folder deleted=" + name); Log.i("Folder deleted=" + name);
if (db.folder().getFolderByName(account.id, name) != null) if (db.folder().getFolderByName(account.id, name) != null)
eval(ServiceSynchronize.this, true, "folder deleted"); reload(ServiceSynchronize.this, account.id, "folder deleted");
} finally { } finally {
wlFolder.release(); wlFolder.release();
} }
@ -1381,7 +1383,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Conditionally init service // Conditionally init service
int accounts = db.account().getSynchronizingAccounts().size(); int accounts = db.account().getSynchronizingAccounts().size();
if (accounts > 0) if (accounts > 0)
eval(context, false, "boot"); eval(context, "boot");
else { else {
for (EntityAccount account : db.account().getAccounts()) for (EntityAccount account : db.account().getAccounts())
db.account().setAccountState(account.id, null); db.account().setAccountState(account.id, null);
@ -1473,11 +1475,18 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
return new long[]{start, end}; return new long[]{start, end};
} }
static void eval(Context context, boolean reload, String reason) { static void eval(Context context, String reason) {
ContextCompat.startForegroundService(context, ContextCompat.startForegroundService(context,
new Intent(context, ServiceSynchronize.class) new Intent(context, ServiceSynchronize.class)
.setAction("eval") .setAction("eval")
.putExtra("reload", reload) .putExtra("reason", reason));
}
static void reload(Context context, long account, String reason) {
ContextCompat.startForegroundService(context,
new Intent(context, ServiceSynchronize.class)
.setAction("eval")
.putExtra("reload", account)
.putExtra("reason", reason)); .putExtra("reason", reason));
} }

@ -69,6 +69,6 @@ public class ServiceTileSynchronize extends TileService implements SharedPrefere
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean enabled = !prefs.getBoolean("enabled", true); boolean enabled = !prefs.getBoolean("enabled", true);
prefs.edit().putBoolean("enabled", enabled).apply(); prefs.edit().putBoolean("enabled", enabled).apply();
ServiceSynchronize.eval(this, false, "tile=" + enabled); ServiceSynchronize.eval(this, "tile=" + enabled);
} }
} }

@ -195,7 +195,7 @@ public class ServiceUI extends IntentService {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "move"); ServiceSynchronize.eval(ServiceUI.this, "move");
} }
private void onMove(long id) { private void onMove(long id) {
@ -218,7 +218,7 @@ public class ServiceUI extends IntentService {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "move"); ServiceSynchronize.eval(ServiceUI.this, "move");
} }
private void onReplyDirect(long id, Intent intent) throws IOException { private void onReplyDirect(long id, Intent intent) throws IOException {
@ -309,7 +309,7 @@ public class ServiceUI extends IntentService {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "flag"); ServiceSynchronize.eval(ServiceUI.this, "flag");
} }
private void onSeen(long id) { private void onSeen(long id) {
@ -328,7 +328,7 @@ public class ServiceUI extends IntentService {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "seen"); ServiceSynchronize.eval(ServiceUI.this, "seen");
} }
private void onSnooze(long id) { private void onSnooze(long id) {
@ -425,7 +425,7 @@ public class ServiceUI extends IntentService {
if (EntityFolder.OUTBOX.equals(folder.type)) if (EntityFolder.OUTBOX.equals(folder.type))
ServiceSend.start(ServiceUI.this); ServiceSend.start(ServiceUI.this);
else else
ServiceSynchronize.eval(ServiceUI.this, false, "wakeup"); ServiceSynchronize.eval(ServiceUI.this, "wakeup");
} }
private void onDaily() { private void onDaily() {

@ -95,7 +95,7 @@ public class WorkerPoll extends Worker {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "refresh/poll"); ServiceSynchronize.eval(context, "refresh/poll");
} }
private static String getName() { private static String getName() {

@ -44,7 +44,7 @@ public class WorkerWatchdog extends Worker {
@Override @Override
public Result doWork() { public Result doWork() {
Log.i("Running " + getName()); Log.i("Running " + getName());
ServiceSynchronize.eval(getApplicationContext(), false, "watchdog"); ServiceSynchronize.eval(getApplicationContext(), "watchdog");
ServiceSend.watchdog(getApplicationContext()); ServiceSend.watchdog(getApplicationContext());
return Result.success(); return Result.success();
} }

Loading…
Cancel
Save