Shortcut improvements

pull/176/head
M66B 5 years ago
parent 25ee99529f
commit 508cbf1dc3

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.Manifest; import android.Manifest;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Person;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutInfo;
@ -51,17 +52,17 @@ public class Shortcuts {
@TargetApi(Build.VERSION_CODES.N_MR1) @TargetApi(Build.VERSION_CODES.N_MR1)
protected List<ShortcutInfo> onExecute(Context context, Bundle args) { protected List<ShortcutInfo> onExecute(Context context, Bundle args) {
ShortcutManager sm = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); ShortcutManager sm = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
int count = sm.getMaxShortcutCountPerActivity() - sm.getManifestShortcuts().size(); int app = sm.getMaxShortcutCountPerActivity();
Log.i("Shortcuts count=" + count + int manifest = sm.getManifestShortcuts().size();
" app=" + sm.getMaxShortcutCountPerActivity() + int count = app - manifest;
" manifest=" + sm.getManifestShortcuts().size()); Log.i("Shortcuts count=" + count + " app=" + app + " manifest=" + manifest);
List<ShortcutInfo> shortcuts = new ArrayList<>(); List<ShortcutInfo> shortcuts = new ArrayList<>();
if (count > 0) { if (count > 0) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
List<EntityContact> frequently = db.contact().getFrequentlyContacted(count); List<EntityContact> frequently = db.contact().getFrequentlyContacted(count);
for (EntityContact contact : frequently) { for (EntityContact contact : frequently) {
Intent intent = new Intent(context, ActivityCompose.class); Intent intent = new Intent(context, ActivityMain.class);
intent.setAction(Intent.ACTION_SEND); intent.setAction(Intent.ACTION_SEND);
intent.setData(Uri.parse("mailto:" + contact.email)); intent.setData(Uri.parse("mailto:" + contact.email));
@ -78,13 +79,29 @@ public class Shortcuts {
if (icon == null) if (icon == null)
icon = Icon.createWithResource(context, R.drawable.ic_shortcut_email); icon = Icon.createWithResource(context, R.drawable.ic_shortcut_email);
shortcuts.add( String name = (TextUtils.isEmpty(contact.name) ? contact.email : contact.name);
new ShortcutInfo.Builder(context, Long.toString(contact.id))
//Set<String> categories = new HashSet<>(Arrays.asList(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION));
ShortcutInfo.Builder builder = new ShortcutInfo.Builder(context, Long.toString(contact.id))
.setIcon(icon) .setIcon(icon)
.setRank(shortcuts.size() + 1) .setRank(shortcuts.size() + 1)
.setShortLabel(TextUtils.isEmpty(contact.name) ? contact.email : contact.name) .setShortLabel(name)
.setIntent(intent) .setLongLabel(name)
.build()); //.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());
} }
} }

Loading…
Cancel
Save