use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class Collection method load.
/**
* DB-related *************************************************************** ********************************
*/
public void load() {
Cursor cursor = null;
String deckConf = "";
try {
// Read in deck table columns
cursor = mDb.query("SELECT crt, mod, scm, dty, usn, ls, " + "conf, dconf, tags,ver FROM col");
if (!cursor.moveToFirst()) {
return;
}
mCrt = cursor.getLong(0);
mMod = cursor.getLong(1);
mScm = cursor.getLong(2);
// No longer used
mDty = cursor.getInt(3) == 1;
mUsn = cursor.getInt(4);
mLs = cursor.getLong(5);
mConf = new JSONObject(cursor.getString(6));
deckConf = cursor.getString(7);
mTagsJson = cursor.getString(8);
mTags.load(mTagsJson);
mVer = cursor.getInt(9);
} finally {
if (cursor != null) {
cursor.close();
}
}
// getModels().load(loadColumn("models")); This code has been
// moved to `CollectionHelper::loadLazyCollection` for
// efficiency Models are loaded lazily on demand. The
// application layer can asynchronously pre-fetch those parts;
// otherwise they get loaded when required.
Timber.i("load new collection");
mDecks.load(loadColumn("decks"), deckConf);
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class Models method scmhash.
/**
* Schema hash ***********************************************************************************************
*/
/**
* Return a hash of the schema, to see if models are compatible.
*/
public String scmhash(Model m) {
String s = "";
JSONArray flds = m.getJSONArray("flds");
for (int i = 0; i < flds.length(); ++i) {
s += flds.getJSONObject(i).getString("name");
}
JSONArray tmpls = m.getJSONArray("tmpls");
for (int i = 0; i < tmpls.length(); ++i) {
JSONObject t = tmpls.getJSONObject(i);
s += t.getString("name");
}
return Utils.checksum(s);
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class Syncer method getModels.
/**
* Models ********************************************************************
*/
private JSONArray getModels() {
JSONArray result = new JSONArray();
if (mCol.getServer()) {
for (JSONObject m : mCol.getModels().all()) {
if (m.getInt("usn") >= mMinUsn) {
result.put(m);
}
}
} else {
for (JSONObject m : mCol.getModels().all()) {
if (m.getInt("usn") == -1) {
m.put("usn", mMaxUsn);
result.put(m);
}
}
mCol.getModels().save();
}
return result;
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class AnkiChinaSyncer method compareSyncTable.
private JSONObject compareSyncTable() {
mCol = CollectionHelper.getInstance().getColSafe(AnkiDroidApp.getInstance());
CollectionHelper.getInstance().lockCollection();
DB db = mCol.getDb();
db.execute("create index if not exists ix_synclog_id on synclog (id);)");
int num = db.queryScalar("SELECT id FROM synclog");
if (num == 0) {
// 表是空的,则直接同步所有内容到该表
Timber.w("no record in synclog table!");
}
JSONObject root = new JSONObject();
JSONObject colJson = new JSONObject();
JSONObject colJsonReplace = new JSONObject();
// JSONObject decksJson = new JSONObject();
// JSONObject modelsJson = new JSONObject();
// JSONObject dconfJson = new JSONObject();
colJsonReplace.put("crt", mCol.getCrt());
colJsonReplace.put("mod", mCol.getMod());
colJsonReplace.put("scm", mCol.getScm());
colJsonReplace.put("ver", mCol.getVer());
colJsonReplace.put("dty", mCol.getDirty() ? 1 : 0);
colJsonReplace.put("usn", mCol.getUsnForSync());
colJsonReplace.put("ls", mCol.getLs());
colJsonReplace.put("conf", mCol.getConf());
colJsonReplace.put("tags", mCol.getTagsJson());
colJson.put("replace", colJsonReplace);
root.put("col", colJson);
root.put("decks", getChangedColJson(SYNC_LOG_TYPE_DECKS, mCol.getDecks().all()));
root.put("dconf", getChangedColJson(SYNC_LOG_TYPE_DCONF, mCol.getDecks().allConf()));
root.put("models", getChangedColJson(SYNC_LOG_TYPE_MODELS, mCol.getModels().all()));
updateDialogProgress(SYNCING_DATA, "整理数据中", 6);
root.put("cards", getChangedCardsOrNote(SYNC_LOG_TYPE_CARD));
root.put("notes", getChangedCardsOrNote(SYNC_LOG_TYPE_NOTE));
root.put("revlog", getAddedRevLog());
CollectionHelper.getInstance().unlockCollection();
// root.put("revlog", getChangedCardsOrNote(SYNC_LOG_TYPE_REVLOG));
return root;
}
use of com.ichi2.libanki.Models in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method baseDeckName.
@Test
public void baseDeckName() {
Collection col = getCol();
Models models = col.getModels();
Decks decks = col.getDecks();
Long didAb = decks.id("A::B");
Model basic = models.byName(AnkiDroidApp.getAppResources().getString(R.string.basic_model_name));
basic.put("did", didAb);
addNoteUsingBasicModel("foo", "bar");
Long didA = decks.id("A");
decks.select(didA);
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertThat(reviewer.getSupportActionBar().getTitle(), is("B"));
}
Aggregations