use of com.google.android.material.snackbar.Snackbar in project apps-android-commons by commons-app.
the class MediaDetailPagerFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (getActivity() == null) {
Timber.d("Returning as activity is destroyed!");
return true;
}
Media m = provider.getMediaAtPosition(pager.getCurrentItem());
switch(item.getItemId()) {
case R.id.menu_bookmark_current_image:
boolean bookmarkExists = bookmarkDao.updateBookmark(bookmark);
Snackbar snackbar = bookmarkExists ? Snackbar.make(getView(), R.string.add_bookmark, Snackbar.LENGTH_LONG) : Snackbar.make(getView(), R.string.remove_bookmark, Snackbar.LENGTH_LONG);
snackbar.show();
updateBookmarkState(item);
return true;
case R.id.menu_share_current_image:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, m.getDisplayTitle() + " \n" + m.getPageTitle().getCanonicalUri());
startActivity(Intent.createChooser(shareIntent, "Share image via..."));
return true;
case R.id.menu_browser_current_image:
// View in browser
handleWebUrl(requireContext(), Uri.parse(m.getPageTitle().getMobileUri()));
return true;
case R.id.menu_download_current_image:
// Download
if (!NetworkUtils.isInternetConnectionEstablished(getActivity())) {
ViewUtil.showShortSnackbar(getView(), R.string.no_internet);
return false;
}
DownloadUtils.downloadMedia(getActivity(), m);
return true;
case R.id.menu_set_as_wallpaper:
// Set wallpaper
setWallpaper(m);
return true;
case R.id.menu_set_as_avatar:
// Set avatar
setAvatar(m);
return true;
case R.id.menu_view_user_page:
if (m != null && m.getUser() != null) {
ProfileActivity.startYourself(getActivity(), m.getUser(), !Objects.equals(sessionManager.getUserName(), m.getUser()));
}
default:
return super.onOptionsItemSelected(item);
}
}
use of com.google.android.material.snackbar.Snackbar in project apps-android-commons by commons-app.
the class WikidataItemDetailsActivity method onOptionsItemSelected.
/**
* This method handles the logic on item select in toolbar menu
* Currently only 1 choice is available to open Wikidata item details page in browser
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.browser_actions_menu_items:
String entityId = getIntent().getStringExtra("entityId");
Uri uri = Uri.parse("https://www.wikidata.org/wiki/" + entityId);
Utils.handleWebUrl(this, uri);
return true;
case R.id.menu_bookmark_current_item:
if (getIntent().getStringExtra("fragment") != null) {
compositeDisposable.add(depictModel.getDepictions(getIntent().getStringExtra("entityId")).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(depictedItems -> {
final boolean bookmarkExists = bookmarkItemsDao.updateBookmarkItem(depictedItems.get(0));
final Snackbar snackbar = bookmarkExists ? Snackbar.make(findViewById(R.id.toolbar_layout), R.string.add_bookmark, Snackbar.LENGTH_LONG) : Snackbar.make(findViewById(R.id.toolbar_layout), R.string.remove_bookmark, Snackbar.LENGTH_LONG);
snackbar.show();
updateBookmarkState(item);
}));
} else {
final boolean bookmarkExists = bookmarkItemsDao.updateBookmarkItem(wikidataItem);
final Snackbar snackbar = bookmarkExists ? Snackbar.make(findViewById(R.id.toolbar_layout), R.string.add_bookmark, Snackbar.LENGTH_LONG) : Snackbar.make(findViewById(R.id.toolbar_layout), R.string.remove_bookmark, Snackbar.LENGTH_LONG);
snackbar.show();
updateBookmarkState(item);
}
return true;
case android.R.id.home:
onBackPressed();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
use of com.google.android.material.snackbar.Snackbar in project AmazeFileManager by TeamAmaze.
the class TextEditorActivity method load.
/**
* Initiates loading of file/uri by getting an input stream associated with it on a worker thread
*/
private void load() {
Snackbar.make(scrollView, R.string.loading, Snackbar.LENGTH_SHORT).show();
new ReadFileTask(getContentResolver(), mFile, getExternalCacheDir(), isRootExplorer(), (data) -> {
switch(data.error) {
case ReadFileTask.NORMAL:
cacheFile = data.cachedFile;
mOriginal = data.fileContents;
try {
mInput.setText(data.fileContents);
if (mFile.scheme.equals(FILE) && getExternalCacheDir() != null && mFile.hybridFileParcelable.getPath().contains(getExternalCacheDir().getPath()) && cacheFile == null) {
// file in cache, and not a root temporary file
mInput.setInputType(EditorInfo.TYPE_NULL);
mInput.setSingleLine(false);
mInput.setImeOptions(EditorInfo.IME_FLAG_NO_ENTER_ACTION);
Snackbar snackbar = Snackbar.make(mInput, getResources().getString(R.string.file_read_only), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(getResources().getString(R.string.got_it).toUpperCase(), v -> snackbar.dismiss());
snackbar.show();
}
if (data.fileContents.isEmpty()) {
mInput.setHint(R.string.file_empty);
} else {
mInput.setHint(null);
}
} catch (OutOfMemoryError e) {
Toast.makeText(getApplicationContext(), R.string.error, Toast.LENGTH_SHORT).show();
finish();
}
break;
case ReadFileTask.EXCEPTION_STREAM_NOT_FOUND:
Toast.makeText(getApplicationContext(), R.string.error_file_not_found, Toast.LENGTH_SHORT).show();
finish();
break;
case ReadFileTask.EXCEPTION_IO:
Toast.makeText(getApplicationContext(), R.string.error_io, Toast.LENGTH_SHORT).show();
finish();
break;
case ReadFileTask.EXCEPTION_OOM:
Toast.makeText(getApplicationContext(), R.string.error_file_too_large, Toast.LENGTH_SHORT).show();
finish();
break;
}
}).execute();
}
use of com.google.android.material.snackbar.Snackbar in project AmazeFileManager by TeamAmaze.
the class Utils method showThemedSnackbar.
public static Snackbar showThemedSnackbar(MainActivity mainActivity, CharSequence text, int length, @StringRes int actionTextId, Runnable actionCallback) {
Snackbar snackbar = Snackbar.make(mainActivity.findViewById(R.id.content_frame), text, length).setAction(actionTextId, v -> actionCallback.run());
if (mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
snackbar.getView().setBackgroundColor(mainActivity.getResources().getColor(android.R.color.white));
snackbar.setTextColor(mainActivity.getResources().getColor(android.R.color.black));
}
snackbar.show();
return snackbar;
}
use of com.google.android.material.snackbar.Snackbar in project Slide by ccrama.
the class MainActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final String subreddit = usedArray.get(Reddit.currentPosition);
switch(item.getItemId()) {
case R.id.filter:
filterContent(shouldLoad);
return true;
case R.id.sidebar:
if (!subreddit.equals("all") && !subreddit.equals("frontpage") && !subreddit.contains(".") && !subreddit.contains("+") && !subreddit.contains(".") && !subreddit.contains("/m/")) {
drawerLayout.openDrawer(GravityCompat.END);
} else {
Toast.makeText(this, R.string.sidebar_notfound, Toast.LENGTH_SHORT).show();
}
return true;
case R.id.night:
{
LayoutInflater inflater = getLayoutInflater();
final View dialoglayout = inflater.inflate(R.layout.choosethemesmall, null);
final TextView title = dialoglayout.findViewById(R.id.title);
title.setBackgroundColor(Palette.getDefaultColor());
final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this).setView(dialoglayout);
final Dialog d = builder.show();
back = new ColorPreferences(MainActivity.this).getFontStyle().getThemeType();
if (SettingValues.isNight()) {
dialoglayout.findViewById(R.id.nightmsg).setVisibility(View.VISIBLE);
}
for (final Pair<Integer, Integer> pair : ColorPreferences.themePairList) {
dialoglayout.findViewById(pair.first).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String[] names = new ColorPreferences(MainActivity.this).getFontStyle().getTitle().split("_");
String name = names[names.length - 1];
final String newName = name.replace("(", "");
for (ColorPreferences.Theme theme : ColorPreferences.Theme.values()) {
if (theme.toString().contains(newName) && theme.getThemeType() == pair.second) {
back = theme.getThemeType();
new ColorPreferences(MainActivity.this).setFontStyle(theme);
d.dismiss();
restartTheme();
break;
}
}
}
});
}
}
return true;
case R.id.action_refresh:
if (adapter != null && adapter.getCurrentFragment() != null) {
((SubmissionsView) adapter.getCurrentFragment()).forceRefresh();
}
return true;
case R.id.action_sort:
if (subreddit.equalsIgnoreCase("friends")) {
Snackbar s = Snackbar.make(findViewById(R.id.anchor), getString(R.string.friends_sort_error), Snackbar.LENGTH_SHORT);
LayoutUtils.showSnackbar(s);
} else {
openPopup();
}
return true;
case R.id.search:
MaterialDialog.Builder builder = new MaterialDialog.Builder(this).title(R.string.search_title).alwaysCallInputCallback().input(getString(R.string.search_msg), "", new MaterialDialog.InputCallback() {
@Override
public void onInput(MaterialDialog materialDialog, CharSequence charSequence) {
term = charSequence.toString();
}
});
// Add "search current sub" if it is not frontpage/all/random
if (!subreddit.equalsIgnoreCase("frontpage") && !subreddit.equalsIgnoreCase("all") && !subreddit.contains(".") && !subreddit.contains("/m/") && !subreddit.equalsIgnoreCase("friends") && !subreddit.equalsIgnoreCase("random") && !subreddit.equalsIgnoreCase("popular") && !subreddit.equalsIgnoreCase("myrandom") && !subreddit.equalsIgnoreCase("randnsfw")) {
builder.positiveText(getString(R.string.search_subreddit, subreddit)).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
i.putExtra(Search.EXTRA_SUBREDDIT, subreddit);
Log.v(LogUtil.getTag(), "INTENT SHOWS " + term + " AND " + subreddit);
startActivity(i);
}
});
builder.neutralText(R.string.search_all).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
} else {
builder.positiveText(R.string.search_all).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
Intent i = new Intent(MainActivity.this, Search.class);
i.putExtra(Search.EXTRA_TERM, term);
startActivity(i);
}
});
}
builder.show();
return true;
case R.id.save:
saveOffline(((SubmissionsView) adapter.getCurrentFragment()).posts.posts, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
return true;
case R.id.hide_posts:
((SubmissionsView) adapter.getCurrentFragment()).clearSeenPosts(false);
return true;
case R.id.share:
Reddit.defaultShareText("Slide for Reddit", "https://play.google.com/store/apps/details?id=me.ccrama.redditslide", MainActivity.this);
return true;
case R.id.submit:
{
Intent i = new Intent(MainActivity.this, Submit.class);
i.putExtra(Submit.EXTRA_SUBREDDIT, subreddit);
startActivity(i);
}
return true;
case R.id.gallery:
if (SettingValues.isPro) {
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Gallery.class);
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_gallerymode_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
if (SettingValues.previews > 0) {
b.setNeutralButton(getString(R.string.pro_previews, SettingValues.previews), (dialog, which) -> {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MainActivity.this, Gallery.class);
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Gallery.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
});
}
b.show();
}
return true;
case R.id.action_shadowbox:
if (SettingValues.isPro) {
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(this, Shadowbox.class);
i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
} else {
final AlertDialog.Builder b = ProUtil.proUpgradeMsg(this, R.string.general_shadowbox_ispro).setNegativeButton(R.string.btn_no_thanks, (dialog, whichButton) -> dialog.dismiss());
if (SettingValues.previews > 0) {
b.setNeutralButton("Preview (" + SettingValues.previews + ")", (dialog, which) -> {
SettingValues.prefs.edit().putInt(SettingValues.PREVIEWS_LEFT, SettingValues.previews - 1).apply();
SettingValues.previews = SettingValues.prefs.getInt(SettingValues.PREVIEWS_LEFT, 10);
List<Submission> posts = ((SubmissionsView) adapter.getCurrentFragment()).posts.posts;
if (posts != null && !posts.isEmpty()) {
Intent i2 = new Intent(MainActivity.this, Shadowbox.class);
i2.putExtra(Shadowbox.EXTRA_PAGE, getCurrentPage());
i2.putExtra("offline", ((SubmissionsView) adapter.getCurrentFragment()).posts.cached != null ? ((SubmissionsView) adapter.getCurrentFragment()).posts.cached.time : 0L);
i2.putExtra(Shadowbox.EXTRA_SUBREDDIT, ((SubmissionsView) adapter.getCurrentFragment()).posts.subreddit);
startActivity(i2);
}
});
}
b.show();
}
return true;
default:
return false;
}
}
Aggregations