Search in sources :

Example 6 with FixedEditText

use of com.ichi2.ui.FixedEditText in project Anki-Android by ankidroid.

the class ModelFieldEditor method repositionFieldDialog.

/*
     * Allows the user to select a number less than the number of fields in the current model to
     * reposition the current field to
     * Processing time is scales with number of items
     */
private void repositionFieldDialog() {
    mFieldNameInput = new FixedEditText(this);
    mFieldNameInput.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    new MaterialEditTextDialog.Builder(this, mFieldNameInput).title(String.format(getResources().getString(R.string.model_field_editor_reposition), 1, mFieldLabels.size())).positiveText(R.string.dialog_ok).onPositive((dialog, which) -> {
        String newPosition = mFieldNameInput.getText().toString();
        int pos;
        try {
            pos = Integer.parseInt(newPosition);
        } catch (NumberFormatException n) {
            Timber.w(n);
            UIUtils.showThemedToast(this, getResources().getString(R.string.toast_out_of_range), true);
            return;
        }
        if (pos < 1 || pos > mFieldLabels.size()) {
            UIUtils.showThemedToast(this, getResources().getString(R.string.toast_out_of_range), true);
        } else {
            changeHandler listener = changeFieldHandler();
            // Input is valid, now attempt to modify
            try {
                mCol.modSchema();
                TaskManager.launchCollectionTask(new CollectionTask.RepositionField(mMod, mNoteFields.getJSONObject(mCurrentPos), pos - 1), listener);
            } catch (ConfirmModSchemaException e) {
                e.log();
                // Handle mod schema confirmation
                ConfirmationDialog c = new ConfirmationDialog();
                c.setArgs(getResources().getString(R.string.full_sync_confirmation));
                Runnable confirm = () -> {
                    try {
                        mCol.modSchemaNoCheck();
                        TaskManager.launchCollectionTask(new CollectionTask.RepositionField(mMod, mNoteFields.getJSONObject(mCurrentPos), pos - 1), listener);
                        dismissContextMenu();
                    } catch (JSONException e1) {
                        throw new RuntimeException(e1);
                    }
                };
                c.setConfirm(confirm);
                c.setCancel(mConfirmDialogCancel);
                ModelFieldEditor.this.showDialogFragment(c);
            }
        }
    }).negativeText(R.string.dialog_cancel).show();
}
Also used : JSONException(com.ichi2.utils.JSONException) CollectionTask(com.ichi2.async.CollectionTask) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) FixedEditText(com.ichi2.ui.FixedEditText)

Aggregations

FixedEditText (com.ichi2.ui.FixedEditText)6 ConfirmationDialog (com.ichi2.anki.dialogs.ConfirmationDialog)4 ConfirmModSchemaException (com.ichi2.anki.exception.ConfirmModSchemaException)4 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 CollectionTask (com.ichi2.async.CollectionTask)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 DisplayMetrics (android.util.DisplayMetrics)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1