Skip to content

Commit

Permalink
libanki as of April 16
Browse files Browse the repository at this point in the history
  • Loading branch information
nobnago committed Apr 16, 2012
1 parent 8277c60 commit c9b0b04
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/com/ichi2/libanki/Card.java
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/com/ichi2/libanki/Collection.java
Expand Up @@ -560,8 +560,9 @@ public ArrayList<Long> genCards(long[] nids) {
}
// 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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 11 additions & 5 deletions src/com/ichi2/libanki/Decks.java
Expand Up @@ -81,7 +81,7 @@ public class Decks {
+ ", "
+ "'perDay': 20, }, "
+ "'lapse': {"
+ "'delays': [1, 10], "
+ "'delays': [10], "
+ "'mult': 0, "
+ "'minInt': 1, "
+ "'leechFails': 8, "
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/com/ichi2/libanki/Models.java
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/com/ichi2/libanki/Sched.java
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/com/ichi2/libanki/sync/Syncer.java
Expand Up @@ -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()) {
Expand Down

0 comments on commit c9b0b04

Please sign in to comment.