Fixed timing issues

pull/169/head
M66B 5 years ago
parent 7f36e108c6
commit 14628c4d22

@ -349,9 +349,10 @@ public class ActivityEML extends ActivityBase {
imessage.setFlag(Flags.Flag.DRAFT, false); imessage.setFlag(Flags.Flag.DRAFT, false);
ifolder.appendMessages(new Message[]{imessage}); ifolder.appendMessages(new Message[]{imessage});
EntityOperation.sync(context, inbox.id, true);
} }
EntityOperation.sync(context, inbox.id, true);
ServiceSynchronize.eval(context, false, "EML");
} }
return account.name + "/" + inbox.name; return account.name + "/" + inbox.name;

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

@ -595,6 +595,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);
return null; return null;
} }

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

@ -2103,6 +2103,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "doubletap");
return null; return null;
} }
@ -2265,6 +2267,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "flag");
return null; return null;
} }
@ -2516,6 +2520,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment");
return null; return null;
} }
@ -2685,6 +2691,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "attachment");
return null; return null;
} }
@ -2928,6 +2936,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "outbox/drafts");
if (message.identity != null) { if (message.identity != null) {
// Identity can be deleted // Identity can be deleted
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
@ -3225,6 +3235,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "seen");
return null; return null;
} }
@ -3361,6 +3373,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "resync");
return null; return null;
} }
@ -3536,6 +3550,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "headers");
return null; return null;
} }
@ -3573,6 +3590,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "raw");
return null; return null;
} }
@ -4524,6 +4544,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "keywords");
return null; return null;
} }
@ -4583,11 +4605,22 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
String keyword = args.getString("keyword"); String keyword = args.getString("keyword");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); try {
if (message == null) db.beginTransaction();
return null;
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, true);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
ServiceSynchronize.eval(context, false, "keyword=" + keyword);
EntityOperation.queue(context, message, EntityOperation.KEYWORD, keyword, true);
return null; return null;
} }

