Skip to content
Browse files

Merge branch 'master' of https://github.com/nobnago/Anki-Android

  • Loading branch information...
2 parents fec5ff0 + 3f6367d commit fdb5103c5576d1e3bdf962d2b17c2af8e1d4721a @nicolas-raoul committed Apr 23, 2012
View
6 res/values-ru/11-arrays.xml
@@ -48,12 +48,12 @@
<string-array name="studyoptions_more_new_card_order">
<item>Новые в случайном порядке</item>
<item>Новые в порядке их добавления</item>
- <item>Новые, в обрат.порядке их добавления</item>
+ <item>Новые в обрат.порядке их добавления</item>
</string-array>
<string-array name="studyoptions_more_new_card_schedule">
- <item>Новые и просмотренные вперемешку</item>
+ <item>Новые и повторяемые вперемешку</item>
<item>Новые после всех других</item>
- <item>Новые до пересматриваемых</item>
+ <item>Новые до повторяемых</item>
</string-array>
<string-array name="studyoptions_more_rev_card_order">
<item>Просмотр карт с наибол. интервалом</item>
View
8 res/values-sv/01-core.xml
@@ -22,7 +22,7 @@
<resources>
<string name="btn_continue">Fortsätt</string>
<string name="app_name">AnkiDroid</string>
- <string name="attention">Attention</string>
+ <string name="attention">Observera</string>
<string name="yes">Ja</string>
<string name="no">Nej</string>
<string name="ok">Ok</string>
@@ -69,7 +69,7 @@
<string name="menu_suspend_card">Åsidosätt kort</string>
<string name="menu_suspend_note">Åsidosätt anteckning</string>
<string name="menu_delete_note">Ta bort anteckning</string>
- <string name="delete_note_message">Really delete this note and all its cards?\n%s</string>
+ <string name="delete_note_message">Vill du verkligen ta bort den här anteckningen och dess kort?\n%s</string>
<string name="menu_edit_card">Redigera kort</string>
<string name="menu_select">Markera text</string>
<string name="menu_search">Sökning i %1$s</string>
@@ -85,8 +85,8 @@
<string name="visit">Besök</string>
<string name="later">Senare</string>
<string name="download">Hämta</string>
- <string name="open_collection">Opening collection.\nPlease wait...</string>
- <string name="create_collection">Creating collection.\nPlease wait...</string>
+ <string name="open_collection">Öppnar samling.\nVar vänlig vänta...</string>
+ <string name="create_collection">Skapar samling.\nVar vänlig vänta...</string>
<string name="studyoptions_congrats_finished">Grattis! Du är klar nu.</string>
<string name="studyoptions_congrats_more_rev">Today\'s review limit has been reached, but there are still cards waiting to be reviewed. For optimum memory, consider increasing the daily limit in the options.</string>
<string name="studyoptions_congrats_more_new">There are more new cards available, but the daily limit has been reached. You can increase the limit in the options, but please bear in mind that the more new cards you introduce, the higher your short-term review workload will become.</string>
View
10 res/values-sv/02-strings.xml
@@ -24,11 +24,11 @@
<string name="CardEditorSaveButton">Spara</string>
<string name="CardEditorLaterButton">Senare</string>
<string name="CardEditorCardDeck">Kortlek: %s</string>
- <string name="CardEditorNoteDeck">Note deck: %s</string>
- <string name="CardEditorModel">Note type: %s</string>
+ <string name="CardEditorNoteDeck">Anteckningskortlek: %s</string>
+ <string name="CardEditorModel">Anteckningstyp: %s</string>
<string name="CardEditorTags">Etiketter: %1$s</string>
<string name="add_new_tag">Lägg till ny etikett</string>
- <string name="note_type">Note type</string>
+ <string name="note_type">Anteckningstyp</string>
<string name="sdcard_missing_message">SD-kortet är inte tillgängligt eftersom det används som USB-minne. Koppla ur USB:n för att komma åt din kortlek.</string>
<string name="show_whiteboard">Visa tidur / whiteboard</string>
<string name="hide_whiteboard">Dölj Whiteboard</string>
@@ -44,7 +44,7 @@
<string name="cardeditor_title_edit_card">Redigera anteckning</string>
<string name="factadder_saving_error">Fel vid sparande av anteckning</string>
<string name="cardeditor_move_note_too">Flytta även anteckning</string>
- <string name="cardeditor_move_to_notes_deck">To note\'s deck</string>
+ <string name="cardeditor_move_to_notes_deck">Till anteckningens kortlek</string>
<string name="saving_facts">Sparar anteckning</string>
<string name="deck">Kortlek</string>
<string name="add">Lägg till</string>
@@ -77,7 +77,7 @@
<string name="delete_deck">Tar bort kortlek...\nVänligen vänta.</string>
<string-array name="dynOrderLabels">
<item>Oldest seen first</item>
- <item>Random</item>
+ <item>Slumpmässigt</item>
<item>Increasing intervals</item>
<item>Decreasing intervals</item>
<item>Most lapses</item>
View
10 res/values-sv/04-network.xml
@@ -44,7 +44,7 @@
<string name="pause_download">Pausa hämtning</string>
<string name="duplicate_download">Denna kortlek hämtas redan</string>
<string name="menu_get_shared_decks">Hämta delade kortlekar</string>
- <string name="download_button_return">Return</string>
+ <string name="download_button_return">Återvänd</string>
<string name="connection_error_message">Ett nätverksfel har uppstått.</string>
<string name="sync_log_db_error">Ett databasfel har inträffat.</string>
<string name="no_user_password_error_message">In order to proceed with this operation, you need to have an AnkiWeb account and be logged in.</string>
@@ -73,7 +73,7 @@
<string name="sync_preparing_full_sync_message">Förbereder fullständig synkronisering...</string>
<string name="sync_uploading_message">Laddar upp...</string>
<string name="sync_downloading_message">Hämtar...</string>
- <string name="sync_reload_message">Reloading collection...</string>
+ <string name="sync_reload_message">Laddar samlingen igen...</string>
<string name="sync_title">Synkronisering</string>
<string name="sync_downloading_media">Hämtar media %1$d/%2$d...</string>
<string name="sync_log_uploading_message">Full synk från lokal sida</string>
@@ -84,11 +84,11 @@
<string name="sync_log_old_version">Synkroniseringsprotokollet har ändrats, var god uppgradera till senaste AnkiDroid. Se %s</string>
<string name="sync_conflict_title">Synkningskonflikt</string>
<string name="sync_no_changes_message">Inga ändringar hittades.</string>
- <string name="sync_database_success">Collection successfully synchronized</string>
+ <string name="sync_database_success">Samlingen har synkroniserats</string>
<string name="sync_log_error_specific">Synkningsfel, typ: %1$s, meddelande: %2$s</string>
- <string name="sync_corrupt_database">Your database is corrupt. Please fix it before trying again to sync.\n\nSee %s for information about repairing your database.</string>
+ <string name="sync_corrupt_database">Din databas är korrupt. Var vänlig och åtgärda detta innan du försöker synkronisera igen.\n\nSe %s för mer information om att reparera din databas.</string>
<string name="sync_too_busy">Servern upptagen. Försök igen senare.</string>
- <string name="sync_remote_db_error">The downloaded database was corrupt. Please try again.</string>
+ <string name="sync_remote_db_error">Den nedladdade databasen var korrupt. Var vänlig och försök igen.</string>
<string name="sync_overwrite_error">Your current collection could not be overwritten by the downloaded file.</string>
<string name="sync_write_access_error">The downloaded file could not be saved to the sd card. Either your sd card is mounted read-only or there is not enough space.</string>
<string name="sync_deletions_message">Synkroniserar borttagningar...</string>
View
6 res/values-sv/07-cardbrowser.xml
@@ -26,8 +26,8 @@
<string name="card_browser_delete_card">Ta bort anteckning</string>
<string name="card_browser_suspend_card">Åsidosätt kort</string>
<string name="card_browser_unsuspend_card">Återaktivera kort</string>
- <string name="card_browser_mark_card">Mark note</string>
- <string name="card_browser_unmark_card">Unmark note</string>
+ <string name="card_browser_mark_card">Markera anteckning</string>
+ <string name="card_browser_unmark_card">Avmarkera anteckning</string>
<string name="delete_card_title">Ta bort anteckning</string>
<string name="delete_card_message">Really delete all cards of this note?\nSearch field: %s</string>
<string name="card_browser_show_marked">Filter marked</string>
@@ -51,7 +51,7 @@
<string name="card_details_added">Tillagt</string>
<string name="card_details_changed">Ändrat</string>
<string name="card_details_tags">Etiketter</string>
- <string name="card_details_model">Note type</string>
+ <string name="card_details_model">Anteckningstyp</string>
<string name="card_browser_sorting_cards">Sorterar kort.\nVar god vänta...</string>
<string name="card_browser_filtering_cards">Filtering cards.\nPlease wait...</string>
<string name="card_details_card_model">Kortmodell</string>
View
12 res/values-sv/09-backup.xml
@@ -30,18 +30,18 @@
<string name="backup_restore">Återställ från säkerhetskopia</string>
<string name="backup_new_collection">New collection</string>
<string name="error_handling_title">Felhantering</string>
- <string name="error_handling_options">Options</string>
- <string name="backup_retry_opening">Retry opening</string>
- <string name="backup_error_menu_repair">Repair database</string>
- <string name="backup_repair_deck">Repair</string>
- <string name="backup_repair_deck_progress">Repairing database.\nPlease wait...</string>
+ <string name="error_handling_options">Alternativ</string>
+ <string name="backup_retry_opening">Prova att öppna igen</string>
+ <string name="backup_error_menu_repair">Reparera databas</string>
+ <string name="backup_repair_deck">Reparera</string>
+ <string name="backup_repair_deck_progress">Reparerar databas.\nVar vänlig vänta...</string>
<string name="backup_restore_error">Kortleken kunde inte återställas</string>
<string name="backup_restore_if_missing">Restoring collection if missing...</string>
<string name="backup_restore_deck">Återställer kortlek.\nVar god vänta...</string>
<string name="backup_restore_select_title">Välj säkerhetskopia att återställa</string>
<string name="backup_restore_no_backups">Inga säkerhetskopior för kortleken finns i AnkiDroid. Om du har säkerhetskopior på din stationära dator, kopiera dem manuellt till din AnkiDroid-mapp</string>
<string name="delete_deck_success">Kortleken %1$s borttagen. Säkerhetskopia i mapp %2$s</string>
- <string name="open_collection_failed_title">Collection not opened</string>
+ <string name="open_collection_failed_title">Samlingen är inte öppnad</string>
<string name="open_collection_failed_message">Database could not be opened. It is either not a real anki database or has been corrupted.\n\nYou can try to repair the collection or restore it from a backup (in both cases, the copy of the corrupt deck will be moved to the subfolder \'%1$s\'). Click on \'options\' for that.\n\nMore information about repairing corrupted decks: %2$s.</string>
<string name="deck_repair_error">Kortlek kunde inte repareras</string>
</resources>
View
16 res/values-sv/10-preferences.xml
@@ -208,31 +208,31 @@
<string name="pref_simple_interface">Enkelt gränssnitt</string>
<string name="pref_simple_interface_summ">Snabbar upp kortbyten men stöder endast text (inga bilder, ljud etc.)</string>
<string name="deck_conf_deck_name">Kortleksnamn</string>
- <string name="deck_conf_deck_description">Deck description</string>
+ <string name="deck_conf_deck_description">Kortleksbeskrivning</string>
<string name="deck_conf_conf_set">Configuration set</string>
- <string name="deck_conf_pref_cat_options">Options</string>
+ <string name="deck_conf_pref_cat_options">Alternativ</string>
<string name="deck_conf_new_cards">Nya kort</string>
<string name="deck_conf_rev_cards">Repetitioner</string>
<string name="deck_conf_lps_cards">Lapses</string>
- <string name="deck_conf_other">Other</string>
+ <string name="deck_conf_other">Andra</string>
<string name="deck_conf_add_conf">Add/delete configurations</string>
- <string name="deck_conf_steps">Steps (in minutes)</string>
+ <string name="deck_conf_steps">Steg (i minuter)</string>
<string name="deck_conf_order">Ordning</string>
<string name="deck_conf_new_cards_day">Nya kort/dag</string>
<string name="deck_conf_graduating_ivl">Graduating interval</string>
<string name="deck_conf_days">XXX dag(ar)</string>
<string name="deck_conf_easy">Lätt</string>
<string name="deck_conf_start_factor">Starting factor</string>
- <string name="deck_conf_separate">Siblings</string>
+ <string name="deck_conf_separate">Syskon</string>
<string name="deck_conf_separate_summ">Try not to show sibling cards next to each other</string>
<string name="deck_conf_max_rev">Maximum reviews/day</string>
<string name="deck_conf_sibl_space">Space siblings by up to</string>
- <string name="deck_conf_easy_bonus">Easy bonus</string>
+ <string name="deck_conf_easy_bonus">Lätt bonus</string>
<string name="deck_conf_min_range">Minimum sibling range</string>
<string name="deck_conf_des_fi">Desired forgetting index</string>
<string name="deck_conf_ass_fi">Assumed forgetting index</string>
- <string name="deck_conf_new_lps_ivl">New interval</string>
- <string name="deck_conf_min_ivl">Minimum Interval</string>
+ <string name="deck_conf_new_lps_ivl">Nytt intervall</string>
+ <string name="deck_conf_min_ivl">Minsta intervall</string>
<string name="deck_conf_leech_thres">Leech Threshold</string>
<string name="deck_conf_fails">XXX fails</string>
<string name="deck_conf_leech_action">Leech Action</string>
View
4 src/com/ichi2/anki/Reviewer.java
@@ -1672,7 +1672,7 @@ public void onClick(DialogInterface dialog, int which) {
private int getRecommendedEase() {
- if (mSched.lrnButtons(mCurrentCard)) {
+ if (mSched.answerButtons(mCurrentCard) == 3) {
return EASE_HARD;
} else {
return EASE_MID;
@@ -1978,7 +1978,7 @@ private void showEaseButtons() {
// hide flipcard button
switchVisibility(mFlipCardLayout, View.GONE);
- boolean lrnCard = mSched.lrnButtons(mCurrentCard);
+ boolean lrnCard = mSched.answerButtons(mCurrentCard) == 3;
// Set correct label for each button
if (lrnCard) {
View
7 src/com/ichi2/libanki/Card.java
@@ -263,8 +263,13 @@ public JSONObject model() {
}
public JSONObject template() {
+ JSONObject m = model();
try {
- return model().getJSONArray("tmpls").getJSONObject(mOrd);
+ if (m.getInt("type") == Sched.MODEL_STD) {
+ return m.getJSONArray("tmpls").getJSONObject(mOrd);
+ } else {
+ return model().getJSONArray("tmpls").getJSONObject(0);
+ }
} catch (JSONException e) {
throw new RuntimeException(e);
}
View
104 src/com/ichi2/libanki/Collection.java
@@ -47,9 +47,9 @@
public class Collection {
// collection schema & syncing vars
- public static final int SCHEMA_VERSION = 2;
+ public static final int SCHEMA_VERSION = 5;
public static final String SYNC_URL = "http://beta.ankiweb.net/sync/";
- public static final int SYNC_VER = 1;
+ public static final int SYNC_VER = 2;
private AnkiDb mDb;
private boolean mServer;
@@ -487,16 +487,29 @@ public void _remNotes(long[] ids) {
* @return (active), non-empty templates.
*/
private ArrayList<JSONObject> findTemplates(Note note) {
- ArrayList<JSONObject> ok = new ArrayList<JSONObject>();
JSONObject model = note.model();
ArrayList<Integer> avail = mModels.availOrds(model,
Utils.joinFields(note.values()));
+ return _tmplsFromOrds(model, avail);
+ }
+
+ private ArrayList<JSONObject> _tmplsFromOrds(JSONObject model, ArrayList<Integer> avail) {
+ ArrayList<JSONObject> ok = new ArrayList<JSONObject>();
JSONArray tmpls;
try {
- tmpls = model.getJSONArray("tmpls");
- for (int i = 0; i < tmpls.length(); i++) {
- JSONObject t = tmpls.getJSONObject(i);
- if (avail.contains(t.getInt("ord"))) {
+ if (model.getInt("type") == Sched.MODEL_STD) {
+ tmpls = model.getJSONArray("tmpls");
+ for (int i = 0; i < tmpls.length(); i++) {
+ JSONObject t = tmpls.getJSONObject(i);
+ if (avail.contains(t.getInt("ord"))) {
+ ok.add(t);
+ }
+ }
+ } else {
+ // cloze - generate temporary templates from first
+ for (int ord : avail) {
+ JSONObject t = new JSONObject(model.getJSONArray("tmpls").getString(0));
+ t.put("ord", ord);
ok.add(t);
}
}
@@ -513,17 +526,30 @@ public void _remNotes(long[] ids) {
// build map of (nid,ord) so we don't create dupes
String snids = Utils.ids2str(nids);
HashMap<Long, HashMap<Integer, Long>> have = new HashMap<Long, HashMap<Integer, Long>>();
+ HashMap<Long, Long> dids = new HashMap<Long, Long>();
Cursor cur = null;
try {
cur = mDb.getDatabase().rawQuery(
- "SELECT id, nid, ord FROM cards WHERE nid IN " + snids,
+ "SELECT id, nid, ord, did FROM cards WHERE nid IN " + snids,
null);
while (cur.moveToNext()) {
+ // existing cards
long nid = cur.getLong(1);
if (!have.containsKey(nids)) {
have.put(nid, null);
}
have.get(nid).put(cur.getInt(2), cur.getLong(0));
+ // and their dids
+ long did = cur.getLong(3);
+ if (!dids.containsKey(nid)) {
+ if (dids.get(nid) != 0 && dids.get(nid) != did) {
+ // cards are in two or more different decks; revert to model default
+ dids.put(nid, 0l);
+ }
+ } else {
+ // first card or multiple cards in same deck
+ dids.put(nid, did);
+ }
}
} finally {
if (cur != null && !cur.isClosed()) {
@@ -547,25 +573,36 @@ public void _remNotes(long[] ids) {
ArrayList<Integer> avail = mModels.availOrds(model,
cur.getString(3));
long nid = cur.getLong(0);
- JSONArray tmpls = model.getJSONArray("tmpls");
- for (int i = 0; i < tmpls.length(); i++) {
- JSONObject t = tmpls.getJSONObject(i);
+ long did = dids.get(nids);
+ if (did == 0) {
+ did = model.getLong("did");
+ }
+ // add any missing cards
+ for (JSONObject t : _tmplsFromOrds(model, avail)) {
int tord = t.getInt("ord");
- boolean doHave = have.containsKey(nid)
- && have.get(nid).containsKey(tord);
- // if have ord but empty, add cid to remove list
- // (may not have nid if generating before any cards added)
- if (doHave && !avail.contains(tord)) {
- rem.add(have.get(nid).get(tord));
- }
- // if missing ord and is available, generate
- if (!doHave && avail.contains(tord)) {
+ boolean doHave = have.containsKey(nid) && have.get(nid).containsKey(tord);
+ if (!doHave) {
+ // check deck is not a cram deck
+ long ndid = t.getLong("did");
+ if (ndid != 0) {
+ did = ndid;
+ }
+ if (getDecks().isDyn(did)) {
+ }
// 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, nextID("pos") });
ts += 1;
}
}
+ // note any cards that need removing
+ if (have.containsKey(nids)) {
+ for (Map.Entry<Integer, Long> n : have.get(nid).entrySet()) {
+ if (!avail.contains(n.getKey())) {
+ rem.add(n.getValue());
+ }
+ }
+ }
}
} catch (JSONException e) {
throw new RuntimeException(e);
@@ -625,7 +662,7 @@ public int _dueForDid(long did, int due) {
// the same random number
Random r = new Random();
r.setSeed(due);
- return r.nextInt((int) Math.pow(2, 32) - 2) + 1;
+ return r.nextInt(Math.max(due, 1000) - 1) + 1;
}
} catch (JSONException e) {
throw new RuntimeException(e);
@@ -667,15 +704,8 @@ public void remCards(long[] ids) {
_remNotes(nids);
}
- public void remEmptyCards(long[] ids) {
- if (ids.length == 0) {
- return;
- }
- // TODO: ask user
- if (true) {
- remCards(ids);
- }
- }
+ // emptyCids
+ // emptyCardReport
/**
* Field checksums and sorting fields
@@ -763,8 +793,13 @@ public void updateFieldCache(long[] nids) {
try {
fields.put("Type", (String) model.get("name"));
fields.put("Deck", mDecks.name((Long) data[3]));
- JSONObject template = model.getJSONArray("tmpls").getJSONObject(
- (Integer) data[4]);
+ JSONObject template;
+ if (model.getInt("type") == Sched.MODEL_STD) {
+ template = model.getJSONArray("tmpls").getJSONObject(
+ (Integer) data[4]);
+ } else {
+ template = model.getJSONArray("tmpls").getJSONObject(0);
+ }
fields.put("Card", template.getString("name"));
Models.fieldParser fparser = new Models.fieldParser(fields);
// render q & a
@@ -1034,6 +1069,11 @@ public long fixIntegrity() {
}
// new card position
mConf.put("nextPos", mDb.queryScalar("SELECT max(due) + 1 FROM cards WHERE type = 0", false));
+ // reviews should have a reasonable due
+ ids = mDb.queryColumn(Long.class, "SELECT id FROM cards WHERE queue = 2 AND due > 10000", 0);
+ if (ids.size() > 0) {
+ mDb.execute("UPDATE cards SET due = 0, mod = " + Utils.intNow() + ", usn = " + usn() + " WHERE id IN " + Utils.ids2str(Utils.arrayList2array(ids)));
+ }
mDb.getDatabase().setTransactionSuccessful();
} catch (JSONException e) {
throw new RuntimeException(e);
View
29 src/com/ichi2/libanki/Decks.java
@@ -455,13 +455,32 @@ public void setConf(JSONObject deck, long id) {
*/
public String name(long did) {
+ return name(did, false);
+ }
+ public String name(long did, boolean def) {
try {
- return get(did).getString("name");
+ JSONObject deck = get(did, def);
+ if (deck != null) {
+ return deck.getString("name");
+ }
+ return "[no deck]";
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
+ public String nameOrNone(long did) {
+ JSONObject deck = get(did, false);
+ if (deck != null) {
+ try {
+ return deck.getString("name");
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return null;
+ }
+
public void setDeck(long[] cids, long did) {
mCol.getDb()
.getDatabase()
@@ -630,6 +649,14 @@ public long newDyn(String name) {
return did;
}
+ public boolean isDyn(long did) {
+ try {
+ return get(did).getInt("dyn") != 0;
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
public String getActualDescription() {
try {
View
69 src/com/ichi2/libanki/Models.java
@@ -55,7 +55,8 @@
"'latexPost': \"\\\\end{document}\", " +
"'mod': 9, " +
"'usn': 9, " +
- "'vers': [] }";
+ "'vers': [], " +
+ "'type': " + Sched.MODEL_STD + "}";
private static final String defaultField =
"{'name': \"\", " +
@@ -566,7 +567,6 @@ public void _updateTemplOrds(JSONObject m) {
private void _syncTemplates(JSONObject m) {
ArrayList<Long> rem = mCol.genCards(Utils.arrayList2array(nids(m)));
- mCol.remEmptyCards(Utils.arrayList2array(rem));
}
@@ -599,10 +599,10 @@ private void _syncTemplates(JSONObject m) {
Template[] t = new Template[2];
try {
template = model.getJSONArray("tmpls").getJSONObject(ord);
- String format = template.getString("qfmt").replace("cloze:", "cq:");
+ String format = template.getString("qfmt").replace("{{cloze:", "{{cq:" + (ord+1) + ":");
Log.i(AnkiDroidApp.TAG, "Compiling question template \"" + format + "\"");
t[0] = Mustache.compiler().compile(format);
- format = template.getString("afmt").replace("cloze:", "ca:");
+ format = template.getString("afmt").replace("{{cloze:", "{{ca:" + (ord+1) + ":");
Log.i(AnkiDroidApp.TAG, "Compiling answer template \"" + format + "\"");
t[1] = Mustache.compiler().compile(format);
} catch (JSONException e) {
@@ -764,31 +764,29 @@ public Object get (Object ctx, String name) throws Exception {
*/
private void _updateRequired(JSONObject m) {
- JSONArray req = new JSONArray();
- ArrayList<String> flds = new ArrayList<String>();
- JSONArray fields;
try {
+ if (m.getInt("type") == Sched.MODEL_CLOZE) {
+ // nothing to do
+ return;
+ }
+ JSONArray req = new JSONArray();
+ ArrayList<String> flds = new ArrayList<String>();
+ JSONArray fields;
fields = m.getJSONArray("flds");
for (int i = 0; i < fields.length(); i++) {
flds.add(fields.getJSONObject(i).getString("name"));
}
- boolean cloze = false;
JSONArray templates = m.getJSONArray("tmpls");
for (int i = 0; i < templates.length(); i++) {
JSONObject t = templates.getJSONObject(i);
Object[] ret = _reqForTemplate(m, flds, t);
- if (((JSONArray)ret[2]).length() > 0) {
- cloze = true;
- }
JSONArray r = new JSONArray();
r.put(t.getInt("ord"));
r.put(ret[0]);
r.put(ret[1]);
- r.put(ret[2]);
req.put(r);
}
m.put("req", req);
- m.put("cloze", cloze);
} catch (JSONException e) {
throw new RuntimeException(e);
}
@@ -798,14 +796,8 @@ private void _updateRequired(JSONObject m) {
try {
ArrayList<String> a = new ArrayList<String> ();
ArrayList<String> b = new ArrayList<String> ();
- String cloze = "";
- JSONArray reqstrs = new JSONArray();
- if (t.has("cloze")) {
- // need a cloze-specific filler
- // TODO
- }
for (String f : flds) {
- a.add(cloze.length() > 0 ? cloze : "1");
+ b.add("1");
b.add("");
}
Object[] data;
@@ -832,7 +824,7 @@ private void _updateRequired(JSONObject m) {
}
}
if (req.length() > 0) {
- return new Object[] {type, req, reqstrs};
+ return new Object[] {type, req};
}
// if there are no required fields, switch to any mode
type = "any";
@@ -848,7 +840,7 @@ private void _updateRequired(JSONObject m) {
req.put(i);
}
}
- return new Object[]{ type, req, reqstrs};
+ return new Object[]{ type, req };
} catch (JSONException e) {
throw new RuntimeException(e);
}
@@ -857,12 +849,15 @@ private void _updateRequired(JSONObject m) {
/** Given a joined field string, return available template ordinals */
public ArrayList<Integer> availOrds(JSONObject m, String flds) {
- String[] fields = Utils.splitFields(flds);
- for (String f : fields) {
- f = f.trim();
- }
- ArrayList<Integer> avail = new ArrayList<Integer>();
try {
+ if (m.getInt("type") == Sched.MODEL_CLOZE) {
+ return _availClozeOrds(m, flds);
+ }
+ String[] fields = Utils.splitFields(flds);
+ for (String f : fields) {
+ f = f.trim();
+ }
+ ArrayList<Integer> avail = new ArrayList<Integer>();
JSONArray reqArray = m.getJSONArray("req");
for (int i = 0; i < reqArray.length(); i++) {
JSONArray sr = reqArray.getJSONArray(i);
@@ -902,26 +897,18 @@ private void _updateRequired(JSONObject m) {
continue;
}
}
- // extra cloze requirement?
- boolean ok = true;
- for (int j = 0; j < reqstrs.length(); j++) {
- if (!flds.matches(reqstrs.getString(i))) {
- // required cloze string was missing
- ok = false;
- break;
- }
- }
- if (!ok) {
- continue;
- }
avail.add(ord);
}
+ return avail;
} catch (JSONException e) {
throw new RuntimeException(e);
}
- return avail;
}
-
+
+ private ArrayList<Integer> _availClozeOrds(JSONObject m, String flds) {
+ // TODO
+ return null;
+ }
/**
* Sync handling
View
59 src/com/ichi2/libanki/Sched.java
@@ -84,6 +84,10 @@
public static final int DYN_ADDED = 6;
public static final int DYN_DUE = 7;
+ // model types
+ public static final int MODEL_STD = 0;
+ public static final int MODEL_CLOZE = 1;
+
private static final String[] REV_ORDER_STRINGS = { "ivl DESC", "ivl" };
private static final int[] FACTOR_ADDITION_VALUES = { -150, 0, 150 };
@@ -234,11 +238,22 @@ public int countIdx(Card card) {
return card.getQueue();
}
- public boolean lrnButtons(Card card) {
+ public int answerButtons(Card card) {
+ if (card.getODid() == 0 && card.getODue() != 0) {
+ JSONObject conf = _lapseConf(card);
+ try {
+ if (conf.getJSONArray("delays").length() > 1) {
+ return 3;
+ }
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ return 2;
+ }
if (card.getQueue() == 2) {
- return false;
+ return 4;
} else {
- return true;
+ return 3;
}
}
@@ -451,6 +466,7 @@ private int _walkingCount(LinkedList<Long> dids, Method limFn, Method cntFn) {
public ArrayList<Object[]> deckDueList(boolean counts) {
// DIFFERS FROM LIBANKI: finds all decks
+ _checkDay();
ArrayList<Object[]> dids = new ArrayList<Object[]>();
for (JSONObject g : mCol.getDecks().all()) {
try {
@@ -1029,7 +1045,7 @@ private void _rescheduleAsRev(Card card, JSONObject conf, boolean early) {
private int _startingLeft(Card card) {
try {
- JSONObject conf = _newConf(card);
+ JSONObject conf = _lrnConf(card);
return conf.getJSONArray("delays").length();
} catch (JSONException e) {
throw new RuntimeException(e);
@@ -1457,7 +1473,17 @@ private void rebuildDyn(long did) {
}
public void remDyn(long did) {
- mCol.getDb().execute("UPDATE cards SET did = odid, queue = type, odue = 0, odid = 0, usn = " + mCol.usn() + ", mod = " + Utils.intNow() + " WHERE did = " + did);
+ remDyn(did, null);
+ }
+ public void remDyn(long did, String lim) {
+ if (lim == null) {
+ lim = "did = " + did;
+ }
+ mCol.getDb().execute("UPDATE cards SET did = odid, queue = type, odue = 0, odid = 0, usn = " + mCol.usn() + ", mod = " + Utils.intNow() + " WHERE " + lim);
+ }
+
+ public void remFromDyn(long[] cids) {
+ remDyn(0, "id IN " + Utils.ids2str(cids) + " AND odid");
}
private String _dynOrder(JSONObject deck) {
@@ -1667,24 +1693,17 @@ public void _updateCutoff() {
for (JSONObject d : mCol.getDecks().all()) {
update(d);
}
-// // update all selected decks
-// for (long did : mCol.getDecks().active()) {
-// update(mCol.getDecks().get(did));
-// }
-// // update parents too
-// for (JSONObject grp : mCol.getDecks().parents(
-// mCol.getDecks().selected())) {
-// update(grp);
-// }
+ // update all daily counts, but don't save decks to prevent needless conflicts. we'll save on card answer instead
+ for (JSONObject deck : mCol.getDecks().all()) {
+ update(deck);
+ }
}
private void update(JSONObject g) {
- boolean save = false;
for (String t : new String[] { "new", "rev", "lrn", "time" }) {
String k = t + "Today";
try {
if (g.getJSONArray(k).getInt(0) != mToday) {
- save = true;
JSONArray ja = new JSONArray();
ja.put(mToday);
ja.put(0);
@@ -1694,9 +1713,6 @@ private void update(JSONObject g) {
throw new RuntimeException(e);
}
}
- if (save) {
- mCol.getDecks().save(g);
- }
}
public boolean _checkDay() {
@@ -1851,6 +1867,8 @@ private int _nextLrnIvl(Card card, int ease) {
* Suspend cards.
*/
public void suspendCards(long[] ids) {
+ remFromDyn(ids);
+ removeFailed(ids);
mCol.getDb().execute("UPDATE cards SET queue = -1, mod = " + Utils.intNow()
+ ", usn = " + mCol.usn() + " WHERE id IN "
+ Utils.ids2str(ids));
@@ -1872,6 +1890,9 @@ public void unsuspendCards(long[] ids) {
*/
public void buryNote(long nid) {
mCol.setDirty();
+ long[] cids = Utils.arrayList2array(mCol.getDb().queryColumn(Long.class, "SELECT id FROM cards WHERE nid = " + nid, 0));
+ remFromDyn(cids);
+ removeFailed(cids);
mCol.getDb().execute("UPDATE cards SET queue = -2 WHERE nid = " + nid);
}
View
6 src/com/ichi2/widget/AnkiDroidWidgetBig.java
@@ -246,7 +246,7 @@ private CharSequence getNextTimeString(Card card) {
again.setSpan(new ForegroundColorSpan(sColorRed), 0, again.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- if (contentService.mCol.getSched().lrnButtons(card)) {
+ if (contentService.mCol.getSched().answerButtons(card) == 3) {
hard.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.widget_big_font_color_green)), 0, hard.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
easy.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.widget_big_font_color)), 0, easy.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
@@ -262,7 +262,7 @@ private CharSequence getNextTimeString(Card card) {
sb.append(hard);
sb.append(" \u2027 ");
sb.append(easy);
- if (!contentService.mCol.getSched().lrnButtons(card)) {
+ if (contentService.mCol.getSched().answerButtons(card) == 4) {
sb.append(" \u2027 ");
sb.append(veryEasy);
}
@@ -718,7 +718,7 @@ private synchronized RemoteViews buildUpdate(Context context) {
updateViews.setOnClickPendingIntent(R.id.widget_big_bottomleft, getAnswerPendingIntent(this, 1));
- if (!contentService.mCol.getSched().lrnButtons(contentService.mCurrentCard)) {
+ if (contentService.mCol.getSched().answerButtons(contentService.mCurrentCard) == 4) {
updateViews.setViewVisibility(R.id.widget_big_ease2_normal, View.INVISIBLE);
updateViews.setViewVisibility(R.id.widget_big_ease2_rec, View.VISIBLE);
updateViews.setViewVisibility(R.id.widget_big_ease3_normal, View.INVISIBLE);

0 comments on commit fdb5103

Please sign in to comment.
Something went wrong with that request. Please try again.