Run start service on foreground

pull/196/head
M66B 5 years ago
parent a2f78423df
commit f7a85deeec

@ -309,11 +309,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "attachment");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);

@ -663,6 +663,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
args.putBoolean("childs", childs); args.putBoolean("childs", childs);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
ServiceSynchronize.eval(context, "refresh/folder");
}
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long fid = args.getLong("folder"); long fid = args.getLong("folder");
@ -704,8 +709,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
db.endTransaction(); db.endTransaction();
} }
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));
@ -836,11 +839,15 @@ 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, "subscribed=" + subscribed);
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "subscribed");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);

@ -134,11 +134,14 @@ public class AdapterImage extends RecyclerView.Adapter<AdapterImage.ViewHolder>
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "attachment");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);

@ -3197,11 +3197,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "doubletap");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "doubletap");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
@ -3394,11 +3397,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "flag");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
@ -3697,11 +3703,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "attachment");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "attachment");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
@ -4463,13 +4472,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "seen");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void ignored) { protected void onExecuted(Bundle args, Void ignored) {
ServiceSynchronize.eval(context, "seen");
long id = args.getLong("id"); long id = args.getLong("id");
TupleMessageEx amessage = getMessage(); TupleMessageEx amessage = getMessage();
if (amessage == null || !amessage.id.equals(id)) if (amessage == null || !amessage.id.equals(id))
@ -4623,13 +4632,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "resync");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "resync");
ToastEx.makeText(context, R.string.title_fetching_again, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_fetching_again, Toast.LENGTH_LONG).show();
} }
@ -4932,11 +4940,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "headers");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "headers");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
@ -5006,13 +5017,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "raw");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "raw");
ToastEx.makeText(context, R.string.title_download_message, Toast.LENGTH_LONG).show(); ToastEx.makeText(context, R.string.title_download_message, Toast.LENGTH_LONG).show();
} }
@ -6895,11 +6905,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "keyword=" + keyword);
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.eval(context, "keyword=" + keyword);
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);

@ -1242,8 +1242,6 @@ public class FragmentAccount extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
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);
nm.cancel("receive:" + account.id, 1); nm.cancel("receive:" + account.id, 1);
@ -1265,8 +1263,10 @@ public class FragmentAccount extends FragmentBase {
fragment.show(getParentFragmentManager(), "account:save"); fragment.show(getParentFragmentManager(), "account:save");
} else { } else {
Context context = getContext(); Context context = getContext();
if (context != null) if (context != null) {
ServiceSynchronize.eval(context, "save account");
WidgetUnified.updateData(context); // Update color stripe WidgetUnified.updateData(context); // Update color stripe
}
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
getParentFragmentManager().popBackStack(); getParentFragmentManager().popBackStack();
@ -1636,13 +1636,15 @@ 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, "delete account");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "delete account");
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getParentFragmentManager().popBackStack(); getParentFragmentManager().popBackStack();
} }

@ -342,6 +342,20 @@ public class FragmentAccounts extends FragmentBase {
@Override @Override
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
swipeRefresh.setRefreshing(false); swipeRefresh.setRefreshing(false);
Context context = getContext();
if (context != null) {
boolean force = args.getBoolean("force");
boolean outbox = args.getBoolean("outbox");
if (force)
ServiceSynchronize.reload(context, null, true, "refresh");
else
ServiceSynchronize.eval(context, "refresh");
if (outbox)
ServiceSend.start(context);
}
} }
@Override @Override
@ -383,13 +397,8 @@ public class FragmentAccounts extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
if (force) args.putBoolean("force", force);
ServiceSynchronize.reload(context, null, true, "refresh"); args.putBoolean("outbox", outbox);
else
ServiceSynchronize.eval(context, "refresh");
if (outbox)
ServiceSend.start(context);
if (!now) if (!now)
throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); throw new IllegalArgumentException(context.getString(R.string.title_no_connection));

