Search in sources :

Example 1 with BasicActivity

use of com.amaze.filemanager.ui.activities.superclasses.BasicActivity in project AmazeFileManager by TeamAmaze.

the class RenameBookmark method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Context c = getActivity();
    if (getActivity() instanceof BookmarkCallback)
        bookmarkCallback = (BookmarkCallback) getActivity();
    title = getArguments().getString("title");
    path = getArguments().getString("path");
    int accentColor = getArguments().getInt("accentColor");
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
    if (dataUtils.containsBooks(new String[] { title, path }) != -1) {
        final MaterialDialog materialDialog;
        String pa = path;
        MaterialDialog.Builder builder = new MaterialDialog.Builder(c);
        builder.title(R.string.rename_bookmark);
        builder.positiveColor(accentColor);
        builder.negativeColor(accentColor);
        builder.neutralColor(accentColor);
        builder.positiveText(R.string.save);
        builder.neutralText(R.string.cancel);
        builder.negativeText(R.string.delete);
        builder.theme(((BasicActivity) getActivity()).getAppTheme().getMaterialDialogTheme());
        builder.autoDismiss(false);
        View v2 = getActivity().getLayoutInflater().inflate(R.layout.rename, null);
        builder.customView(v2, true);
        final TextInputLayout t1 = v2.findViewById(R.id.t1);
        final TextInputLayout t2 = v2.findViewById(R.id.t2);
        final AppCompatEditText conName = v2.findViewById(R.id.editText4);
        conName.setText(title);
        final String s1 = getString(R.string.cant_be_empty, c.getString(R.string.name));
        final String s2 = getString(R.string.cant_be_empty, c.getString(R.string.path));
        conName.addTextChangedListener(new SimpleTextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
                if (conName.getText().toString().length() == 0)
                    t1.setError(s2);
                else
                    t1.setError("");
            }
        });
        final AppCompatEditText ip = v2.findViewById(R.id.editText);
        t2.setVisibility(View.GONE);
        ip.setText(pa);
        builder.onNeutral((dialog, which) -> dialog.dismiss());
        materialDialog = builder.build();
        materialDialog.getActionButton(DialogAction.POSITIVE).setOnClickListener(v -> {
            String t = ip.getText().toString();
            String name = conName.getText().toString();
            int i = -1;
            if ((i = dataUtils.containsBooks(new String[] { title, path })) != -1) {
                if (!t.equals(title) && t.length() >= 1) {
                    dataUtils.removeBook(i);
                    dataUtils.addBook(new String[] { name, t });
                    dataUtils.sortBook();
                    if (bookmarkCallback != null) {
                        bookmarkCallback.modify(path, title, t, name);
                    }
                }
            }
            materialDialog.dismiss();
        });
        materialDialog.getActionButton(DialogAction.NEGATIVE).setOnClickListener(v -> {
            int i;
            if ((i = dataUtils.containsBooks(new String[] { title, path })) != -1) {
                dataUtils.removeBook(i);
                if (bookmarkCallback != null) {
                    bookmarkCallback.delete(title, path);
                }
            }
            materialDialog.dismiss();
        });
        return materialDialog;
    }
    return null;
}
Also used : Context(android.content.Context) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) SharedPreferences(android.content.SharedPreferences) BasicActivity(com.amaze.filemanager.ui.activities.superclasses.BasicActivity) View(android.view.View) AppCompatEditText(androidx.appcompat.widget.AppCompatEditText) SimpleTextWatcher(com.amaze.filemanager.utils.SimpleTextWatcher) Editable(android.text.Editable) TextInputLayout(com.google.android.material.textfield.TextInputLayout)

Aggregations

Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 Editable (android.text.Editable)1 View (android.view.View)1 AppCompatEditText (androidx.appcompat.widget.AppCompatEditText)1 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)1 BasicActivity (com.amaze.filemanager.ui.activities.superclasses.BasicActivity)1 SimpleTextWatcher (com.amaze.filemanager.utils.SimpleTextWatcher)1 TextInputLayout (com.google.android.material.textfield.TextInputLayout)1