@ -92,27 +92,6 @@ public class EntityOperation {
static final String SEND = "send"; static final String SEND = "send";
static final String EXISTS = "exists"; static final String EXISTS = "exists";
void cleanup(Context context) {
DB db = DB.getInstance(context);
if (message != null)
db.message().setMessageUiHide(message, false);
if (EntityOperation.MOVE.equals(name) ||
EntityOperation.ADD.equals(name) ||
EntityOperation.RAW.equals(name))
try {
JSONArray jargs = new JSONArray(args);
long tmpid = jargs.optLong(2, -1);
if (tmpid < 0)
return;
db.message().deleteMessage(tmpid);
} catch (JSONException ex) {
Log.e(ex);
}
}
static void queue(Context context, EntityMessage message, String name, Object... values) { static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -316,11 +295,6 @@ public class EntityOperation {
crumb.put("message", Long.toString(op.message)); crumb.put("message", Long.toString(op.message));
crumb.put("free", Integer.toString(Log.getFreeMemMb())); crumb.put("free", Integer.toString(Log.getFreeMemMb()));
Log.breadcrumb("queued", crumb); Log.breadcrumb("queued", crumb);
if (SEND.equals(name))
ServiceSend.start(context);
else
ServiceSynchronize.eval(context, false, "operation=" + name);
} }
static void queue(Context context, EntityFolder folder, String name, Object... values) { static void queue(Context context, EntityFolder folder, String name, Object... values) {
@ -379,8 +353,6 @@ public class EntityOperation {
if (folder.account == null) // Outbox if (folder.account == null) // Outbox
ServiceSend.start(context); ServiceSend.start(context);
else if (foreground)
ServiceSynchronize.eval(context, false, "sync folder=" + fid);
} }
static void subscribe(Context context, long fid, boolean subscribe) { static void subscribe(Context context, long fid, boolean subscribe) {
@ -403,6 +375,27 @@ public class EntityOperation {
Log.i("Queued subscribe=" + subscribe + " folder=" + folder); Log.i("Queued subscribe=" + subscribe + " folder=" + folder);
} }
void cleanup(Context context) {
DB db = DB.getInstance(context);
if (message != null)
db.message().setMessageUiHide(message, false);
if (EntityOperation.MOVE.equals(name) ||
EntityOperation.ADD.equals(name) ||
EntityOperation.RAW.equals(name))
try {
JSONArray jargs = new JSONArray(args);
long tmpid = jargs.optLong(2, -1);
if (tmpid < 0)
return;
db.message().deleteMessage(tmpid);
} catch (JSONException ex) {
Log.e(ex);
}
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EntityOperation) { if (obj instanceof EntityOperation) {

@ -313,6 +313,7 @@ public class FragmentAccounts extends FragmentBase {
throw new IllegalStateException(context.getString(R.string.title_no_internet)); throw new IllegalStateException(context.getString(R.string.title_no_internet));
boolean now = true; boolean now = true;
boolean outbox = false;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
@ -323,7 +324,9 @@ public class FragmentAccounts extends FragmentBase {
for (EntityFolder folder : folders) { for (EntityFolder folder : folders) {
EntityOperation.sync(context, folder.id, true); EntityOperation.sync(context, folder.id, true);
if (folder.account != null) { if (folder.account == null)
outbox = true;
else {
EntityAccount account = db.account().getAccount(folder.account); EntityAccount account = db.account().getAccount(folder.account);
if (account != null && !"connected".equals(account.state)) if (account != null && !"connected".equals(account.state))
now = false; now = false;
@ -335,6 +338,10 @@ public class FragmentAccounts extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "refresh/accounts");
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));

@ -3057,6 +3057,8 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "compose/draft");
return data; return data;
} }
@ -3590,6 +3592,8 @@ public class FragmentCompose extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "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));
EntityMessage.snooze(context, draft.id, draft.ui_snoozed); EntityMessage.snooze(context, draft.id, draft.ui_snoozed);

@ -57,7 +57,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import java.util.Collections;
import java.util.List; import java.util.List;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -322,6 +321,7 @@ public class FragmentFolders extends FragmentBase {
throw new IllegalStateException(context.getString(R.string.title_no_internet)); throw new IllegalStateException(context.getString(R.string.title_no_internet));
boolean now = true; boolean now = true;
boolean outbox = false;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
@ -333,25 +333,14 @@ public class FragmentFolders extends FragmentBase {
for (EntityFolder folder : folders) { for (EntityFolder folder : folders) {
EntityOperation.sync(context, folder.id, true); EntityOperation.sync(context, folder.id, true);
if (folder.account != null) { if (folder.account == null)
outbox = true;
else {
EntityAccount account = db.account().getAccount(folder.account); EntityAccount account = db.account().getAccount(folder.account);
if (account != null && !"connected".equals(account.state)) if (account != null && !"connected".equals(account.state))
now = false; now = false;
} }
} }
} else {
// Folder list
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
if (enabled)
ServiceSynchronize.eval(context, true, "refresh folders");
else {
List<EntityFolder> folders = db.folder().getSynchronizingFolders(aid);
if (folders.size() > 0)
Collections.sort(folders, folders.get(0).getComparator(context));
for (EntityFolder folder : folders)
EntityOperation.sync(context, folder.id, false);
}
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();
@ -359,6 +348,10 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, aid > 0, "refresh/folders");
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));
@ -523,6 +516,8 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "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));
@ -613,6 +608,8 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete");
return null; return null;
} }

@ -1192,6 +1192,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "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));
@ -2029,6 +2031,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "seen");
return null; return null;
} }
@ -2162,6 +2166,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "flag");
return null; return null;
} }
@ -3479,6 +3485,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "expand");
return null; return null;
} }
@ -3617,6 +3625,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move");
return null; return null;
} }
@ -3738,6 +3749,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move");
} }
}, "messages:movetimeout"); }, "messages:movetimeout");
thread.setPriority(THREAD_PRIORITY_BACKGROUND); thread.setPriority(THREAD_PRIORITY_BACKGROUND);
@ -4715,6 +4728,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete");
return null; return null;
} }
@ -4750,6 +4765,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete");
return null; return null;
} }
@ -4785,6 +4802,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "move");
return null; return null;
} }
@ -4843,6 +4862,9 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
EntityOperation.queue(context, message, EntityOperation.FLAG, true, color); EntityOperation.queue(context, message, EntityOperation.FLAG, true, color);
} }
}); });
ServiceSynchronize.eval(context, false, "flag");
return null; return null;
} }
@ -4994,6 +5016,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "copy");
return result; return result;
} }
@ -5177,6 +5201,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(context, false, "delete");
return null; return null;
} }

@ -177,7 +177,6 @@ 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("badge", checked).apply(); prefs.edit().putBoolean("badge", checked).apply();
ServiceSynchronize.restart(getContext(), "badge");
} }
}); });
@ -185,7 +184,6 @@ 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("unseen_ignored", checked).apply(); prefs.edit().putBoolean("unseen_ignored", checked).apply();
ServiceSynchronize.restart(getContext(), "unseen_ignored");
} }
}); });

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

