use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class ModelTest method bigQuery.
@Test
public void bigQuery() {
assumeTrue("This test is flaky on API29, ignoring", Build.VERSION.SDK_INT != Build.VERSION_CODES.Q);
ModelManager models = mTestCol.getModels();
Model model = models.all().get(0);
final String testString = "test";
final int size = testString.length() * 1024 * 1024;
StringBuilder buf = new StringBuilder((int) (size * 1.01));
// * 1.01 for padding
for (int i = 0; i < 1024 * 1024; ++i) {
buf.append(testString);
}
model.put(testString, buf.toString());
// Buf should be more than 4MB, so at least two chunks from database.
models.flush();
// Reload models
mTestCol.load();
Model newModel = models.all().get(0);
assertEquals(newModel, model);
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class CardTemplateEditor method showDiscardChangesDialog.
@VisibleForTesting
public MaterialDialog showDiscardChangesDialog() {
MaterialDialog discardDialog = DiscardChangesDialog.getDefault(this).onPositive((dialog, which) -> {
Timber.i("TemplateEditor:: OK button pressed to confirm discard changes");
// Clear the edited model from any cache files, and clear it from this objects memory to discard changes
TemporaryModel.clearTempModelFiles();
mTempModel = null;
finishWithAnimation(END);
}).build();
discardDialog.show();
return discardDialog;
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class CardTemplateEditor method onDeckSelected.
/**
* When a deck is selected via Deck Override
*/
@Override
public void onDeckSelected(@Nullable SelectableDeck deck) {
if (getTempModel().getModel().isCloze()) {
Timber.w("Attempted to set deck for cloze model");
UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
return;
}
int ordinal = mViewPager.getCurrentItem();
JSONObject template = getTempModel().getTemplate(ordinal);
String templateName = template.getString("name");
if (deck != null && Decks.isDynamic(getCol(), deck.getDeckId())) {
Timber.w("Attempted to set default deck of %s to dynamic deck %s", templateName, deck.getName());
UIUtils.showThemedToast(this, getString(R.string.multimedia_editor_something_wrong), true);
return;
}
String message;
if (deck == null) {
Timber.i("Removing default template from template '%s'", templateName);
template.put("did", JSONObject.NULL);
message = getString(R.string.model_manager_deck_override_removed_message, templateName);
} else {
Timber.i("Setting template '%s' to '%s'", templateName, deck.getName());
template.put("did", deck.getDeckId());
message = getString(R.string.model_manager_deck_override_added_message, templateName, deck.getName());
}
UIUtils.showThemedToast(this, message, true);
// Deck Override can change from "on" <-> "off"
supportInvalidateOptionsMenu();
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method singleTemplateFromNoteEditorHasNoNavigation.
@Test
public void singleTemplateFromNoteEditorHasNoNavigation() {
List<NoteService.NoteField> fields = new ArrayList<>();
fields.add(new Field(0, "Hello"));
fields.add(new Field(1, "World"));
Model basicModel = getCurrentDatabaseModelCopy("Basic");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), basicModel);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
Bundle noteEditorBundle = new Bundle();
noteEditorBundle.putBundle("editFields", getFieldsAsBundleForPreview(fields));
noteEditorBundle.putInt("ordinal", 0);
noteEditorBundle.putLong("did", 1);
intent.putExtra("noteEditorBundle", noteEditorBundle);
TestCardTemplatePreviewer testCardTemplatePreviewer = super.startActivityNormallyOpenCollectionWithIntent(TestCardTemplatePreviewer.class, intent);
assertThat("prev should not be visible", testCardTemplatePreviewer.previousButtonVisible(), is(false));
assertThat("next should not be visible", testCardTemplatePreviewer.nextButtonVisible(), is(false));
}
use of com.ichi2.libanki.Model in project Anki-Android by ankidroid.
the class CardTemplatePreviewerTest method nonClozeFromNoteEditorHasMultipleCards.
@Test
public void nonClozeFromNoteEditorHasMultipleCards() {
List<NoteService.NoteField> fields = new ArrayList<>();
fields.add(new Field(0, "Hello"));
fields.add(new Field(1, "World"));
Model basicModel = getCurrentDatabaseModelCopy("Basic (and reversed card)");
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), basicModel);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
Bundle noteEditorBundle = new Bundle();
noteEditorBundle.putBundle("editFields", getFieldsAsBundleForPreview(fields));
noteEditorBundle.putInt("ordinal", 0);
noteEditorBundle.putLong("did", 1);
intent.putExtra("noteEditorBundle", noteEditorBundle);
TestCardTemplatePreviewer testCardTemplatePreviewer = super.startActivityNormallyOpenCollectionWithIntent(TestCardTemplatePreviewer.class, intent);
assertTwoCards(testCardTemplatePreviewer);
}
Aggregations