mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 13:24:52 +02:00
Simplified boot/init
This commit is contained in:
@@ -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);
|
||||
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
DB db = DB.getInstance(context);
|
||||
// Restore notifications
|
||||
db.message().clearNotifyingMessages();
|
||||
|
||||
// Restore notifications
|
||||
db.message().clearNotifyingMessages();
|
||||
// Restore snooze timers
|
||||
for (EntityMessage message : db.message().getSnoozed())
|
||||
EntityMessage.snooze(context, message.id, message.ui_snoozed);
|
||||
|
||||
// Restore snooze timers
|
||||
for (EntityMessage message : db.message().getSnoozed())
|
||||
EntityMessage.snooze(context, message.id, message.ui_snoozed);
|
||||
// Restore schedule
|
||||
schedule(context);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user