From 508cbf1dc35a26a3655d26a72b8ccb3dd02254ce Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 14 Mar 2020 18:14:03 +0100 Subject: [PATCH] Shortcut improvements --- .../java/eu/faircode/email/Shortcuts.java | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Shortcuts.java b/app/src/main/java/eu/faircode/email/Shortcuts.java index 395b8a3925..7b24c0cfc2 100644 --- a/app/src/main/java/eu/faircode/email/Shortcuts.java +++ b/app/src/main/java/eu/faircode/email/Shortcuts.java @@ -21,6 +21,7 @@ package eu.faircode.email; import android.Manifest; import android.annotation.TargetApi; +import android.app.Person; import android.content.Context; import android.content.Intent; import android.content.pm.ShortcutInfo; @@ -51,17 +52,17 @@ public class Shortcuts { @TargetApi(Build.VERSION_CODES.N_MR1) protected List onExecute(Context context, Bundle args) { ShortcutManager sm = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); - int count = sm.getMaxShortcutCountPerActivity() - sm.getManifestShortcuts().size(); - Log.i("Shortcuts count=" + count + - " app=" + sm.getMaxShortcutCountPerActivity() + - " manifest=" + sm.getManifestShortcuts().size()); + int app = sm.getMaxShortcutCountPerActivity(); + int manifest = sm.getManifestShortcuts().size(); + int count = app - manifest; + Log.i("Shortcuts count=" + count + " app=" + app + " manifest=" + manifest); List shortcuts = new ArrayList<>(); if (count > 0) { DB db = DB.getInstance(context); List frequently = db.contact().getFrequentlyContacted(count); for (EntityContact contact : frequently) { - Intent intent = new Intent(context, ActivityCompose.class); + Intent intent = new Intent(context, ActivityMain.class); intent.setAction(Intent.ACTION_SEND); intent.setData(Uri.parse("mailto:" + contact.email)); @@ -78,13 +79,29 @@ public class Shortcuts { if (icon == null) icon = Icon.createWithResource(context, R.drawable.ic_shortcut_email); - shortcuts.add( - new ShortcutInfo.Builder(context, Long.toString(contact.id)) - .setIcon(icon) - .setRank(shortcuts.size() + 1) - .setShortLabel(TextUtils.isEmpty(contact.name) ? contact.email : contact.name) - .setIntent(intent) - .build()); + String name = (TextUtils.isEmpty(contact.name) ? contact.email : contact.name); + + //Set categories = new HashSet<>(Arrays.asList(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION)); + + ShortcutInfo.Builder builder = new ShortcutInfo.Builder(context, Long.toString(contact.id)) + .setIcon(icon) + .setRank(shortcuts.size() + 1) + .setShortLabel(name) + .setLongLabel(name) + //.setCategories(categories) + .setIntent(intent); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + Person.Builder person = new Person.Builder() + .setIcon(icon) + .setName(name) + .setImportant(true); + if (contact.avatar != null) + person.setUri(contact.avatar); + builder.setPerson(person.build()); + } + + shortcuts.add(builder.build()); } }