Simplified boot/init

pull/160/head
M66B 6 years ago
parent 2fda4ebd35
commit 6f47a2e22c

@ -83,7 +83,7 @@ public class ActivityMain extends ActivityBase implements FragmentManager.OnBack
protected void onExecuted(Bundle args, Boolean hasAccounts) { protected void onExecuted(Bundle args, Boolean hasAccounts) {
if (hasAccounts) { if (hasAccounts) {
startActivity(new Intent(ActivityMain.this, ActivityView.class)); startActivity(new Intent(ActivityMain.this, ActivityView.class));
ServiceSynchronize.boot(ActivityMain.this); ServiceSynchronize.init(ActivityMain.this);
ServiceSend.boot(ActivityMain.this); ServiceSend.boot(ActivityMain.this);
} else } else
startActivity(new Intent(ActivityMain.this, ActivitySetup.class)); startActivity(new Intent(ActivityMain.this, ActivitySetup.class));

@ -433,25 +433,21 @@ public class ServiceSend extends ServiceBase {
} }
static void boot(final Context context) { static void boot(final Context context) {
if (!booted) { Thread thread = new Thread(new Runnable() {
booted = true; @Override
public void run() {
Thread thread = new Thread(new Runnable() { try {
@Override DB db = DB.getInstance(context);
public void run() { EntityFolder outbox = db.folder().getOutbox();
try { if (outbox != null && db.operation().getOperations(outbox.id).size() > 0)
DB db = DB.getInstance(context); start(context);
EntityFolder outbox = db.folder().getOutbox(); } catch (Throwable ex) {
if (outbox != null && db.operation().getOperations(outbox.id).size() > 0) Log.e(ex);
start(context);
} catch (Throwable ex) {
Log.e(ex);
}
} }
}, "send:boot"); }
thread.setPriority(THREAD_PRIORITY_BACKGROUND); }, "send:boot");
thread.start(); thread.setPriority(THREAD_PRIORITY_BACKGROUND);
} thread.start();
} }
static void start(Context context) { static void start(Context context) {

@ -1418,51 +1418,51 @@ public class ServiceSynchronize extends ServiceBase {
}; };
static void boot(final Context context) { static void boot(final Context context) {
if (!booted) { Thread thread = new Thread(new Runnable() {
booted = true; @Override
public void run() {
Thread thread = new Thread(new Runnable() { try {
@Override DB db = DB.getInstance(context);
public void run() {
try { // Restore notifications
DB db = DB.getInstance(context); db.message().clearNotifyingMessages();
// Restore notifications // Restore snooze timers
db.message().clearNotifyingMessages(); for (EntityMessage message : db.message().getSnoozed())
EntityMessage.snooze(context, message.id, message.ui_snoozed);
// Restore snooze timers
for (EntityMessage message : db.message().getSnoozed()) // Restore schedule
EntityMessage.snooze(context, message.id, message.ui_snoozed); schedule(context);
// Restore schedule // Conditionally init service
schedule(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean enabled = prefs.getBoolean("enabled", true);
// Conditionally init service int pollInterval = prefs.getInt("poll_interval", 0);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int accounts = db.account().getSynchronizingAccounts().size();
boolean enabled = prefs.getBoolean("enabled", true); if (enabled && pollInterval == 0 && accounts > 0)
int pollInterval = prefs.getInt("poll_interval", 0); init(context);
int accounts = db.account().getSynchronizingAccounts().size(); else {
if (enabled && pollInterval == 0 && accounts > 0) for (EntityAccount account : db.account().getAccounts())
ContextCompat.startForegroundService(context, db.account().setAccountState(account.id, null);
new Intent(context, ServiceSynchronize.class)
.setAction("init")); for (EntityFolder folder : db.folder().getFolders()) {
else { db.folder().setFolderState(folder.id, null);
for (EntityAccount account : db.account().getAccounts()) db.folder().setFolderSyncState(folder.id, null);
db.account().setAccountState(account.id, null);
for (EntityFolder folder : db.folder().getFolders()) {
db.folder().setFolderState(folder.id, null);
db.folder().setFolderSyncState(folder.id, null);
}
} }
} catch (Throwable ex) {
Log.e(ex);
} }
} catch (Throwable ex) {
Log.e(ex);
} }
}, "synchronize:boot"); }
thread.setPriority(THREAD_PRIORITY_BACKGROUND); }, "synchronize:boot");
thread.start(); thread.setPriority(THREAD_PRIORITY_BACKGROUND);
} thread.start();
}
static void init(Context context) {
ContextCompat.startForegroundService(context,
new Intent(context, ServiceSynchronize.class)
.setAction("init"));
} }
private static void schedule(Context context) { private static void schedule(Context context) {

Loading…
Cancel
Save