Simplified boot/init

pull/160/head
M66B 5 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) {
if (hasAccounts) {
startActivity(new Intent(ActivityMain.this, ActivityView.class));
ServiceSynchronize.boot(ActivityMain.this);
ServiceSynchronize.init(ActivityMain.this);
ServiceSend.boot(ActivityMain.this);
} else
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));

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

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

Loading…
Cancel
Save