From 6bd5a92cb4c90a13320b7c7254e15ca9679fac6e Mon Sep 17 00:00:00 2001 From: Houssam Salem Date: Tue, 22 Oct 2013 20:57:58 +1100 Subject: [PATCH 1/5] add separate is:buried and use with filtered deck (dae/anki cf51f33) --- src/com/ichi2/libanki/Finder.java | 4 +++- src/com/ichi2/libanki/Sched.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/com/ichi2/libanki/Finder.java b/src/com/ichi2/libanki/Finder.java index 0561f4bc7e..0041761622 100644 --- a/src/com/ichi2/libanki/Finder.java +++ b/src/com/ichi2/libanki/Finder.java @@ -463,7 +463,9 @@ private String _findCardState(String val) { } return "type = " + n; } else if (val.equals("suspended")) { - return "c.queue in (-1, -2)"; + return "c.queue = -1"; + } else if (val.equals("buried")) { + return "c.queue = -2"; } else if (val.equals("due")) { return "(c.queue in (2,3) and c.due <= " + mCol.getSched().getToday() + ") or (c.queue = 1 and c.due <= " + mCol.getSched().getDayCutoff() + ")"; diff --git a/src/com/ichi2/libanki/Sched.java b/src/com/ichi2/libanki/Sched.java index e79f53e4ca..e463fe2199 100644 --- a/src/com/ichi2/libanki/Sched.java +++ b/src/com/ichi2/libanki/Sched.java @@ -1595,7 +1595,7 @@ private List _fillDyn(JSONObject deck) { int limit = terms.getInt(1); int order = terms.getInt(2); String orderlimit = _dynOrder(order, limit); - search += " -is:suspended -deck:filtered"; + search += " -is:suspended -is:buried -deck:filtered"; ids = mCol.findCards(search, orderlimit); if (ids.isEmpty()) { return ids; From 64f065515ed839d225bbc636c4954a142bcfb39b Mon Sep 17 00:00:00 2001 From: Houssam Salem Date: Tue, 22 Oct 2013 21:53:59 +1100 Subject: [PATCH 2/5] bury card option (dae/anki a9c9452) --- res/values/01-core.xml | 1 + src/com/ichi2/anki/Reviewer.java | 16 ++++++++++++---- src/com/ichi2/async/DeckTask.java | 8 ++++++++ src/com/ichi2/libanki/Collection.java | 5 +++++ src/com/ichi2/libanki/Sched.java | 15 ++++++++++----- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/res/values/01-core.xml b/res/values/01-core.xml index 66b6795f52..3e54f5e541 100644 --- a/res/values/01-core.xml +++ b/res/values/01-core.xml @@ -103,6 +103,7 @@ About Dismiss Note... +Bury Card Bury Note Suspend Card Suspend Note diff --git a/src/com/ichi2/anki/Reviewer.java b/src/com/ichi2/anki/Reviewer.java index 9953fc6cdb..819a01b1d2 100644 --- a/src/com/ichi2/anki/Reviewer.java +++ b/src/com/ichi2/anki/Reviewer.java @@ -165,7 +165,8 @@ public class Reviewer extends AnkiActivity { private static final int MENU_CLEAR_WHITEBOARD = 1; private static final int MENU_EDIT = 2; private static final int MENU_REMOVE = 3; - private static final int MENU_REMOVE_BURY = 31; + private static final int MENU_REMOVE_BURY_CARD = 30; + private static final int MENU_REMOVE_BURY_NOTE = 31; private static final int MENU_REMOVE_SUSPEND_CARD = 32; private static final int MENU_REMOVE_SUSPEND_NOTE = 33; private static final int MENU_REMOVE_DELETE = 34; @@ -1228,7 +1229,8 @@ public boolean onCreateOptionsMenu(Menu menu) { SubMenu removeDeckSubMenu = menu.addSubMenu(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.menu_dismiss_note); removeDeckSubMenu.setIcon(R.drawable.ic_menu_stop); - removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY, Menu.NONE, R.string.menu_bury_note); + removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_CARD, Menu.NONE, R.string.menu_bury_card); + removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_BURY_NOTE, Menu.NONE, R.string.menu_bury_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_CARD, Menu.NONE, R.string.menu_suspend_card); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_SUSPEND_NOTE, Menu.NONE, R.string.menu_suspend_note); removeDeckSubMenu.add(Menu.NONE, MENU_REMOVE_DELETE, Menu.NONE, R.string.menu_delete_note); @@ -1403,8 +1405,14 @@ public boolean onOptionsItemSelected(MenuItem item) { case MENU_EDIT: return editCard(); - - case MENU_REMOVE_BURY: + + case MENU_REMOVE_BURY_CARD: + setNextCardAnimation(false); + DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData( + mSched, mCurrentCard, 4)); + return true; + + case MENU_REMOVE_BURY_NOTE: setNextCardAnimation(false); DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData( mSched, mCurrentCard, 0)); diff --git a/src/com/ichi2/async/DeckTask.java b/src/com/ichi2/async/DeckTask.java index 64b93b5f4c..6ed2b45419 100644 --- a/src/com/ichi2/async/DeckTask.java +++ b/src/com/ichi2/async/DeckTask.java @@ -558,6 +558,14 @@ private TaskData doInBackgroundDismissNote(TaskData... params) { col.getDb().getDatabase().beginTransaction(); try { switch (type) { + case 4: + // collect undo information + col.markUndo(Collection.UNDO_BURY_CARD, + new Object[] { col.getDirty(), note.cards(), card.getId() }); + // then bury + sched.buryCards(new long[]{ card.getId() }); + sHadCardQueue = true; + break; case 0: // collect undo information col.markUndo(Collection.UNDO_BURY_NOTE, diff --git a/src/com/ichi2/libanki/Collection.java b/src/com/ichi2/libanki/Collection.java index 8f4257a1c6..c3afe8c12c 100644 --- a/src/com/ichi2/libanki/Collection.java +++ b/src/com/ichi2/libanki/Collection.java @@ -111,6 +111,8 @@ public class Collection { public static final int UNDO_SUSPEND_NOTE = 4; public static final int UNDO_DELETE_NOTE = 5; public static final int UNDO_MARK_NOTE = 6; + public static final int UNDO_BURY_CARD = 7; + private static final int[] fUndoNames = new int[]{ R.string.undo_action_review, R.string.undo_action_edit, @@ -1261,6 +1263,9 @@ public void markUndo(int type, Object[] o) { case UNDO_EDIT_NOTE: mUndo.add(new Object[]{type, ((Note)o[0]).clone(), o[1], o[2]}); break; + case UNDO_BURY_CARD: + mUndo.add(new Object[]{type, o[0], o[1], o[2]}); + break; case UNDO_BURY_NOTE: mUndo.add(new Object[]{type, o[0], o[1], o[2]}); break; diff --git a/src/com/ichi2/libanki/Sched.java b/src/com/ichi2/libanki/Sched.java index e463fe2199..7be3cacd13 100644 --- a/src/com/ichi2/libanki/Sched.java +++ b/src/com/ichi2/libanki/Sched.java @@ -2096,8 +2096,15 @@ public void unsuspendCards(long[] ids) { "UPDATE cards SET queue = type, mod = " + Utils.intNow() + ", usn = " + mCol.usn() + " WHERE queue = -1 AND id IN " + Utils.ids2str(ids)); } - - + + + public void buryCards(long[] cids) { + removeLrn(cids); + mCol.getDb().execute("update cards set queue=-2,mod=?,usn=? where id in " + Utils.ids2str(cids), + new Object[]{Utils.now(), mCol.usn()}); + } + + /** * Bury all cards for note until next session. * @param nid The id of the targetted note. @@ -2105,9 +2112,7 @@ public void unsuspendCards(long[] ids) { public void buryNote(long nid) { long[] cids = Utils.arrayList2array(mCol.getDb().queryColumn(Long.class, "SELECT id FROM cards WHERE nid = " + nid + " AND queue >= 0", 0)); - removeLrn(cids); - mCol.getDb().execute("update cards set queue=-2,mod=?,usn=? where id in " + Utils.ids2str(cids), - new Object[]{Utils.now(), mCol.usn()}); + buryCards(cids); } /** From aa2ac2bf1f3e88fe20a64d64b95001c5846c75dd Mon Sep 17 00:00:00 2001 From: Houssam Salem Date: Tue, 22 Oct 2013 21:54:38 +1100 Subject: [PATCH 3/5] Fix missing parameter in forgetCards query. --- src/com/ichi2/libanki/Sched.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/ichi2/libanki/Sched.java b/src/com/ichi2/libanki/Sched.java index 7be3cacd13..00b87f4608 100644 --- a/src/com/ichi2/libanki/Sched.java +++ b/src/com/ichi2/libanki/Sched.java @@ -2166,7 +2166,7 @@ private void _burySiblings(Card card) { /** Put cards at the end of the new queue. */ public void forgetCards(long[] ids) { - mCol.getDb().execute("update cards set type=0,queue=0,ivl=0,due=0,factor=? where odid=0 "+ + mCol.getDb().execute("update cards set type=0,queue=0,ivl=0,due=0,factor=2500 where odid=0 "+ "and queue >= 0 and id in " + Utils.ids2str(ids)); int pmax = mCol.getDb().queryScalar("SELECT max(due) FROM cards WHERE type=0", false); // takes care of mod + usn From 92d14c6e2a080c7096b2536df48f93b7c8632929 Mon Sep 17 00:00:00 2001 From: Houssam Salem Date: Wed, 23 Oct 2013 01:00:44 +1100 Subject: [PATCH 4/5] Added new burying options in option groups Also removed the now unused sibling settings. --- res/values/10-preferences.xml | 8 ++++---- res/xml/deck_options.xml | 23 ++++++++--------------- src/com/ichi2/anki/DeckOptions.java | 15 ++++++--------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/res/values/10-preferences.xml b/res/values/10-preferences.xml index 501c9cd10b..624d0b4f4a 100644 --- a/res/values/10-preferences.xml +++ b/res/values/10-preferences.xml @@ -270,12 +270,12 @@ XXX day(s) Easy interval Starting ease -Siblings -Try not to show sibling cards next to each other Maximum reviews/day -Space siblings by up to +Bury related new cards +Related new cards are buried until the next day +Bury related reviews +Related reviews are buried until the next day Easy bonus -Minimum sibling range Interval modifier Maximum interval New interval diff --git a/res/xml/deck_options.xml b/res/xml/deck_options.xml index 3b214ee93a..02ca5bfa66 100644 --- a/res/xml/deck_options.xml +++ b/res/xml/deck_options.xml @@ -62,9 +62,9 @@ app:min="100" /> + android:key="newBury" + android:summary="@string/deck_conf_new_bury_summ" + android:title="@string/deck_conf_new_bury" /> - - + Date: Wed, 23 Oct 2013 01:39:26 +1100 Subject: [PATCH 5/5] Add unbury option to congrats screen and fix unbury query. The "back to study screen" button was removed in this commit to make space for the unbury button. It was not very useful in the first place as it duplicated the function of the back button. --- res/layout/studyoptions_congrats.xml | 12 +++++------ res/values/01-core.xml | 3 ++- src/com/ichi2/anki/StudyOptionsFragment.java | 22 ++++++++++++-------- src/com/ichi2/libanki/Sched.java | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/res/layout/studyoptions_congrats.xml b/res/layout/studyoptions_congrats.xml index 9ecb1fe33b..51458a1452 100644 --- a/res/layout/studyoptions_congrats.xml +++ b/res/layout/studyoptions_congrats.xml @@ -20,18 +20,18 @@ android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center" - android:id="@+id/studyoptions_congrats_open_other_deck" - android:text="@string/studyoptions_congrats_open_other_deck" /> + android:id="@+id/studyoptions_congrats_unbury" + android:text="@string/unbury" />