use of com.google.android.material.snackbar.Snackbar in project android by nextcloud.
the class FileDisplayActivity method onPostCreate.
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
if (!PermissionUtil.checkExternalStoragePermission(this)) {
// Check if we should show an explanation
if (PermissionUtil.shouldShowRequestPermissionRationale(this, PermissionUtil.getExternalStoragePermission())) {
// Show explanation to the user and then request permission
Snackbar snackbar = Snackbar.make(binding.rootLayout, R.string.permission_storage_access, Snackbar.LENGTH_INDEFINITE).setAction(R.string.common_ok, v -> PermissionUtil.requestExternalStoragePermission(this));
ThemeSnackbarUtils.colorSnackbar(this, snackbar);
snackbar.show();
} else {
// No explanation needed, request the permission.
PermissionUtil.requestExternalStoragePermission(this);
}
}
if (getIntent().getParcelableExtra(OCFileListFragment.SEARCH_EVENT) != null) {
switchToSearchFragment(savedInstanceState);
int menuId = getIntent().getIntExtra(DRAWER_MENU_ID, -1);
if (menuId != -1) {
setupDrawer(menuId);
}
} else {
createMinFragments(savedInstanceState);
syncAndUpdateFolder(true);
}
upgradeNotificationForInstantUpload();
checkOutdatedServer();
}
use of com.google.android.material.snackbar.Snackbar in project android by nextcloud.
the class FileActivity method onUpdateShareInformation.
private void onUpdateShareInformation(RemoteOperationResult result, @StringRes int defaultError) {
Snackbar snackbar;
FileDetailSharingFragment sharingFragment = getShareFileFragment();
if (result.isSuccess()) {
updateFileFromDB();
if (sharingFragment != null) {
sharingFragment.onUpdateShareInformation(result, getFile());
}
} else if (sharingFragment != null && sharingFragment.getView() != null) {
if (TextUtils.isEmpty(result.getMessage())) {
snackbar = Snackbar.make(sharingFragment.getView(), defaultError, Snackbar.LENGTH_LONG);
} else {
snackbar = Snackbar.make(sharingFragment.getView(), result.getMessage(), Snackbar.LENGTH_LONG);
}
ThemeSnackbarUtils.colorSnackbar(this, snackbar);
snackbar.show();
}
}
use of com.google.android.material.snackbar.Snackbar in project android by nextcloud.
the class FileActivity method onCreateShareViaLinkOperationFinish.
private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation operation, RemoteOperationResult result) {
FileDetailSharingFragment sharingFragment = getShareFileFragment();
if (result.isSuccess()) {
updateFileFromDB();
// if share to user and share via link multiple ocshares are returned,
// therefore filtering for public_link
String link = "";
OCFile file = null;
for (Object object : result.getData()) {
OCShare shareLink = (OCShare) object;
if (TAG_PUBLIC_LINK.equalsIgnoreCase(shareLink.getShareType().name())) {
link = shareLink.getShareLink();
file = getStorageManager().getFileByPath(shareLink.getPath());
break;
}
}
copyAndShareFileLink(this, file, link);
if (sharingFragment != null) {
sharingFragment.onUpdateShareInformation(result, file);
}
} else {
// Detect Failure (403) --> maybe needs password
String password = operation.getPassword();
if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_FORBIDDEN && TextUtils.isEmpty(password) && getCapabilities().getFilesSharingPublicEnabled().isUnknown()) {
// Try with password before giving up; see also ShareFileFragment#OnShareViaLinkListener
if (sharingFragment != null && sharingFragment.isAdded()) {
// only if added to the view hierarchy
sharingFragment.requestPasswordForShareViaLink(true, getCapabilities().getFilesSharingPublicAskForOptionalPassword().isTrue());
}
} else {
if (sharingFragment != null) {
sharingFragment.refreshSharesFromDB();
}
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()), Snackbar.LENGTH_LONG);
ThemeSnackbarUtils.colorSnackbar(this, snackbar);
snackbar.show();
}
}
}
use of com.google.android.material.snackbar.Snackbar in project Taskbar by farmerbb.
the class MainActivity method proceedWithAppLaunch.
@SuppressWarnings("ResultOfMethodCallIgnored")
private void proceedWithAppLaunch(Bundle savedInstanceState) {
try {
setContentView(R.layout.tb_main);
} catch (IllegalStateException e) {
setTheme(R.style.Theme_AppCompat_Light);
setContentView(R.layout.tb_main);
}
if (!U.isLibrary(this)) {
setSupportActionBar(findViewById(R.id.toolbar));
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
}
}
theSwitch = findViewById(R.id.the_switch);
helpButton = findViewById(R.id.help_button);
if (theSwitch != null) {
final SharedPreferences pref = U.getSharedPreferences(this);
theSwitch.setChecked(pref.getBoolean(PREF_TASKBAR_ACTIVE, false));
theSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
if (b) {
if (U.canDrawOverlays(this)) {
boolean firstRun = pref.getBoolean(PREF_FIRST_RUN, true);
startTaskbarService();
if (firstRun)
U.showRecentAppsDialog(this);
} else {
U.showPermissionDialog(this);
compoundButton.setChecked(false);
}
} else
stopTaskbarService();
});
}
if (savedInstanceState == null) {
U.initPrefs(this);
File restoreInProgress = new File(getFilesDir(), "restore_in_progress");
File restoreSuccessful = new File(getFilesDir(), "restore_successful");
if (restoreInProgress.exists() || restoreSuccessful.exists()) {
if (restoreInProgress.exists()) {
U.showToastLong(this, R.string.tb_restore_failed);
restoreInProgress.delete();
}
if (restoreSuccessful.exists()) {
U.showToastLong(this, R.string.tb_restore_successful);
restoreSuccessful.delete();
}
navigateTo(new ManageAppDataFragment());
} else if (!getIntent().hasExtra("theme_change"))
navigateTo(new AboutFragment());
else
navigateTo(new AppearanceFragment());
} else
try {
Fragment oldFragment = getFragmentManager().findFragmentById(R.id.fragmentContainer);
navigateTo(oldFragment.getClass().newInstance());
} catch (IllegalAccessException | InstantiationException ignored) {
}
SharedPreferences pref = U.getSharedPreferences(this);
if (!getPackageName().equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) {
if (!pref.getBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, false)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.tb_settings_imported_successfully).setMessage(R.string.tb_import_dialog_message).setPositiveButton(R.string.tb_action_uninstall, (dialog, which) -> {
pref.edit().putBoolean(PREF_UNINSTALL_DIALOG_SHOWN, true).apply();
try {
startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID)));
} catch (ActivityNotFoundException ignored) {
}
});
if (pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false))
builder.setNegativeButton(R.string.tb_action_dont_show_again, (dialogInterface, i) -> pref.edit().putBoolean(PREF_DONT_SHOW_UNINSTALL_DIALOG, true).apply());
AlertDialog dialog = builder.create();
dialog.show();
dialog.setCancelable(false);
}
if (!pref.getBoolean(PREF_UNINSTALL_DIALOG_SHOWN, false)) {
if (theSwitch != null)
theSwitch.setChecked(false);
SharedPreferences.Editor editor = pref.edit();
String iconPack = pref.getString(PREF_ICON_PACK, BuildConfig.BASE_APPLICATION_ID);
if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) {
editor.putString(PREF_ICON_PACK, getPackageName());
} else {
U.refreshPinnedIcons(this);
}
editor.putBoolean(PREF_FIRST_RUN, true);
editor.apply();
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && !U.isLibrary(this)) {
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
if (shortcutManager.getDynamicShortcuts().size() == 0) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, StartTaskbarActivity.class);
intent.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar").setShortLabel(getString(R.string.tb_start_taskbar)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_start)).setIntent(intent).build();
if (U.enableFreeformModeShortcut(this)) {
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.setClass(this, ShortcutActivity.class);
intent2.putExtra(EXTRA_IS_LAUNCHING_SHORTCUT, true);
ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode").setShortLabel(getString(R.string.tb_pref_header_freeform)).setIcon(Icon.createWithResource(this, R.drawable.tb_shortcut_icon_freeform)).setIntent(intent2).build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2));
} else
shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
}
if (pref.getInt("show_changelog", 0) < latestChangelogVersion && U.isConsumerBuild(this)) {
Snackbar snackbar = Snackbar.make(findViewById(R.id.main_activity_layout), R.string.tb_see_whats_new, Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(R.string.tb_action_view, v -> {
pref.edit().putInt("show_changelog", latestChangelogVersion).apply();
Uri uri = Uri.parse("https://github.com/farmerbb/Taskbar/blob/" + BuildConfig.VERSION_CODE + "/CHANGELOG.md");
try {
DependencyUtils.openChromeCustomTab(this, uri);
} catch (ActivityNotFoundException | IllegalArgumentException ignored) {
}
});
snackbar.show();
}
}
use of com.google.android.material.snackbar.Snackbar in project apps-android-commons by commons-app.
the class ViewUtil method showDismissibleSnackBar.
/**
* A snack bar which has an action button which on click dismisses the snackbar and invokes the
* listener passed
*/
public static void showDismissibleSnackBar(View view, int messageResourceId, int actionButtonResourceId, View.OnClickListener onClickListener) {
if (view.getContext() == null) {
return;
}
ExecutorUtils.uiExecutor().execute(() -> {
Snackbar snackbar = Snackbar.make(view, view.getContext().getString(messageResourceId), Snackbar.LENGTH_INDEFINITE);
snackbar.setAction(view.getContext().getString(actionButtonResourceId), v -> {
snackbar.dismiss();
onClickListener.onClick(v);
});
snackbar.show();
});
}
Aggregations