use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class Syncer method changes.
/**
* Bundle up small objects.
*/
public JSONObject changes() {
JSONObject o = new JSONObject();
o.put("models", getModels());
o.put("decks", getDecks());
o.put("tags", getTags());
if (mLNewer) {
o.put("conf", getConf());
o.put("crt", mCol.getCrt());
}
return o;
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class ReviewerTest method cloneTemplate.
private void cloneTemplate(ModelManager models, Model m) throws ConfirmModSchemaException {
JSONArray tmpls = m.getJSONArray("tmpls");
JSONObject defaultTemplate = tmpls.getJSONObject(0);
JSONObject newTemplate = defaultTemplate.deepClone();
newTemplate.put("ord", tmpls.length());
String card_name = getTargetContext().getString(R.string.card_n_name, tmpls.length() + 1);
newTemplate.put("name", card_name);
models.addTemplate(m, newTemplate);
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class ReviewerTest method jsAnkiGetDeckName.
@Test
public void jsAnkiGetDeckName() {
Collection col = getCol();
ModelManager models = col.getModels();
DeckManager decks = col.getDecks();
Long didAb = addDeck("A::B");
Model basic = models.byName(AnkiDroidApp.getAppResources().getString(R.string.basic_model_name));
basic.put("did", didAb);
addNoteUsingBasicModel("foo", "bar");
Long didA = addDeck("A");
decks.select(didA);
Reviewer reviewer = startReviewer();
AnkiDroidJsAPI javaScriptFunction = reviewer.javaScriptFunction();
waitForAsyncTasksToComplete();
assertThat(javaScriptFunction.ankiGetDeckName(), is("B"));
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class ContentProviderTest method testProviderProvidesDefaultForEmptyModelDeck.
/**
* Test that a null did will not crash the provider (#6378)
*/
@Test
public void testProviderProvidesDefaultForEmptyModelDeck() {
assumeTrue("This causes mild data corruption - should not be run on a collection you care about", isEmulator());
Collection col = getCol();
col.getModels().all().get(0).put("did", JSONObject.NULL);
col.save();
final ContentResolver cr = getContentResolver();
// Query all available models
final Cursor allModels = cr.query(FlashCardsContract.Model.CONTENT_URI, null, null, null, null);
assertNotNull(allModels);
}
use of com.ichi2.libanki.Models in project Anki-Android by ankidroid.
the class ContentProviderTest method setUp.
/**
* Initially create one note for each model.
*/
@Before
public void setUp() throws Exception {
Timber.i("setUp()");
mCreatedNotes = new ArrayList<>();
final Collection col = getCol();
// We have parameterized the "schedVersion" variable, if we are on an emulator
// (so it is safe) we will try to run with multiple scheduler versions
mTearDown = false;
if (InstrumentedTest.isEmulator()) {
col.changeSchedulerVer(schedVersion);
} else {
if (schedVersion == 1) {
assumeThat(col.getSched().getName(), is("std"));
} else {
assumeThat(col.getSched().getName(), is("std2"));
}
}
mTearDown = true;
// Do not teardown if setup was aborted
// Add a new basic model that we use for testing purposes (existing models could potentially be corrupted)
Model model = StdModels.BASIC_MODEL.add(col, BASIC_MODEL_NAME);
mModelId = model.getLong("id");
List<String> fields = model.getFieldsNames();
// Use the names of the fields as test values for the notes which will be added
mDummyFields = fields.toArray(new String[0]);
// create test decks and add one note for every deck
mNumDecksBeforeTest = col.getDecks().count();
for (String fullName : TEST_DECKS) {
String[] path = Decks.path(fullName);
String partialName = "";
/* Looping over all parents of full name. Adding them to
* mTestDeckIds ensures the deck parents decks get deleted
* too at tear-down.
*/
for (String s : path) {
partialName += s;
/* If parent already exists, don't add the deck, so
* that we are sure it won't get deleted at
* set-down, */
if (col.getDecks().byName(partialName) != null) {
continue;
}
long did = col.getDecks().id(partialName);
mTestDeckIds.add(did);
mCreatedNotes.add(setupNewNote(col, mModelId, did, mDummyFields, TEST_TAG));
partialName += "::";
}
}
// Add a note to the default deck as well so that testQueryNextCard() works
mCreatedNotes.add(setupNewNote(col, mModelId, 1, mDummyFields, TEST_TAG));
}
Aggregations