use of com.amaze.filemanager.ui.activities.MainActivity 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.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method showArchiveDialog.
public static void showArchiveDialog(final File f, final MainActivity m) {
int accentColor = m.getAccent();
MaterialDialog.Builder mat = new MaterialDialog.Builder(m);
mat.title(R.string.archive).content(R.string.archive_text).positiveText(R.string.extract).negativeText(R.string.view).neutralText(R.string.cancel).positiveColor(accentColor).negativeColor(accentColor).neutralColor(accentColor).onPositive((dialog, which) -> m.mainActivityHelper.extractFile(f)).onNegative((dialog, which) -> m.openCompressed(Uri.fromFile(f).toString()));
if (m.getAppTheme().equals(AppTheme.DARK) || m.getAppTheme().equals(AppTheme.BLACK))
mat.theme(Theme.DARK);
MaterialDialog b = mat.build();
if (!CompressedHelper.isFileExtractable(f.getPath())) {
b.getActionButton(DialogAction.NEGATIVE).setEnabled(false);
}
b.show();
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class CloudSheetFragment method setupDialog.
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
rootView = FragmentSheetCloudBinding.inflate(LayoutInflater.from(requireActivity())).getRoot();
MainActivity activity = (MainActivity) getActivity();
if (activity.getAppTheme().equals(AppTheme.DARK)) {
rootView.setBackgroundColor(Utils.getColor(getContext(), R.color.holo_dark_background));
} else if (activity.getAppTheme().equals(AppTheme.BLACK)) {
rootView.setBackgroundColor(Utils.getColor(getContext(), android.R.color.black));
} else {
rootView.setBackgroundColor(Utils.getColor(getContext(), android.R.color.white));
}
mSmbLayout = rootView.findViewById(R.id.linear_layout_smb);
mScpLayout = rootView.findViewById(R.id.linear_layout_scp);
mBoxLayout = rootView.findViewById(R.id.linear_layout_box);
mDropboxLayout = rootView.findViewById(R.id.linear_layout_dropbox);
mGoogleDriveLayout = rootView.findViewById(R.id.linear_layout_google_drive);
mOnedriveLayout = rootView.findViewById(R.id.linear_layout_onedrive);
mGetCloudLayout = rootView.findViewById(R.id.linear_layout_get_cloud);
if (isCloudProviderAvailable(getContext())) {
mBoxLayout.setVisibility(View.VISIBLE);
mDropboxLayout.setVisibility(View.VISIBLE);
mGoogleDriveLayout.setVisibility(View.VISIBLE);
mOnedriveLayout.setVisibility(View.VISIBLE);
mGetCloudLayout.setVisibility(View.GONE);
}
mSmbLayout.setOnClickListener(this);
mScpLayout.setOnClickListener(this);
mBoxLayout.setOnClickListener(this);
mDropboxLayout.setOnClickListener(this);
mGoogleDriveLayout.setOnClickListener(this);
mOnedriveLayout.setOnClickListener(this);
mGetCloudLayout.setOnClickListener(this);
dialog.setContentView(rootView);
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class MainFragment method onListItemClicked.
/**
* method called when list item is clicked in the adapter
*
* @param isBackButton is it the back button aka '..'
* @param position the position
* @param layoutElementParcelable the list item
* @param imageView the check icon that is to be animated
*/
public void onListItemClicked(boolean isBackButton, int position, LayoutElementParcelable layoutElementParcelable, ImageView imageView) {
if (mainFragmentViewModel.getResults()) {
// check to initialize search results
// if search task is been running, cancel it
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
SearchWorkerFragment fragment = (SearchWorkerFragment) fragmentManager.findFragmentByTag(MainActivity.TAG_ASYNC_HELPER);
if (fragment != null) {
if (fragment.searchAsyncTask.getStatus() == AsyncTask.Status.RUNNING) {
fragment.searchAsyncTask.cancel(true);
}
getActivity().getSupportFragmentManager().beginTransaction().remove(fragment).commit();
}
mainFragmentViewModel.setRetainSearchTask(true);
mainFragmentViewModel.setResults(false);
} else {
mainFragmentViewModel.setRetainSearchTask(false);
MainActivityHelper.SEARCH_TEXT = null;
}
if (getMainActivity().getListItemSelected()) {
if (isBackButton) {
getMainActivity().setListItemSelected(false);
if (getMainActivity().getActionModeHelper().getActionMode() != null) {
getMainActivity().getActionModeHelper().getActionMode().finish();
}
getMainActivity().getActionModeHelper().setActionMode(null);
} else {
// the first {goback} item if back navigation is enabled
adapter.toggleChecked(position, imageView);
}
} else {
if (isBackButton) {
goBackItemClick();
} else {
// hiding search view if visible
if (getMainActivity().getAppbar().getSearchView().isEnabled()) {
getMainActivity().getAppbar().getSearchView().hideSearchView();
}
String path = !layoutElementParcelable.hasSymlink() ? layoutElementParcelable.desc : layoutElementParcelable.symlink;
if (layoutElementParcelable.isDirectory) {
computeScroll();
loadlist(path, false, mainFragmentViewModel.getOpenMode());
} else if (layoutElementParcelable.desc.endsWith(CryptUtil.CRYPT_EXTENSION)) {
// decrypt the file
mainFragmentViewModel.setEncryptOpen(true);
mainFragmentViewModel.initEncryptBaseFile(getActivity().getExternalCacheDir().getPath() + "/" + layoutElementParcelable.generateBaseFile().getName(getMainActivity()).replace(CryptUtil.CRYPT_EXTENSION, ""));
EncryptDecryptUtils.decryptFile(getContext(), getMainActivity(), this, mainFragmentViewModel.getOpenMode(), layoutElementParcelable.generateBaseFile(), getActivity().getExternalCacheDir().getPath(), utilsProvider, true);
} else {
if (getMainActivity().mReturnIntent) {
// are we here to return an intent to another app
returnIntentResults(layoutElementParcelable.generateBaseFile());
} else {
switch(layoutElementParcelable.getMode()) {
case SMB:
launchSMB(layoutElementParcelable.generateBaseFile(), getMainActivity());
break;
case SFTP:
Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
SshClientUtils.launchSftp(layoutElementParcelable.generateBaseFile(), getMainActivity());
break;
case OTG:
FileUtils.openFile(OTGUtil.getDocumentFile(layoutElementParcelable.desc, getContext(), false), (MainActivity) getActivity(), sharedPref);
break;
case DOCUMENT_FILE:
FileUtils.openFile(OTGUtil.getDocumentFile(layoutElementParcelable.desc, SafRootHolder.getUriRoot(), getContext(), OpenMode.DOCUMENT_FILE, false), (MainActivity) getActivity(), sharedPref);
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
Toast.makeText(getContext(), getResources().getString(R.string.please_wait), Toast.LENGTH_LONG).show();
CloudUtil.launchCloud(layoutElementParcelable.generateBaseFile(), mainFragmentViewModel.getOpenMode(), getMainActivity());
break;
default:
FileUtils.openFile(new File(path), (MainActivity) getActivity(), sharedPref);
break;
}
DataUtils.getInstance().addHistoryFile(layoutElementParcelable.desc);
}
}
}
}
}
use of com.amaze.filemanager.ui.activities.MainActivity 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