use of androidx.core.content.pm.ShortcutInfoCompat in project Slide by ccrama.
the class MainActivity method updateSubs.
public void updateSubs(ArrayList<String> subs) {
if (subs.isEmpty() && !NetworkUtil.isConnected(this)) {
findViewById(R.id.toolbar).setVisibility(View.GONE);
d = new MaterialDialog.Builder(MainActivity.this).title(R.string.offline_no_content_found).positiveText(R.string.offline_enter_online).negativeText(R.string.btn_close).cancelable(false).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
finish();
}
}).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
Reddit.appRestart.edit().remove("forceoffline").commit();
Reddit.forceRestart(MainActivity.this, false);
}
}).show();
} else {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if (!getResources().getBoolean(R.bool.isTablet)) {
setDrawerEdge(this, Constants.DRAWER_SWIPE_EDGE, drawerLayout);
} else {
setDrawerEdge(this, Constants.DRAWER_SWIPE_EDGE_TABLET, drawerLayout);
}
if (loader != null) {
header.setVisibility(View.VISIBLE);
setDataSet(subs);
doDrawer();
try {
setDataSet(subs);
} catch (Exception ignored) {
}
loader.finish();
loader = null;
} else {
setDataSet(subs);
doDrawer();
}
}
if (NetworkUtil.isConnected(MainActivity.this)) {
final ArrayList<ShortcutInfoCompat> shortcuts = new ArrayList<>();
if (Authentication.isLoggedIn) {
shortcuts.add(new ShortcutInfoCompat.Builder(this, "inbox").setShortLabel("Inbox").setLongLabel("Open your Inbox").setIcon(getIcon("inbox", R.drawable.ic_email)).setIntent(new Intent(Intent.ACTION_VIEW, null, this, Inbox.class)).build());
shortcuts.add(new ShortcutInfoCompat.Builder(this, "submit").setShortLabel("Submit").setLongLabel("Create new Submission").setIcon(getIcon("submit", R.drawable.ic_edit)).setIntent(new Intent(Intent.ACTION_VIEW, null, this, Submit.class)).build());
int count = 0;
for (String s : subs) {
if (count == 2 || count == subs.size()) {
break;
}
if (!s.contains("/m/")) {
Intent sub = new Intent(Intent.ACTION_VIEW, null, this, SubredditView.class);
sub.putExtra(SubredditView.EXTRA_SUBREDDIT, s);
String frontpage = (s.equalsIgnoreCase("frontpage") ? "" : "/r/") + s;
shortcuts.add(new ShortcutInfoCompat.Builder(this, "sub" + s).setShortLabel(frontpage).setLongLabel(frontpage).setIcon(getIcon(s, R.drawable.ic_bookmark_border)).setIntent(sub).build());
count++;
}
}
} else {
int count = 0;
for (String s : subs) {
if (count == 4 || count == subs.size()) {
break;
}
if (!s.contains("/m/")) {
Intent sub = new Intent(Intent.ACTION_VIEW, null, this, SubredditView.class);
sub.putExtra(SubredditView.EXTRA_SUBREDDIT, s);
String frontpage = (s.equalsIgnoreCase("frontpage") ? "" : "/r/") + s;
new ShortcutInfoCompat.Builder(this, "sub" + s).setShortLabel(frontpage).setLongLabel(frontpage).setIcon(getIcon(s, R.drawable.ic_bookmark_border)).setIntent(sub).build();
count++;
}
}
}
Collections.reverse(shortcuts);
ShortcutManagerCompat.setDynamicShortcuts(this, shortcuts);
}
}
use of androidx.core.content.pm.ShortcutInfoCompat in project MiMangaNu by raulhaag.
the class Shortcuts method addShortCutsX.
public static void addShortCutsX(Manga m, Context ctx) {
if (ShortcutManagerCompat.isRequestPinShortcutSupported(ctx) && m.getImages() != null && !m.getImages().isEmpty()) {
Intent i = new Intent(ctx, ar.rulosoft.mimanganu.MainActivity.class);
i.putExtra("manga_id", m.getId());
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
String icdir = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/";
icdir = icdir + "cache/";
Bitmap bm = decodeFile(new File(icdir + m.getImages().hashCode()));
IconCompat icon = null;
if (bm == null) {
icon = IconCompat.createWithResource(ctx, R.drawable.noimage);
} else {
icon = IconCompat.createWithAdaptiveBitmap(bm);
}
ShortcutInfoCompat shortcutInfo = new ShortcutInfoCompat.Builder(ctx, m.getTitle() + m.getServerId() + Math.random()).setIntent(i).setShortLabel(m.getTitle()).setIcon(icon).build();
ShortcutManagerCompat.requestPinShortcut(ctx, shortcutInfo, null);
} else {
Util.getInstance().toast(ctx, ctx.getString(R.string.device_dont_supported));
}
}
Aggregations