use of com.ichi2.libanki.StdModels in project Anki-Android by ankidroid.
the class ModelBrowser method initializeNoteTypeList.
/*
* retrieve list of note type in variable, which will going to be in use for adding/cloning note type
*/
private void initializeNoteTypeList() {
String add = getResources().getString(R.string.model_browser_add_add);
String clone = getResources().getString(R.string.model_browser_add_clone);
// Populates array adapters listing the mModels (includes prefixes/suffixes)
int existingModelSize = mModels.size();
int stdModelSize = StdModels.STD_MODELS.length;
mNewModelLabels = new ArrayList<>(existingModelSize + stdModelSize);
mExistingModelNames = new ArrayList<>(existingModelSize);
// Used to fetch model names
mNewModelNames = new ArrayList<>(stdModelSize);
for (StdModels StdModels : StdModels.STD_MODELS) {
String defaultName = StdModels.getDefaultName();
mNewModelLabels.add(String.format(add, defaultName));
mNewModelNames.add(defaultName);
}
for (Model model : mModels) {
String name = model.getString("name");
mNewModelLabels.add(String.format(clone, name));
mNewModelNames.add(name);
mExistingModelNames.add(name);
}
}
use of com.ichi2.libanki.StdModels in project AnkiChinaAndroid by ankichinateam.
the class ModelBrowser method addNewNoteTypeDialog.
/*
*Creates the dialogue box to select a note type, add a name, and then clone it
*/
private void addNewNoteTypeDialog() {
String add = getResources().getString(R.string.model_browser_add_add);
String clone = getResources().getString(R.string.model_browser_add_clone);
// Populates arrayadapters listing the mModels (includes prefixes/suffixes)
mNewModelLabels = new ArrayList<>();
ArrayList<String> existingModelsNames = new ArrayList<>();
// Used to fetch model names
mNewModelNames = new ArrayList<>();
for (StdModels StdModels : StdModels.stdModels) {
String defaultName = StdModels.getDefaultName();
mNewModelLabels.add(String.format(add, defaultName));
mNewModelNames.add(defaultName);
}
final int numStdModels = mNewModelLabels.size();
if (mModels != null) {
for (Model model : mModels) {
String name = model.getString("name");
mNewModelLabels.add(String.format(clone, name));
mNewModelNames.add(name);
existingModelsNames.add(name);
}
}
final Spinner addSelectionSpinner = new Spinner(this);
ArrayAdapter<String> mNewModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item, mNewModelLabels);
addSelectionSpinner.setAdapter(mNewModelAdapter);
new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).customView(addSelectionSpinner, true).onPositive((dialog, which) -> {
mModelNameInput = new EditText(ModelBrowser.this);
mModelNameInput.setSingleLine();
final boolean isStdModel = addSelectionSpinner.getSelectedItemPosition() < numStdModels;
// Try to find a unique model name. Add "clone" if cloning, and random digits if necessary.
String suggestedName = mNewModelNames.get(addSelectionSpinner.getSelectedItemPosition());
if (!isStdModel) {
suggestedName += " " + getResources().getString(R.string.model_clone_suffix);
}
if (existingModelsNames.contains(suggestedName)) {
suggestedName = randomizeName(suggestedName);
}
mModelNameInput.setText(suggestedName);
mModelNameInput.setSelection(mModelNameInput.getText().length());
// Create textbox to name new model
new MaterialDialog.Builder(ModelBrowser.this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).customView(mModelNameInput, true).onPositive((innerDialog, innerWhich) -> {
String modelName = mModelNameInput.getText().toString();
addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition());
}).negativeText(R.string.dialog_cancel).show();
}).negativeText(R.string.dialog_cancel).show();
}