@ -4181,8 +4181,6 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "compose/draft");
return data; return data;
} }
@ -4191,6 +4189,10 @@ public class FragmentCompose extends FragmentBase {
final String action = getArguments().getString("action"); final String action = getArguments().getString("action");
Log.i("Loaded draft id=" + data.draft.id + " action=" + action); Log.i("Loaded draft id=" + data.draft.id + " action=" + action);
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "compose/draft");
working = data.draft.id; working = data.draft.id;
encrypt = data.draft.ui_encrypt; encrypt = data.draft.ui_encrypt;
getActivity().invalidateOptionsMenu(); getActivity().invalidateOptionsMenu();
@ -4994,13 +4996,9 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
if (dirty) args.putBoolean("dirty", dirty);
ServiceSynchronize.eval(context, "compose/action");
if (action == R.id.action_send) if (action == R.id.action_send && draft.ui_snoozed != null) {
if (draft.ui_snoozed == null)
ServiceSend.start(context);
else {
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));
EntityMessage.snooze(context, draft.id, draft.ui_snoozed); EntityMessage.snooze(context, draft.id, draft.ui_snoozed);
} }
@ -5013,10 +5011,21 @@ public class FragmentCompose extends FragmentBase {
if (draft == null) if (draft == null)
return; return;
boolean needsEncryption = args.getBoolean("needsEncryption");
int action = args.getInt("action"); int action = args.getInt("action");
boolean dirty = args.getBoolean("dirty");
boolean needsEncryption = args.getBoolean("needsEncryption");
Log.i("Loaded action id=" + draft.id + Log.i("Loaded action id=" + draft.id +
" action=" + getActionName(action) + " encryption=" + needsEncryption); " action=" + getActionName(action) +
" dirty=" + dirty +
" encryption=" + needsEncryption);
Context context = getContext();
if (context != null) {
if (dirty)
ServiceSynchronize.eval(context, "compose/action");
if (action == R.id.action_send && draft.ui_snoozed == null)
ServiceSend.start(context);
}
etTo.setText(MessageHelper.formatAddressesCompose(draft.to)); etTo.setText(MessageHelper.formatAddressesCompose(draft.to));
etCc.setText(MessageHelper.formatAddressesCompose(draft.cc)); etCc.setText(MessageHelper.formatAddressesCompose(draft.cc));

@ -116,11 +116,16 @@ public class FragmentDialogSync extends FragmentDialogBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "folder:months");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "folder:months");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);

@ -631,16 +631,23 @@ public class FragmentFolder extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
if (reload) args.putBoolean("reload", reload);
ServiceSynchronize.reload(context, aid, false, "save folder");
else
ServiceSynchronize.eval(context, "save folder");
return false; return false;
} }
@Override @Override
protected void onExecuted(Bundle args, Boolean dirty) { protected void onExecuted(Bundle args, Boolean dirty) {
Context context = getContext();
if (context != null) {
long aid = args.getLong("account");
boolean reload = args.getBoolean("reload");
if (reload)
ServiceSynchronize.reload(context, aid, false, "save folder");
else
ServiceSynchronize.eval(context, "save folder");
}
if (dirty) { if (dirty) {
Bundle aargs = new Bundle(); Bundle aargs = new Bundle();
aargs.putString("question", getString(R.string.title_ask_save)); aargs.putString("question", getString(R.string.title_ask_save));

@ -321,6 +321,20 @@ public class FragmentFolders extends FragmentBase {
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
Context context = getContext();
if (context != null) {
boolean force = args.getBoolean("force");
boolean outbox = args.getBoolean("outbox");
if (force)
ServiceSynchronize.reload(context, null, true, "refresh");
else
ServiceSynchronize.eval(context, "refresh");
if (outbox)
ServiceSend.start(context);
}
swipeRefresh.setRefreshing(false); swipeRefresh.setRefreshing(false);
} }
@ -375,13 +389,8 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
if (force) args.putBoolean("force", force);
ServiceSynchronize.reload(context, null, true, "refresh"); args.putBoolean("outbox", outbox);
else
ServiceSynchronize.eval(context, "refresh");
if (outbox)
ServiceSend.start(context);
if (!now) if (!now)
throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
@ -691,11 +700,16 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "purge");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "purge");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);