@ -461,14 +461,16 @@ public class ServiceSend extends ServiceBase {
EntityOperation.queue(this, orphan, EntityOperation.EXISTS); EntityOperation.queue(this, orphan, EntityOperation.EXISTS);
} }
// Reset identity
db.identity().setIdentityConnected(ident.id, new Date().getTime());
db.identity().setIdentityError(ident.id, null);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
// Reset identity ServiceSynchronize.eval(ServiceSend.this, false, "sent");
db.identity().setIdentityConnected(ident.id, new Date().getTime());
db.identity().setIdentityError(ident.id, null);
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);

@ -104,9 +104,11 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
)); ));
private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList( private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList(
"metered", "roaming", "rlah", "metered", "roaming", "rlah", // force reconnect
"socks_enabled", "socks_proxy", "socks_enabled", "socks_proxy", // force reconnect
"subscribed_only", "debug" "subscribed_only", // force folder sync
"badge", "unseen_ignored", // force update badge/widget
"debug" // force reconnect
)); ));
static final int PI_ALARM = 1; static final int PI_ALARM = 1;
@ -153,6 +155,10 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
postValue(result); postValue(result);
} }
} }
private void postDestroy() {
postValue(null);
}
} }
@Override @Override
@ -198,7 +204,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} }
}); });
liveAccountNetworkState.observe(this, new Observer<List<TupleAccountNetworkState>>() { Log.i("### observe");
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
boolean running = true; boolean running = true;
private List<TupleAccountNetworkState> accountStates = new ArrayList<>(); private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
private Map<TupleAccountNetworkState, Core.State> serviceStates = new Hashtable<>(); private Map<TupleAccountNetworkState, Core.State> serviceStates = new Hashtable<>();
@ -206,69 +213,81 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override @Override
public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) { public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) {
if (!running) { if (accountNetworkStates == null) {
Log.i("### not running"); for (TupleAccountNetworkState prev : serviceStates.keySet())
return; stop(prev);
}
quit();
accountStates.clear();
serviceStates.clear();
liveAccountNetworkState.removeObserver(this);
} else {
if (!running) {
Log.i("### not running");
return;
}
boolean runService = false; int connected = 0;
int pending = 0;
int connected = 0; boolean runService = false;
int pending = 0; for (TupleAccountNetworkState current : accountNetworkStates) {
for (TupleAccountNetworkState current : accountNetworkStates) { if (current.accountState.shouldRun(current.enabled))
if (current.accountState.shouldRun(current.enabled)) runService = true;
runService = true; if ("connected".equals(current.accountState.state))
if ("connected".equals(current.accountState.state)) connected++;
connected++; pending += current.accountState.operations;
pending += current.accountState.operations;
int index = accountStates.indexOf(current);
int index = accountStates.indexOf(current); if (index < 0) {
if (index < 0) { if (current.canRun()) {
if (current.canRun()) { Log.i("### new " + current);
Log.i("### new " + current);
start(current, current.accountState.isEnabled(current.enabled));
}
} else {
TupleAccountNetworkState prev = accountStates.get(index);
accountStates.remove(index);
Core.State state = serviceStates.get(current);
if (state != null)
state.setNetworkState(current.networkState);
// TODO: reload disconnected account on new network available
// !"connected".equals(current.accountState.state))
if (current.reload ||
prev.canRun() != current.canRun() ||
!prev.accountState.equals(current.accountState)) {
Log.i("### changed " + current +
" reload=" + current.reload +
" run prev=" + prev.canRun() +
" run cur=" + current.canRun() +
" changed=" + !prev.accountState.equals(current.accountState));
if (prev.canRun())
stop(prev);
if (current.canRun())
start(current, current.accountState.isEnabled(current.enabled)); start(current, current.accountState.isEnabled(current.enabled));
if (current.accountState.tbd != null) }
delete(current); } else {
TupleAccountNetworkState prev = accountStates.get(index);
accountStates.remove(index);
Core.State state = serviceStates.get(current);
if (state != null)
state.setNetworkState(current.networkState);
// TODO: reload disconnected account on new network available
// !"connected".equals(current.accountState.state))
if (current.reload ||
prev.canRun() != current.canRun() ||
!prev.accountState.equals(current.accountState)) {
Log.i("### changed " + current +
" reload=" + current.reload +
" run prev=" + prev.canRun() +
" run cur=" + current.canRun() +
" changed=" + !prev.accountState.equals(current.accountState));
if (prev.canRun())
stop(prev);
if (current.canRun())
start(current, current.accountState.isEnabled(current.enabled));
if (current.accountState.tbd != null)
delete(current);
}
} }
}
if (current.accountState.tbd == null) if (current.accountState.tbd == null)
accountStates.add(current); accountStates.add(current);
} }
if (accounts != connected || operations != pending) { if (runService) {
accounts = connected; if (accounts != connected || operations != pending) {
operations = pending; accounts = connected;
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); operations = pending;
nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(accounts, operations).build()); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(accounts, operations).build());
}
} else {
running = false;
stopSelf();
}
} }
if (!runService)
exit();
} }
private void start(final TupleAccountNetworkState accountNetworkState, boolean sync) { private void start(final TupleAccountNetworkState accountNetworkState, boolean sync) {
@ -359,14 +378,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}); });
} }
private void exit() { private void quit() {
EntityLog.log(ServiceSynchronize.this, "Service exit"); EntityLog.log(ServiceSynchronize.this, "Service quit");
running = false;
queue.submit(new Runnable() { queue.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
Log.i("### exit"); Log.i("### quit");
DB db = DB.getInstance(ServiceSynchronize.this); DB db = DB.getInstance(ServiceSynchronize.this);
List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC); List<EntityOperation> ops = db.operation().getOperations(EntityOperation.SYNC);
@ -374,7 +392,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
db.folder().setFolderSyncState(op.folder, null); db.folder().setFolderSyncState(op.folder, null);
stopSelf(); stopSelf();
Log.i("### exited"); Log.i("### quited");
} }
}); });
} }
@ -523,7 +541,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
cm.unregisterNetworkCallback(networkCallback); cm.unregisterNetworkCallback(networkCallback);
liveAccountNetworkState.post(new ConnectionHelper.NetworkState()); liveAccountNetworkState.postDestroy();
setUnseen(null); setUnseen(null);
@ -1486,9 +1504,4 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
new Intent(context, ServiceSynchronize.class) new Intent(context, ServiceSynchronize.class)
.setAction("reset")); .setAction("reset"));
} }
static void restart(Context context, String reason) {
context.stopService(new Intent(context, ServiceSynchronize.class));
eval(context, false, reason);
}
} }

