Delete shortcuts, not

This commit is contained in:
M66B 2022-11-23 21:00:59 +01:00
parent 391f32f5b2
commit 295419b0be
2 changed files with 22 additions and 0 deletions

View File

@ -345,4 +345,24 @@ class Shortcuts {
static void requestPinShortcut(Context context, ShortcutInfoCompat info) {
ShortcutManagerCompat.requestPinShortcut(context.getApplicationContext(), info, null);
}
static void cleanup(Context context) {
if (!BuildConfig.DEBUG)
return;
DB db = DB.getInstance(context);
List<ShortcutInfoCompat> pinned =
ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_PINNED);
for (ShortcutInfoCompat shortcut : pinned) {
String[] id = shortcut.getId().split(":");
if (id.length == 2 && "message".equals(id[0])) {
Intent intent = shortcut.getIntent();
long account = intent.getLongExtra("account", -1L);
String thread = intent.getStringExtra("thread");
List<EntityMessage> messages = db.message().getMessagesByThread(account, thread, null, null);
if (messages != null && messages.size() == 0)
; // Delete the shortcut, if only this was possible ...
}
}
}
}

View File

@ -374,6 +374,8 @@ public class WorkerCleanup extends Worker {
DB.createEmergencyBackup(context);
Shortcuts.cleanup(context);
if (manual) {
// https://www.sqlite.org/lang_vacuum.html
long size = context.getDatabasePath(db.getOpenHelper().getDatabaseName()).length();