@ -497,16 +497,19 @@ public class FragmentGmail extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "Gmail");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "Gmail");
if (args.getLong("account") < 0) { if (args.getLong("account") < 0) {
finish(); finish();
ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show(); if (context != null)
ToastEx.makeText(context, R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show();
} else { } else {
FragmentReview fragment = new FragmentReview(); FragmentReview fragment = new FragmentReview();
fragment.setArguments(args); fragment.setArguments(args);

@ -1451,6 +1451,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
args.putString("type", type); args.putString("type", type);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
Context context = getContext();
if (context != null) {
boolean force = args.getBoolean("force");
if (force)
ServiceSynchronize.reload(context, null, true, "refresh");
else
ServiceSynchronize.eval(context, "refresh");
}
}
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long fid = args.getLong("folder"); long fid = args.getLong("folder");
@ -1502,10 +1515,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
if (force) args.putBoolean("force", force);
ServiceSynchronize.reload(context, null, true, "refresh");
else
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));
@ -2965,11 +2975,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "seen");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "seen");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);
@ -3104,11 +3119,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "flag");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);
@ -3677,8 +3697,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "outbox/drafts");
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, 1); nm.cancel("send:" + id, 1);
@ -3687,12 +3705,14 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
protected void onExecuted(Bundle args, EntityMessage draft) { protected void onExecuted(Bundle args, EntityMessage draft) {
if (draft != null) if (draft != null) {
ServiceSynchronize.eval(context, "outbox/drafts");
context.startActivity( context.startActivity(
new Intent(context, ActivityCompose.class) new Intent(context, ActivityCompose.class)
.putExtra("action", "edit") .putExtra("action", "edit")
.putExtra("id", draft.id)); .putExtra("id", draft.id));
} }
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
@ -5196,11 +5216,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "expand");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "expand");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);
@ -5395,13 +5420,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "move");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "move");
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
PagedList<TupleMessageEx> messages = adapter.getCurrentList(); PagedList<TupleMessageEx> messages = adapter.getCurrentList();
if (messages != null && result.size() > 0) { if (messages != null && result.size() > 0) {
@ -5492,11 +5519,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "move");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "move");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.e(ex); Log.e(ex);
@ -7166,8 +7198,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "delete");
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("send:" + id, 1); nm.cancel("send:" + id, 1);
@ -7176,6 +7206,10 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "delete");
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
PagedList<TupleMessageEx> messages = adapter.getCurrentList(); PagedList<TupleMessageEx> messages = adapter.getCurrentList();
if (messages != null) { if (messages != null) {
@ -7218,13 +7252,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "delete");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "delete");
if (viewType == AdapterMessage.ViewType.THREAD) { if (viewType == AdapterMessage.ViewType.THREAD) {
long[] ids = args.getLongArray("ids"); long[] ids = args.getLongArray("ids");
PagedList<TupleMessageEx> messages = adapter.getCurrentList(); PagedList<TupleMessageEx> messages = adapter.getCurrentList();
@ -7286,11 +7322,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "junk");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "junk");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
if (ex instanceof IllegalArgumentException) { if (ex instanceof IllegalArgumentException) {
@ -7357,11 +7398,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
}); });
ServiceSynchronize.eval(context, "flag");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "flag");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);
@ -7542,18 +7588,19 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
if (copy)
ServiceSynchronize.eval(context, "copy");
return result; return result;
} }
@Override @Override
protected void onExecuted(Bundle args, ArrayList<MessageTarget> result) { protected void onExecuted(Bundle args, ArrayList<MessageTarget> result) {
boolean copy = args.getBoolean("copy"); boolean copy = args.getBoolean("copy");
if (copy) if (copy) {
ToastEx.makeText(getContext(), R.string.title_completed, Toast.LENGTH_LONG).show(); Context context = getContext();
else if (context != null) {
ServiceSynchronize.eval(context, "copy");
ToastEx.makeText(context, R.string.title_completed, Toast.LENGTH_LONG).show();
}
} else
moveAsk(result, false, !autoclose && onclose == null); moveAsk(result, false, !autoclose && onclose == null);
} }
@ -7866,11 +7913,16 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "purge");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "purge");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex); Log.unexpectedError(getParentFragmentManager(), ex);

