From 36e68347d0734f8b206c96314378528202caa075 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Jan 2020 12:07:45 +0100 Subject: [PATCH] Simplified starting FTS indexing --- .../main/java/eu/faircode/email/AdapterMessage.java | 1 + app/src/main/java/eu/faircode/email/Core.java | 4 ---- app/src/main/java/eu/faircode/email/DaoMessage.java | 8 ++++++-- .../java/eu/faircode/email/EntityOperation.java | 9 +++------ .../java/eu/faircode/email/FragmentCompose.java | 1 + .../java/eu/faircode/email/ServiceSynchronize.java | 8 ++++++++ app/src/main/java/eu/faircode/email/ServiceUI.java | 1 + app/src/main/java/eu/faircode/email/WorkerFts.java | 13 ++++++++----- 8 files changed, 28 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 62f1a9f617..a34e3f24a4 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -3042,6 +3042,7 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + private boolean fts = false; private List accountStates = new ArrayList<>(); private ExecutorService queue = Helper.getBackgroundExecutor(1, "service"); @@ -258,6 +259,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (lastAccounts != accounts || lastOperations != operations) { lastAccounts = accounts; lastOperations = operations; + if (operations == 0) { + fts = true; + WorkerFts.init(ServiceSynchronize.this, false); + } else if (fts) { + fts = false; + WorkerFts.cancel(ServiceSynchronize.this); + } NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(lastAccounts, lastOperations).build()); } diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java index 9d69dc1757..ab03e5e99c 100644 --- a/app/src/main/java/eu/faircode/email/ServiceUI.java +++ b/app/src/main/java/eu/faircode/email/ServiceUI.java @@ -419,6 +419,7 @@ public class ServiceUI extends IntentService { // A new message ID is needed for a new (wearable) notification db.message().deleteMessage(id); message.id = null; + message.fts = false; message.id = db.message().insertMessage(message); if (message.content) EntityMessage.getFile(this, id) diff --git a/app/src/main/java/eu/faircode/email/WorkerFts.java b/app/src/main/java/eu/faircode/email/WorkerFts.java index 9fdfea0cda..3e69f9f525 100644 --- a/app/src/main/java/eu/faircode/email/WorkerFts.java +++ b/app/src/main/java/eu/faircode/email/WorkerFts.java @@ -96,17 +96,20 @@ public class WorkerFts extends Worker { .enqueueUniqueWork(getName(), ExistingWorkPolicy.REPLACE, workRequest); Log.i("Queued " + getName()); - } else if (immediately) { - Log.i("Cancelling " + getName()); - WorkManager.getInstance(context).cancelUniqueWork(getName()); - Log.i("Cancelled " + getName()); - } + } else if (immediately) + cancel(context); } catch (IllegalStateException ex) { // https://issuetracker.google.com/issues/138465476 Log.w(ex); } } + static void cancel(Context context) { + Log.i("Cancelling " + getName()); + WorkManager.getInstance(context).cancelUniqueWork(getName()); + Log.i("Cancelled " + getName()); + } + private static String getName() { return WorkerFts.class.getSimpleName(); }