use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundRenderBrowserQA.
private TaskData doInBackgroundRenderBrowserQA(TaskData param) {
// TODO: Convert this to accept the following to make thread-safe:
// (Range<Position>, Function<Position, BrowserCard>)
Timber.d("doInBackgroundRenderBrowserQA");
Collection col = getCol();
List<CardBrowser.CardCache> cards = (List<CardBrowser.CardCache>) param.getObjArray()[0];
Integer startPos = (Integer) param.getObjArray()[1];
Integer n = (Integer) param.getObjArray()[2];
int column1Index = (Integer) param.getObjArray()[3];
int column2Index = (Integer) param.getObjArray()[4];
List<Long> invalidCardIds = new ArrayList<>();
// for each specified card in the browser list
for (int i = startPos; i < startPos + n; i++) {
// Stop if cancelled
if (isCancelled()) {
Timber.d("doInBackgroundRenderBrowserQA was aborted");
return null;
}
if (i < 0 || i >= cards.size()) {
continue;
}
CardBrowser.CardCache card;
try {
card = cards.get(i);
} catch (IndexOutOfBoundsException e) {
// we won't reach any more cards.
continue;
}
if (card.isLoaded()) {
// We've already rendered the answer, we don't need to do it again.
continue;
}
// Extract card item
try {
// Ensure that card still exists.
card.getCard();
} catch (WrongId e) {
// #5891 - card can be inconsistent between the deck browser screen and the collection.
// Realistically, we can skip any exception as it's a rendering task which should not kill the
// process
long cardId = card.getId();
Timber.e(e, "Could not process card '%d' - skipping and removing from sight", cardId);
invalidCardIds.add(cardId);
continue;
}
// Update item
card.load(false, column1Index, column2Index);
float progress = (float) i / n * 100;
publishProgress(new TaskData((int) progress));
}
return new TaskData(new Object[] { cards, invalidCardIds });
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class CardTemplatePreviewerTest method testPreviewUnsavedTemplate.
@Test
public void testPreviewUnsavedTemplate() throws Exception {
String modelName = "Basic";
Model collectionBasicModelOriginal = getCurrentDatabaseModelCopy(modelName);
JSONObject template = collectionBasicModelOriginal.getJSONArray("tmpls").getJSONObject(0);
template.put("qfmt", template.getString("qfmt").concat("PREVIEWER_TEST"));
String tempModelPath = TemporaryModel.saveTempModel(getTargetContext(), collectionBasicModelOriginal);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(TemporaryModel.INTENT_MODEL_FILENAME, tempModelPath);
intent.putExtra("index", 0);
ActivityController<TestCardTemplatePreviewer> previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class, intent).create().start().resume().visible();
saveControllerForCleanup((previewerController));
TestCardTemplatePreviewer testCardTemplatePreviewer = (TestCardTemplatePreviewer) previewerController.get();
Assert.assertTrue("model change did not show up?", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Take it through a destroy/re-create lifecycle in order to test instance state persistence
Bundle outBundle = new Bundle();
previewerController.saveInstanceState(outBundle);
previewerController.pause().stop().destroy();
previewerController = Robolectric.buildActivity(TestCardTemplatePreviewer.class).create(outBundle).start().resume().visible();
saveControllerForCleanup(previewerController);
testCardTemplatePreviewer = (TestCardTemplatePreviewer) previewerController.get();
Assert.assertTrue("model change not preserved in lifecycle??", testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).q().contains("PREVIEWER_TEST") && testCardTemplatePreviewer.getDummyCard(collectionBasicModelOriginal, 0).a().contains("PREVIEWER_TEST"));
// Make sure we can click
Assert.assertFalse("Showing the answer already?", testCardTemplatePreviewer.getShowingAnswer());
testCardTemplatePreviewer.disableDoubleClickPrevention();
View showAnswerButton = testCardTemplatePreviewer.findViewById(R.id.preview_buttons_layout);
showAnswerButton.performClick();
Assert.assertTrue("Not showing the answer?", testCardTemplatePreviewer.getShowingAnswer());
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class ReviewerTest method jsTime4ShouldBeBlankIfButtonUnavailable.
@Test
public void jsTime4ShouldBeBlankIfButtonUnavailable() {
// #6623 - easy should be blank when displaying a card with 3 buttons (after displaying a review)
Note firstNote = addNoteUsingBasicModel("Hello", "World");
moveToReviewQueue(firstNote.firstCard());
addNoteUsingBasicModel("Hello", "World2");
Reviewer reviewer = startReviewer();
JavaScriptFunction javaScriptFunction = reviewer.javaScriptFunction();
// The answer needs to be displayed to be able to get the time.
displayAnswer(reviewer);
assertThat("4 buttons should be displayed", reviewer.getAnswerButtonCount(), is(4));
String nextTime = javaScriptFunction.ankiGetNextTime4();
assertThat(nextTime, not(isEmptyString()));
// Display the next answer
reviewer.answerCard(EASE_4);
displayAnswer(reviewer);
if (schedVersion == 1) {
assertThat("The 4th button should not be visible", reviewer.getAnswerButtonCount(), is(3));
String learnTime = javaScriptFunction.ankiGetNextTime4();
assertThat("If the 4th button is not visible, there should be no time4 in JS", learnTime, isEmptyString());
}
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_filt_reviewing_early_normal.
@Test
public void test_filt_reviewing_early_normal() throws Exception {
Collection col = getColV2();
Note note = col.newNote();
note.setItem("Front", "one");
col.addNote(note);
Card c = note.cards().get(0);
c.setIvl(100);
c.setQueue(CARD_TYPE_REV);
c.setType(QUEUE_TYPE_REV);
// due in 25 days, so it's been waiting 75 days
c.setDue(col.getSched().getToday() + 25);
c.setMod(1);
c.setFactor(STARTING_FACTOR);
c.startTimer();
c.flush();
col.reset();
assertArrayEquals(new int[] { 0, 0, 0 }, col.getSched().counts());
// create a dynamic deck and refresh it
long did = col.getDecks().newDyn("Cram");
col.getSched().rebuildDyn(did);
col.reset();
// should appear as normal in the deck list
/* todo sort
assertEquals(1, sorted(col.getSched().deckDueTree().getChildren())[0].review_count);
*/
// and should appear in the counts
assertArrayEquals(new int[] { 0, 0, 1 }, col.getSched().counts());
// grab it and check estimates
c = col.getSched().getCard();
assertEquals(4, col.getSched().answerButtons(c));
assertEquals(600, col.getSched().nextIvl(c, 1));
assertEquals(Math.round(75 * 1.2) * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertThat(col.getSched().nextIvl(c, 3), is((long) (75 * 2.5) * SECONDS_PER_DAY));
assertThat(col.getSched().nextIvl(c, 4), is((long) (75 * 2.5 * 1.15) * SECONDS_PER_DAY));
// answer 'good'
col.getSched().answerCard(c, 3);
checkRevIvl(col, c, 90);
assertEquals(col.getSched().getToday() + c.getIvl(), c.getDue());
assertEquals(0L, c.getODue());
// should not be in learning
assertEquals(QUEUE_TYPE_REV, c.getQueue());
// should be logged as a cram rep
assertEquals(3, col.getDb().queryLongScalar("select type from revlog order by id desc limit 1"));
// due in 75 days, so it's been waiting 25 days
c.setIvl(100);
c.setDue(col.getSched().getToday() + 75);
c.flush();
col.getSched().rebuildDyn(did);
col.reset();
c = col.getSched().getCard();
assertEquals(60 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 2));
assertEquals(100 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 3));
assertEquals(114 * SECONDS_PER_DAY, col.getSched().nextIvl(c, 4));
}
use of com.ichi2.anki.CardBrowser.Column.ANSWER in project AnkiChinaAndroid by ankichinateam.
the class SchedV2Test method test_new_v2.
@Test
public void test_new_v2() throws Exception {
Collection col = getColV2();
col.reset();
assertEquals(0, col.getSched().counts()[0]);
// add a note
Note note = col.newNote();
note.setItem("Front", "one");
note.setItem("Back", "two");
col.addNote(note);
col.reset();
assertEquals(1, col.getSched().counts()[0]);
// fetch it
Card c = col.getSched().getCard();
assertNotNull(c);
assertEquals(QUEUE_TYPE_NEW, c.getQueue());
assertEquals(CARD_TYPE_NEW, c.getType());
// if we answer it, it should become a learn card
long t = col.getTime().intTime();
col.getSched().answerCard(c, 1);
assertEquals(QUEUE_TYPE_LRN, c.getQueue());
assertEquals(CARD_TYPE_LRN, c.getType());
assertThat(c.getDue(), is(greaterThanOrEqualTo(t)));
// disabled for now, as the learn fudging makes this randomly fail
// // the default order should ensure siblings are not seen together, and
// // should show all cards
// Model m = col.getModels().current(); Models mm = col.getModels()
// JSONObject t = mm.newTemplate("Reverse")
// t['qfmt'] = "{{Back}}"
// t['afmt'] = "{{Front}}"
// mm.addTemplateModChanged(m, t)
// mm.save(m)
// note = col.newNote()
// note['Front'] = u"2"; note['Back'] = u"2"
// col.addNote(note)
// note = col.newNote()
// note['Front'] = u"3"; note['Back'] = u"3"
// col.addNote(note)
// col.reset()
// qs = ("2", "3", "2", "3")
// for (int n = 0; n < 4; n++) {
// c = col.getSched().getCard()
// assertTrue(qs[n] in c.q())
// col.getSched().answerCard(c, 2)
// }
}
Aggregations