use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class DeckPicker method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Resources res = getResources();
if (getDrawerToggle().onOptionsItemSelected(item)) {
return true;
}
int itemId = item.getItemId();
if (itemId == R.id.action_undo) {
Timber.i("DeckPicker:: Undo button pressed");
undo();
return true;
} else if (itemId == R.id.action_sync) {
Timber.i("DeckPicker:: Sync button pressed");
sync();
return true;
} else if (itemId == R.id.action_import) {
Timber.i("DeckPicker:: Import button pressed");
showDialogFragment(ImportFileSelectionFragment.createInstance(this));
return true;
} else if (itemId == R.id.action_new_filtered_deck) {
CreateDeckDialog createFilteredDeckDialog = new CreateDeckDialog(DeckPicker.this, R.string.new_deck, CreateDeckDialog.DeckDialogType.FILTERED_DECK, null);
createFilteredDeckDialog.setOnNewDeckCreated((id) -> {
// a filtered deck was created
openStudyOptions(true);
});
createFilteredDeckDialog.showFilteredDeckDialog();
return true;
} else if (itemId == R.id.action_check_database) {
Timber.i("DeckPicker:: Check database button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_DATABASE_CHECK);
return true;
} else if (itemId == R.id.action_check_media) {
Timber.i("DeckPicker:: Check media button pressed");
showMediaCheckDialog(MediaCheckDialog.DIALOG_CONFIRM_MEDIA_CHECK);
return true;
} else if (itemId == R.id.action_empty_cards) {
Timber.i("DeckPicker:: Empty cards button pressed");
handleEmptyCards();
return true;
} else if (itemId == R.id.action_model_browser_open) {
Timber.i("DeckPicker:: Model browser button pressed");
Intent noteTypeBrowser = new Intent(this, ModelBrowser.class);
startActivityForResultWithAnimation(noteTypeBrowser, 0, START);
return true;
} else if (itemId == R.id.action_restore_backup) {
Timber.i("DeckPicker:: Restore from backup button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_RESTORE_BACKUP);
return true;
} else if (itemId == R.id.action_export) {
Timber.i("DeckPicker:: Export collection button pressed");
String msg = getResources().getString(R.string.confirm_apkg_export);
mExportingDelegate.showExportDialog(msg);
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.ichi2.libanki.Model 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.Model in project Anki-Android by ankidroid.
the class ModelBrowser method addNewNoteTypeDialog.
/*
*Creates the dialogue box to select a note type, add a name, and then clone it
*/
private void addNewNoteTypeDialog() {
initializeNoteTypeList();
final Spinner addSelectionSpinner = new Spinner(this);
ArrayAdapter<String> newModelAdapter = new ArrayAdapter<>(this, R.layout.dropdown_deck_item, mNewModelLabels);
addSelectionSpinner.setAdapter(newModelAdapter);
new MaterialDialog.Builder(this).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).customView(addSelectionSpinner, true).onPositive((dialog, which) -> {
mModelNameInput = new FixedEditText(ModelBrowser.this);
mModelNameInput.setSingleLine();
final boolean isStdModel = addSelectionSpinner.getSelectedItemPosition() < mNewModelLabels.size();
// 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 (mExistingModelNames.contains(suggestedName)) {
suggestedName = randomizeName(suggestedName);
}
mModelNameInput.setText(suggestedName);
mModelNameInput.setSelection(mModelNameInput.getText().length());
// Create textbox to name new model
new MaterialEditTextDialog.Builder(ModelBrowser.this, mModelNameInput).title(R.string.model_browser_add).positiveText(R.string.dialog_ok).onPositive((innerDialog, innerWhich) -> {
String modelName = mModelNameInput.getText().toString();
addNewNoteType(modelName, addSelectionSpinner.getSelectedItemPosition());
}).negativeText(R.string.dialog_cancel).show();
}).negativeText(R.string.dialog_cancel).show();
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class ModelBrowser method addNewNoteType.
/**
* Add a new note type
* @param modelName name of the new model
* @param position position in dialog the user selected to add / clone the model type from
*/
private void addNewNoteType(String modelName, int position) {
Model model;
if (modelName.length() > 0) {
int nbStdModels = StdModels.STD_MODELS.length;
if (position < nbStdModels) {
model = StdModels.STD_MODELS[position].add(mCol);
} else {
// New model
// Model that is being cloned
Model oldModel = mModels.get(position - nbStdModels).deepClone();
Model newModel = StdModels.BASIC_MODEL.add(mCol);
oldModel.put("id", newModel.getLong("id"));
model = oldModel;
}
model.put("name", modelName);
mCol.getModels().update(model);
fullRefresh();
} else {
showToast(getResources().getString(R.string.toast_empty_name));
}
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class ImportTest method testCsv2.
@Test
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.O)
public void testCsv2() throws IOException, ConfirmModSchemaException {
ModelManager mm = mTestCol.getModels();
Model m = mm.current();
JSONObject f = mm.newField("Three");
mm.addField(m, f);
mm.save(m);
Note n = mTestCol.newNote();
n.setField(0, "1");
n.setField(1, "2");
n.setField(2, "3");
mTestCol.addNote(n);
// an update with unmapped fields should not clobber those fields
String file = Shared.getTestFilePath(getTestContext(), "text-update.txt");
TextImporter i = new TextImporter(mTestCol, file);
i.initMapping();
i.run();
n.load();
List<String> fields = Arrays.asList(n.getFields());
assertThat(fields, contains("1", "x", "3"));
}
Aggregations