Search in sources :

Example 6 with AppTheme

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();
    });
}
Also used : WarnableTextInputLayout(com.amaze.filemanager.ui.views.WarnableTextInputLayout) RequiresApi(androidx.annotation.RequiresApi) LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) MainFragment(com.amaze.filemanager.ui.fragments.MainFragment) FileProperties(com.amaze.filemanager.filesystem.FileProperties) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) SortHandler(com.amaze.filemanager.database.SortHandler) MDButton(com.afollestad.materialdialogs.internal.MDButton) CompressedHelper(com.amaze.filemanager.filesystem.compressed.CompressedHelper) GeneralSecurityException(java.security.GeneralSecurityException) RootHelper(com.amaze.filemanager.filesystem.RootHelper) CheckBox(android.widget.CheckBox) View(android.view.View) Button(android.widget.Button) DialogSigninWithGoogleBinding(com.amaze.filemanager.databinding.DialogSigninWithGoogleBinding) PieChart(com.github.mikephil.charting.charts.PieChart) Log(android.util.Log) PieData(com.github.mikephil.charting.data.PieData) LoadFolderSpaceDataTask(com.amaze.filemanager.asynchronous.asynctasks.LoadFolderSpaceDataTask) M(android.os.Build.VERSION_CODES.M) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) AsyncTask(android.os.AsyncTask) Entry(com.github.mikephil.charting.data.Entry) Set(java.util.Set) InputType(android.text.InputType) ExtensionsKt(com.amaze.filemanager.ui.ExtensionsKt) FingerprintManager(android.hardware.fingerprint.FingerprintManager) FileUtils(com.amaze.filemanager.filesystem.files.FileUtils) AppCompatButton(androidx.appcompat.widget.AppCompatButton) Executors(java.util.concurrent.Executors) EncryptDecryptUtils(com.amaze.filemanager.filesystem.files.EncryptDecryptUtils) Objects(java.util.Objects) FileUtils.toHybridFileArrayList(com.amaze.filemanager.filesystem.files.FileUtils.toHybridFileArrayList) List(java.util.List) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) HiddenAdapter(com.amaze.filemanager.adapters.HiddenAdapter) PREFERENCE_SORTBY_ONLY_THIS(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_SORTBY_ONLY_THIS) R(com.amaze.filemanager.R) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) CountItemsOrAndSizeTask(com.amaze.filemanager.asynchronous.asynctasks.CountItemsOrAndSizeTask) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) AppConfig(com.amaze.filemanager.application.AppConfig) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) Legend(com.github.mikephil.charting.components.Legend) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) TextInputEditText(com.google.android.material.textfield.TextInputEditText) IValueFormatter(com.github.mikephil.charting.formatter.IValueFormatter) HybridFile(com.amaze.filemanager.filesystem.HybridFile) FingerprintHandler(com.amaze.filemanager.utils.FingerprintHandler) Intent(android.content.Intent) OpenMode(com.amaze.filemanager.file_operations.filesystem.OpenMode) Sort(com.amaze.filemanager.database.models.explorer.Sort) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WarnableTextInputLayout(com.amaze.filemanager.ui.views.WarnableTextInputLayout) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) PieDataSet(com.github.mikephil.charting.data.PieDataSet) ShellNotRunningException(com.amaze.filemanager.file_operations.exceptions.ShellNotRunningException) PreferencesConstants(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants) DataUtils(com.amaze.filemanager.utils.DataUtils) Toast(android.widget.Toast) Build(android.os.Build) ExecutorService(java.util.concurrent.ExecutorService) Formatter(android.text.format.Formatter) GenerateHashesTask(com.amaze.filemanager.asynchronous.asynctasks.GenerateHashesTask) SpannableString(android.text.SpannableString) LayoutInflater(android.view.LayoutInflater) IOException(java.io.IOException) DialogAction(com.afollestad.materialdialogs.DialogAction) TextUtils(android.text.TextUtils) ChangeFilePermissionsCommand(com.amaze.filemanager.filesystem.root.ChangeFilePermissionsCommand) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator) File(java.io.File) Theme(com.afollestad.materialdialogs.Theme) Color(android.graphics.Color) Utils(com.amaze.filemanager.utils.Utils) SharedPreferences(android.content.SharedPreferences) CryptUtil(com.amaze.filemanager.filesystem.files.CryptUtil) ViewPortHandler(com.github.mikephil.charting.utils.ViewPortHandler) EncryptService(com.amaze.filemanager.asynchronous.services.EncryptService) ThemedActivity(com.amaze.filemanager.ui.activities.superclasses.ThemedActivity) PreferenceManager(androidx.preference.PreferenceManager) PieEntry(com.github.mikephil.charting.data.PieEntry) Collections(java.util.Collections) EditText(android.widget.EditText) MDButton(com.afollestad.materialdialogs.internal.MDButton) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) TextInputEditText(com.google.android.material.textfield.TextInputEditText) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) TextWatcher(android.text.TextWatcher) WarnableTextInputValidator(com.amaze.filemanager.ui.views.WarnableTextInputValidator)

