Revert "Small improvement"

This reverts commit 2414485689.
This commit is contained in:
M66B 2020-01-06 12:28:15 +01:00
parent ac0dafabff
commit 999669918d
2 changed files with 21 additions and 3 deletions

View File

@ -38,7 +38,7 @@ public class ReceiverAutoStart extends BroadcastReceiver {
ServiceSynchronize.boot(context); ServiceSynchronize.boot(context);
ServiceSend.boot(context); ServiceSend.boot(context);
WorkerCleanup.queue(context); WorkerCleanup.queueOnce(context);
} }
} }
} }

View File

@ -24,7 +24,9 @@ import android.content.SharedPreferences;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.work.Data;
import androidx.work.ExistingPeriodicWorkPolicy; import androidx.work.ExistingPeriodicWorkPolicy;
import androidx.work.OneTimeWorkRequest;
import androidx.work.PeriodicWorkRequest; import androidx.work.PeriodicWorkRequest;
import androidx.work.WorkManager; import androidx.work.WorkManager;
import androidx.work.Worker; import androidx.work.Worker;
@ -103,8 +105,6 @@ public class WorkerCleanup extends Worker {
for (EntityMessage message : db.message().getSnoozed()) for (EntityMessage message : db.message().getSnoozed())
EntityMessage.snooze(context, message.id, message.ui_snoozed); EntityMessage.snooze(context, message.id, message.ui_snoozed);
ServiceSynchronize.reschedule(context);
// Clear last search // Clear last search
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit() prefs.edit()
@ -223,6 +223,24 @@ public class WorkerCleanup extends Worker {
} }
} }
static void queueOnce(Context context) {
try {
Log.i("Queuing " + getName() + " once");
Data data = new Data.Builder().putBoolean("manual", true).build();
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(WorkerCleanup.class)
.setInputData(data)
.build();
WorkManager.getInstance(context).enqueue(workRequest);
Log.i("Queued " + getName() + " once");
} catch (IllegalStateException ex) {
// https://issuetracker.google.com/issues/138465476
Log.w(ex);
}
}
static void cancel(Context context) { static void cancel(Context context) {
try { try {
Log.i("Cancelling " + getName()); Log.i("Cancelling " + getName());