mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-04 06:20:26 +00:00
parent
185efd00ef
commit
e0d259a48e
1 changed files with 32 additions and 52 deletions
|
@ -173,7 +173,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
});
|
});
|
||||||
|
|
||||||
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
|
liveAccountNetworkState.observeForever(new Observer<List<TupleAccountNetworkState>>() {
|
||||||
private boolean init = false;
|
|
||||||
private boolean fts = false;
|
private boolean fts = false;
|
||||||
private Integer lastQuitId = null;
|
private Integer lastQuitId = null;
|
||||||
private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
|
private List<TupleAccountNetworkState> accountStates = new ArrayList<>();
|
||||||
|
@ -192,11 +191,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
coreStates.clear();
|
coreStates.clear();
|
||||||
liveAccountNetworkState.removeObserver(this);
|
liveAccountNetworkState.removeObserver(this);
|
||||||
} else {
|
} else {
|
||||||
if (!init) {
|
|
||||||
init = true;
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
int accounts = 0;
|
int accounts = 0;
|
||||||
int operations = 0;
|
int operations = 0;
|
||||||
boolean runService = false;
|
boolean runService = false;
|
||||||
|
@ -304,52 +298,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
|
||||||
EntityLog.log(ServiceSynchronize.this, "Service reset");
|
|
||||||
|
|
||||||
queue.submit(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
|
||||||
try {
|
|
||||||
db.beginTransaction();
|
|
||||||
|
|
||||||
// Reset accounts
|
|
||||||
for (EntityAccount account : db.account().getAccounts())
|
|
||||||
db.account().setAccountState(account.id, null);
|
|
||||||
|
|
||||||
// reset folders
|
|
||||||
for (EntityFolder folder : db.folder().getFolders()) {
|
|
||||||
db.folder().setFolderState(folder.id, null);
|
|
||||||
db.folder().setFolderSyncState(folder.id, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset operations
|
|
||||||
db.operation().resetOperationStates();
|
|
||||||
|
|
||||||
// Restore notifications
|
|
||||||
db.message().clearNotifyingMessages();
|
|
||||||
|
|
||||||
// Restore snooze timers
|
|
||||||
for (EntityMessage message : db.message().getSnoozed(null))
|
|
||||||
EntityMessage.snooze(ServiceSynchronize.this, message.id, message.ui_snoozed);
|
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Restore schedule
|
|
||||||
schedule(ServiceSynchronize.this);
|
|
||||||
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
Log.e(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void start(final TupleAccountNetworkState accountNetworkState, boolean sync) {
|
private void start(final TupleAccountNetworkState accountNetworkState, boolean sync) {
|
||||||
EntityLog.log(ServiceSynchronize.this, "Service start=" + accountNetworkState);
|
EntityLog.log(ServiceSynchronize.this, "Service start=" + accountNetworkState);
|
||||||
|
|
||||||
|
@ -1802,6 +1750,38 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
|
try {
|
||||||
|
db.beginTransaction();
|
||||||
|
|
||||||
|
// Reset accounts
|
||||||
|
for (EntityAccount account : db.account().getAccounts())
|
||||||
|
db.account().setAccountState(account.id, null);
|
||||||
|
|
||||||
|
// reset folders
|
||||||
|
for (EntityFolder folder : db.folder().getFolders()) {
|
||||||
|
db.folder().setFolderState(folder.id, null);
|
||||||
|
db.folder().setFolderSyncState(folder.id, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset operations
|
||||||
|
db.operation().resetOperationStates();
|
||||||
|
|
||||||
|
// Restore notifications
|
||||||
|
db.message().clearNotifyingMessages();
|
||||||
|
|
||||||
|
// Restore snooze timers
|
||||||
|
for (EntityMessage message : db.message().getSnoozed(null))
|
||||||
|
EntityMessage.snooze(context, message.id, message.ui_snoozed);
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore schedule
|
||||||
|
schedule(context);
|
||||||
|
|
||||||
|
// Init service
|
||||||
int accounts = db.account().getSynchronizingAccounts().size();
|
int accounts = db.account().getSynchronizingAccounts().size();
|
||||||
if (accounts > 0)
|
if (accounts > 0)
|
||||||
eval(context, "boot");
|
eval(context, "boot");
|
||||||
|
|
Loading…
Reference in a new issue