Permalink
Browse files

libanki as of April 16

  • Loading branch information...
1 parent 8277c60 commit c9b0b04870251e23d000a451caf5db58319c2323 @nobnago nobnago committed Apr 16, 2012
@@ -233,7 +233,7 @@ public String css() {
public HashMap<String, String> _getQA(boolean reload) {
if (mQA == null || reload) {
mQA = new HashMap<String, String>();
- Note n = note();
+ Note n = note(reload);
JSONObject m = model();
Object[] data;
try {
@@ -560,8 +560,9 @@ public void _remNotes(long[] ids) {
}
// if missing ord and is available, generate
if (!doHave && avail.contains(tord)) {
+ // we'd like to use the same due# as sibling cards, but we can't retrieve that quickly, so we give it a new id instead
data.add(new Object[] { ts, nid, cur.getLong(2), tord, now,
- usn, cur.getLong(0) });
+ usn, nextID("pos") });
ts += 1;
}
}
@@ -1031,8 +1032,12 @@ public long fixIntegrity() {
for (JSONObject m : mModels.all()) {
updateFieldCache(Utils.arrayList2array(mModels.nids(m)));
}
+ // new card position
+ mConf.put("nextPos", mDb.queryScalar("SELECT max(due) + 1 FROM cards WHERE type = 0", false));
mDb.getDatabase().setTransactionSuccessful();
- } finally {
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ } finally {
mDb.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
@@ -81,7 +81,7 @@
+ ", "
+ "'perDay': 20, }, "
+ "'lapse': {"
- + "'delays': [1, 10], "
+ + "'delays': [10], "
+ "'mult': 0, "
+ "'minInt': 1, "
+ "'leechFails': 8, "
@@ -211,7 +211,7 @@ public long id(String name, boolean create, String type) {
}
if (name.matches(".*::.*")) {
// not top level; ensure all parents exist
- _ensureParents(name);
+ name = _ensureParents(name);
}
JSONObject g;
long id;
@@ -370,17 +370,23 @@ public boolean rename(JSONObject g, String newName) {
return true;
}
- private void _ensureParents(String name) {
- String[] path = name.split("::");
+ /** Ensure parents exist, and return name with case matching parents. */
+ private String _ensureParents(String name) {
String s = "";
+ String[] path = name.split("::");
for (int i = 0; i < path.length - 1; i++) {
if (i == 0) {
s = path[0];
} else {
s = s + "::" + path[i];
}
- id(s);
+ // fetch or create
+ long did = id(s);
+ // get original case
+ s = name(did);
}
+ name = s + "::" + path[path.length - 1];
+ return name;
}
/**
@@ -19,10 +19,8 @@
package com.ichi2.libanki;
import android.content.ContentValues;
-import android.database.Cursor;
import android.util.Log;
-import com.ichi2.anki.AnkiDb;
import com.ichi2.anki.AnkiDroidApp;
import com.mindprod.common11.StringTools;
import com.samskivert.mustache.Mustache;
@@ -1003,7 +1003,6 @@ private int _delayForGrade(JSONObject conf, int left) {
}
private JSONObject _lrnConf(Card card) {
- JSONObject conf = _cardConf(card);
if (card.getType() == 2) {
return _lapseConf(card);
} else {
@@ -1013,7 +1012,8 @@ private JSONObject _lrnConf(Card card) {
private void _rescheduleAsRev(Card card, JSONObject conf, boolean early) {
if (card.getType() == 2) {
- card.setDue(card.getODue());
+ card.setDue(Math.max(mToday + 1, card.getODue()));
+ card.setODue(0);
} else {
_rescheduleNew(card, conf, early);
}
@@ -2118,7 +2118,7 @@ public void sortCards(long[] cids, int start, int step, boolean shuffle, boolean
int low = mCol.getDb().queryScalar("SELECT min(due) FROM cards WHERE due >= " + start + " AND type = 0 AND id NOT IN " + scids, false);
if (low != 0) {
int shiftby = high - low + 1;
- mCol.getDb().execute("UPDATE cards SET mod = " + now + ", usn = " + mCol.usn() + ", due = due + " + shiftby + " WHERE id NOT IN " + scids + " AND due >= " + low);
+ mCol.getDb().execute("UPDATE cards SET mod = " + now + ", usn = " + mCol.usn() + ", due = due + " + shiftby + " WHERE id NOT IN " + scids + " AND due >= " + low + " AND queue = 0");
}
}
// reorder cards
@@ -311,6 +311,9 @@ private JSONArray sanityCheck() {
return null;
}
mCol.getSched().reset();
+ // check for missing parent decks
+ mCol.getSched().deckDueList();
+ // return summary of deck
JSONArray ja = new JSONArray();
JSONArray sa = new JSONArray();
for (int c : mCol.getSched().counts()) {

0 comments on commit c9b0b04

Please sign in to comment.