@ -194,6 +194,8 @@ public class ServiceUI extends IntentService {
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "move");
} }
private void onMove(long id) { private void onMove(long id) {
@ -215,6 +217,8 @@ public class ServiceUI extends IntentService {
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "move");
} }
private void onReplyDirect(long id, Intent intent) throws IOException { private void onReplyDirect(long id, Intent intent) throws IOException {
@ -273,11 +277,12 @@ public class ServiceUI extends IntentService {
EntityOperation.queue(this, reply, EntityOperation.SEND); EntityOperation.queue(this, reply, EntityOperation.SEND);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
ToastEx.makeText(this, R.string.title_queued, Toast.LENGTH_LONG).show();
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSend.start(ServiceUI.this);
ToastEx.makeText(this, R.string.title_queued, Toast.LENGTH_LONG).show();
} }
private void onFlag(long id) { private void onFlag(long id) {
@ -303,6 +308,8 @@ public class ServiceUI extends IntentService {
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "flag");
} }
private void onSeen(long id) { private void onSeen(long id) {
@ -320,6 +327,8 @@ public class ServiceUI extends IntentService {
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(ServiceUI.this, false, "seen");
} }
private void onSnooze(long id) { private void onSnooze(long id) {
@ -376,6 +385,8 @@ public class ServiceUI extends IntentService {
} }
private void onWakeup(long id) { private void onWakeup(long id) {
EntityFolder folder;
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
try { try {
db.beginTransaction(); db.beginTransaction();
@ -384,7 +395,10 @@ public class ServiceUI extends IntentService {
if (message == null) if (message == null)
return; return;
EntityFolder folder = db.folder().getFolder(message.folder); folder = db.folder().getFolder(message.folder);
if (folder == null)
return;
if (EntityFolder.OUTBOX.equals(folder.type)) { if (EntityFolder.OUTBOX.equals(folder.type)) {
Log.i("Delayed send id=" + message.id); Log.i("Delayed send id=" + message.id);
db.message().setMessageSnoozed(message.id, null); db.message().setMessageSnoozed(message.id, null);
@ -407,6 +421,11 @@ public class ServiceUI extends IntentService {
} finally { } finally {
db.endTransaction(); db.endTransaction();
} }
if (EntityFolder.OUTBOX.equals(folder.type))
ServiceSend.start(ServiceUI.this);
else
ServiceSynchronize.eval(ServiceUI.this, false, "wakeup");
} }
private void onDaily() { private void onDaily() {

@ -63,6 +63,8 @@ public class WorkerPoll extends Worker {
db.endTransaction(); db.endTransaction();
} }
ServiceSynchronize.eval(getApplicationContext(), false, "refresh/poll");
return Result.success(); return Result.success();
} }

Loading…
Cancel
Save