Source:
<code>public static void addShortcut(@Nullable final Context context, @NonNull final ChannelInfoItem data) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1 || context == null) { return; } final ShortcutManager manager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); if (manager == null) { return; } Single.fromCallable(() -> getIcon(context, data.getThumbnailUrl(), manager.getIconMaxWidth(), manager.getIconMaxHeight(), R.drawable.ic_newpipe_triangle_white)) <START> .subscribeOn(Schedulers.computation()) <END> .map(icon -> new ShortcutInfo.Builder(context, getShortcutId(data)) .setShortLabel(data.getName()) .setLongLabel(data.getName()) .setIcon(icon.toIcon()) .setIntent(createIntent(context, data))) .observeOn(AndroidSchedulers.mainThread()) .subscribe(builder -> { final String id = getShortcutId(data); final List<ShortcutInfo> shortcuts = manager.getDynamicShortcuts(); final int limit = manager.getMaxShortcutCountPerActivity(); for (int i = 0; i < shortcuts.size(); i++) { final ShortcutInfo shortcut = shortcuts.get(i); if (id.equals(shortcut.getId())) { builder.setRank(shortcut.getRank() + 1); manager.updateShortcuts(Collections.singletonList(builder.build())); return; } } builder.setRank(1); if (!shortcuts.isEmpty() && shortcuts.size() >= limit) { manager.removeDynamicShortcuts(Collections.singletonList(shortcuts.get(shortcuts.size() - 1).getId())); } manager.addDynamicShortcuts(Collections.singletonList(builder.build())); }, e -> { if (BuildConfig.DEBUG) { e.printStackTrace(); } }); }</code><technical_language>computation scheduler for blocking operations, fetching transforming bitmaps</technical_language>

Target:
public static Disposable addShortcut(@Nullable final Context context, @NonNull final ChannelInfoItem data) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1 || context == null) { return null; } final ShortcutManager manager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE); if (manager == null) { return null; } return Single.fromCallable(() -> getIcon(context, data.getThumbnailUrl(), manager.getIconMaxWidth(), manager.getIconMaxHeight(), R.drawable.ic_newpipe_triangle_white)) .subscribeOn(Schedulers.io()) .map(icon -> new ShortcutInfo.Builder(context, getShortcutId(data.getUrl())) .setShortLabel(data.getName()) .setLongLabel(data.getName()) .setIcon(icon.toIcon()) .setIntent(createIntent(context, data))) .observeOn(AndroidSchedulers.mainThread()) .subscribe(builder -> { final String id = getShortcutId(data.getUrl()); final List<ShortcutInfo> shortcuts = manager.getDynamicShortcuts(); final int limit = manager.getMaxShortcutCountPerActivity(); for (int i = 0; i < shortcuts.size(); i++) { final ShortcutInfo shortcut = shortcuts.get(i); if (id.equals(shortcut.getId())) { builder.setRank(shortcut.getRank() + 1); manager.updateShortcuts(Collections.singletonList(builder.build())); return; } } builder.setRank(1); if (!shortcuts.isEmpty() && shortcuts.size() >= limit) { manager.removeDynamicShortcuts(Collections.singletonList(shortcuts.get(shortcuts.size() - 1).getId())); } manager.addDynamicShortcuts(Collections.singletonList(builder.build())); }, e -> { if (BuildConfig.DEBUG) { e.printStackTrace(); } }); }