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();
}
Aggregations