Example 7 with AppTheme

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();
}
Also used : GlideConstants(com.amaze.filemanager.utils.GlideConstants) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppHolder(com.amaze.filemanager.adapters.holders.AppHolder) ColorDrawable(android.graphics.drawable.ColorDrawable) AppDataParcelable(com.amaze.filemanager.adapters.data.AppDataParcelable) LoaderManager(androidx.loader.app.LoaderManager) MainActivity(com.amaze.filemanager.ui.activities.MainActivity) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) WeakReference(java.lang.ref.WeakReference) AppsRecyclerAdapter(com.amaze.filemanager.adapters.AppsRecyclerAdapter) Log(android.util.Log) Loader(androidx.loader.content.Loader) PREFERENCE_APPLIST_ISASCENDING(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_APPLIST_ISASCENDING) LayoutInflater(android.view.LayoutInflater) PREFERENCE_APPLIST_SORTBY(com.amaze.filemanager.ui.fragments.preference_fragments.PreferencesConstants.PREFERENCE_APPLIST_SORTBY) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) List(java.util.List) Utils(com.amaze.filemanager.utils.Utils) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) GlideApp(com.amaze.filemanager.GlideApp) ViewPreloadSizeProvider(com.bumptech.glide.util.ViewPreloadSizeProvider) PreferenceManager(androidx.preference.PreferenceManager) MaterialProgressBar(me.zhanghai.android.materialprogressbar.MaterialProgressBar) R(com.amaze.filemanager.R) UtilitiesProvider(com.amaze.filemanager.ui.provider.UtilitiesProvider) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) AppTheme(com.amaze.filemanager.ui.theme.AppTheme) Collections(java.util.Collections) AppsAdapterPreloadModel(com.amaze.filemanager.adapters.glide.AppsAdapterPreloadModel) AppListLoader(com.amaze.filemanager.asynchronous.loaders.AppListLoader) FastScroller(com.amaze.filemanager.ui.views.FastScroller) RecyclerViewPreloader(com.bumptech.glide.integration.recyclerview.RecyclerViewPreloader) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) WeakReference(java.lang.ref.WeakReference) MainActivity(com.amaze.filemanager.ui.activities.MainActivity)

Aggregations

AppTheme (com.amaze.filemanager.ui.theme.AppTheme)7 View (android.view.View)6 SharedPreferences (android.content.SharedPreferences)5 Log (android.util.Log)5 LayoutInflater (android.view.LayoutInflater)5 LinearLayout (android.widget.LinearLayout)5 TextView (android.widget.TextView)5 NonNull (androidx.annotation.NonNull)5 Nullable (androidx.annotation.Nullable)5 PreferenceManager (androidx.preference.PreferenceManager)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)5 R (com.amaze.filemanager.R)5 Context (android.content.Context)4 Intent (android.content.Intent)4 Color (android.graphics.Color)4 Typeface (android.graphics.Typeface)4 FingerprintManager (android.hardware.fingerprint.FingerprintManager)4 Uri (android.net.Uri)4 AsyncTask (android.os.AsyncTask)4 Build (android.os.Build)4