@ -608,8 +608,6 @@ public class FragmentOAuth extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "OAuth");
return null; return null;
} }
@ -617,9 +615,14 @@ public class FragmentOAuth extends FragmentBase {
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
pbOAuth.setVisibility(View.GONE); pbOAuth.setVisibility(View.GONE);
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "OAuth");
if (args.getLong("account") < 0) { if (args.getLong("account") < 0) {
finish(); finish();
ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show(); if (context != null)
ToastEx.makeText(context, R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show();
} else { } else {
FragmentReview fragment = new FragmentReview(); FragmentReview fragment = new FragmentReview();
fragment.setArguments(args); fragment.setArguments(args);

@ -229,7 +229,7 @@ public class FragmentOptionsNotifications extends FragmentBase implements Shared
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("background_service", checked).apply(); prefs.edit().putBoolean("background_service", checked).apply();
ServiceSynchronize.eval(getContext(), "background=" + checked); ServiceSynchronize.eval(compoundButton.getContext(), "background=" + checked);
} }
}); });

@ -506,11 +506,16 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.account().setAccountPollExempted(id, exempted); db.account().setAccountPollExempted(id, exempted);
ServiceSynchronize.eval(context, "exempted");
return null; return null;
} }
@Override
protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "exempted");
}
@Override @Override
protected void onException(Bundle args, Throwable ex) { protected void onException(Bundle args, Throwable ex) {
Log.e(ex); Log.e(ex);

@ -611,8 +611,6 @@ public class FragmentPop extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "POP3");
if (!synchronize) { if (!synchronize) {
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel("receive:" + account.id, 1); nm.cancel("receive:" + account.id, 1);
@ -634,8 +632,10 @@ public class FragmentPop extends FragmentBase {
fragment.show(getParentFragmentManager(), "account:save"); fragment.show(getParentFragmentManager(), "account:save");
} else { } else {
Context context = getContext(); Context context = getContext();
if (context != null) if (context != null) {
ServiceSynchronize.eval(context, "POP3");
WidgetUnified.updateData(context); // Update color stripe WidgetUnified.updateData(context); // Update color stripe
}
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
getParentFragmentManager().popBackStack(); getParentFragmentManager().popBackStack();
@ -879,13 +879,15 @@ 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, "delete account");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, Void data) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "delete account");
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
getParentFragmentManager().popBackStack(); getParentFragmentManager().popBackStack();
} }

@ -452,13 +452,15 @@ public class FragmentQuickSetup extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, "quick setup");
return null; return null;
} }
@Override @Override
protected void onExecuted(Bundle args, EmailProvider result) { protected void onExecuted(Bundle args, EmailProvider result) {
Context context = getContext();
if (context != null)
ServiceSynchronize.eval(context, "quick setup");
boolean check = args.getBoolean("check"); boolean check = args.getBoolean("check");
if (check) { if (check) {
tvImap.setText(result == null ? null tvImap.setText(result == null ? null

@ -2023,7 +2023,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
prefs.edit().putInt("poll_interval", OPTIMIZE_POLL_INTERVAL).apply(); prefs.edit().putInt("poll_interval", OPTIMIZE_POLL_INTERVAL).apply();
} else if (pollInterval <= 60 && account.poll_exempted) { } else if (pollInterval <= 60 && account.poll_exempted) {
db.account().setAccountPollExempted(account.id, false); db.account().setAccountPollExempted(account.id, false);
ServiceSynchronize.eval(this, "Optimize=" + reason); ApplicationEx.getMainHandler().post(new Runnable() {
@Override
public void run() {
try {
onEval(new Intent().putExtra("account", account.id));
} catch (Throwable ex) {
Log.e(ex);
}
}
});
} }
} }
@ -2432,13 +2441,14 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static void start(Context context, Intent intent) { private static void start(Context context, Intent intent) {
if (isBackgroundService(context)) if (isBackgroundService(context))
context.startService(intent); context.startService(intent);
else else {
try { try {
ContextCompat.startForegroundService(context, intent); ContextCompat.startForegroundService(context, intent);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(ex); Log.e(ex);
} }
} }
}
private static boolean isBackgroundService(Context context) { private static boolean isBackgroundService(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)

Loading…
Cancel
Save