use of com.amaze.filemanager.ui.theme.AppTheme in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method showEncryptAuthenticateDialog.
public static void showEncryptAuthenticateDialog(final Context c, final Intent intent, final MainActivity main, AppTheme appTheme, final EncryptDecryptUtils.EncryptButtonCallbackInterface encryptButtonCallbackInterface) {
int accentColor = main.getAccent();
MaterialDialog.Builder builder = new MaterialDialog.Builder(c);
builder.title(main.getString(R.string.crypt_encrypt));
View rootView = View.inflate(c, R.layout.dialog_encrypt_authenticate, null);
final TextInputEditText passwordEditText = rootView.findViewById(R.id.edit_text_dialog_encrypt_password);
final TextInputEditText passwordConfirmEditText = rootView.findViewById(R.id.edit_text_dialog_encrypt_password_confirm);
final TextInputEditText encryptSaveAsEditText = rootView.findViewById(R.id.edit_text_encrypt_save_as);
WarnableTextInputLayout textInputLayoutPassword = rootView.findViewById(R.id.til_encrypt_password);
WarnableTextInputLayout textInputLayoutPasswordConfirm = rootView.findViewById(R.id.til_encrypt_password_confirm);
WarnableTextInputLayout textInputLayoutEncryptSaveAs = rootView.findViewById(R.id.til_encrypt_save_as);
HybridFileParcelable intentParcelable = intent.getParcelableExtra(EncryptService.TAG_SOURCE);
encryptSaveAsEditText.setText(intentParcelable.getName(c).concat(CryptUtil.CRYPT_EXTENSION));
textInputLayoutEncryptSaveAs.setHint(intentParcelable.isDirectory() ? c.getString(R.string.encrypt_folder_save_as) : c.getString(R.string.encrypt_file_save_as));
builder.customView(rootView, true).positiveText(c.getString(R.string.ok)).negativeText(c.getString(R.string.cancel)).theme(appTheme.getMaterialDialogTheme()).positiveColor(accentColor).negativeColor(accentColor).autoDismiss(false).onNegative((dialog, which) -> dialog.cancel()).onPositive((dialog, which) -> {
intent.putExtra(EncryptService.TAG_ENCRYPT_TARGET, encryptSaveAsEditText.getText().toString());
try {
encryptButtonCallbackInterface.onButtonPressed(intent, passwordEditText.getText().toString());
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
Toast.makeText(c, c.getString(R.string.crypt_encryption_fail), Toast.LENGTH_LONG).show();
} finally {
dialog.dismiss();
}
});
MaterialDialog dialog = builder.show();
MDButton btnOK = dialog.getActionButton(DialogAction.POSITIVE);
btnOK.setEnabled(false);
rootView.post(() -> ExtensionsKt.openKeyboard(passwordEditText, main.getApplicationContext()));
TextWatcher textWatcher = new SimpleTextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
btnOK.setEnabled(encryptSaveAsEditText.getText().toString().length() > 0 && passwordEditText.getText().toString().length() > 0 && passwordConfirmEditText.getText().toString().length() > 0);
}
};
passwordEditText.addTextChangedListener(textWatcher);
passwordConfirmEditText.addTextChangedListener(textWatcher);
encryptSaveAsEditText.addTextChangedListener(textWatcher);
new WarnableTextInputValidator(c, passwordEditText, textInputLayoutPassword, btnOK, (text) -> {
if (text.length() < 1) {
return new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.field_empty);
}
return new WarnableTextInputValidator.ReturnState();
});
new WarnableTextInputValidator(c, passwordConfirmEditText, textInputLayoutPasswordConfirm, btnOK, (text) -> {
if (!text.equals(passwordEditText.getText().toString())) {
return new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.password_no_match);
}
return new WarnableTextInputValidator.ReturnState();
});
new WarnableTextInputValidator(c, encryptSaveAsEditText, textInputLayoutEncryptSaveAs, btnOK, (text) -> {
if (text.length() < 1) {
return new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.field_empty);
}
if (!text.endsWith(CryptUtil.CRYPT_EXTENSION)) {
return new WarnableTextInputValidator.ReturnState(WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.encrypt_file_must_end_with_aze);
}
return new WarnableTextInputValidator.ReturnState();
});
}
use of com.amaze.filemanager.ui.theme.AppTheme in project AmazeFileManager by TeamAmaze.
the class AppsListFragment method showSortDialog.
public void showSortDialog(AppTheme appTheme) {
final MainActivity mainActivity = (MainActivity) getActivity();
if (mainActivity == null) {
return;
}
WeakReference<AppsListFragment> appsListFragment = new WeakReference<>(this);
int accentColor = mainActivity.getAccent();
String[] sort = getResources().getStringArray(R.array.sortbyApps);
MaterialDialog.Builder builder = new MaterialDialog.Builder(mainActivity).theme(appTheme.getMaterialDialogTheme()).items(sort).itemsCallbackSingleChoice(sortby, (dialog, view, which, text) -> true).negativeText(R.string.ascending).positiveColor(accentColor).positiveText(R.string.descending).negativeColor(accentColor).onNegative((dialog, which) -> {
final AppsListFragment $this = appsListFragment.get();
if ($this == null) {
return;
}
$this.saveAndReload(dialog.getSelectedIndex(), true);
dialog.dismiss();
}).onPositive((dialog, which) -> {
final AppsListFragment $this = appsListFragment.get();
if ($this == null) {
return;
}
$this.saveAndReload(dialog.getSelectedIndex(), false);
dialog.dismiss();
}).title(R.string.sort_by);
builder.build().show();
}
Aggregations