MCPcopy Create free account
hub / github.com/M66B/FairEmail / onExecute

Method onExecute

app/src/main/java/eu/faircode/email/Shortcuts.java:73–114  ·  view source on GitHub ↗
(Context context, Bundle args)

Source from the content-addressed store, hash-verified

71
72 new SimpleTask<List<ShortcutInfoCompat>>() {
73 @Override
74 @TargetApi(Build.VERSION_CODES.N_MR1)
75 protected List<ShortcutInfoCompat> onExecute(Context context, Bundle args) {
76 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
77 boolean enabled = prefs.getBoolean("shortcuts", true);
78
79 ShortcutManager sm = Helper.getSystemService(context, ShortcutManager.class);
80 int app = sm.getMaxShortcutCountPerActivity();
81 int manifest = sm.getManifestShortcuts().size();
82 int count = Math.min(app - manifest, MAX_SHORTCUTS);
83 EntityLog.log(context, "Shortcuts count=" + count +
84 " app=" + app + " manifest=" + manifest + " enabled=" + enabled);
85
86 List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
87 if (!enabled)
88 return shortcuts;
89
90 DB db = DB.getInstance(context);
91 List<String> emails = new ArrayList<>();
92 try (Cursor cursor = db.contact().getFrequentlyContacted()) {
93 int colEmail = cursor.getColumnIndex("email");
94 int colName = cursor.getColumnIndex("name");
95 int colAvatar = cursor.getColumnIndex("avatar");
96 while (shortcuts.size() < count && cursor.moveToNext()) {
97 String email = cursor.getString(colEmail);
98 String name = (cursor.isNull(colName) ? null : cursor.getString(colName));
99 String avatar = (cursor.isNull(colAvatar) ? null : cursor.getString(colAvatar));
100
101 if (emails.contains(email))
102 continue;
103 emails.add(email);
104
105 EntityLog.log(context, "Shortcut email=" + email);
106 ShortcutInfoCompat.Builder builder = getShortcut(context, email, name, avatar);
107 builder.setLongLived(true);
108 builder.setRank(shortcuts.size() + 1);
109 shortcuts.add(builder.build());
110 }
111 }
112
113 return shortcuts;
114 }
115
116 @Override
117 @TargetApi(Build.VERSION_CODES.N_MR1)

Callers

nothing calls this directly

Calls 15

getSystemServiceMethod · 0.95
logMethod · 0.95
getInstanceMethod · 0.95
contactMethod · 0.95
getShortcutMethod · 0.95
getBooleanMethod · 0.80
minMethod · 0.80
moveToNextMethod · 0.80
isNullMethod · 0.80
sizeMethod · 0.65
getColumnIndexMethod · 0.45

Tested by

no test coverage detected