mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-03 03:19:24 +01:00
Simplified boot/init
This commit is contained in:
@@ -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