use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class SchedV2 method _checkLeech.
/*
Leeches ****************************************************************** *****************************
*/
/**
* Leech handler. True if card was a leech.
* Overridden: in V1, due and did are changed
*/
protected boolean _checkLeech(@NonNull Card card, @NonNull JSONObject conf) {
int lf = conf.getInt("leechFails");
if (lf == 0) {
return false;
}
// if over threshold or every half threshold reps after that
if (card.getLapses() >= lf && (card.getLapses() - lf) % Math.max(lf / 2, 1) == 0) {
// add a leech tag
Note n = card.note();
n.addTag("leech");
n.flush();
// handle
if (conf.getInt("leechAction") == Consts.LEECH_SUSPEND) {
card.setQueue(Consts.QUEUE_TYPE_SUSPENDED);
}
// notify UI
if (mContextReference != null) {
Activity context = mContextReference.get();
leech(card, context);
}
return true;
}
return false;
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class ReviewerNoParamTest method whiteboardPenColorChangeChangesDatabaseLight.
@Test
public void whiteboardPenColorChangeChangesDatabaseLight() {
Whiteboard whiteboard = startReviewerForWhiteboard();
whiteboard.setPenColor(ARBITRARY_PEN_COLOR_VALUE);
WhiteboardPenColor penColor = getPenColor();
assertThat("Light pen color is changed", penColor.getLightPenColor(), is(ARBITRARY_PEN_COLOR_VALUE));
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class NoteServiceTest method importAudioWithSameNameTest.
/**
* Tests if after importing:
*
* * New file keeps its name
* * File with same name, but different content, has its name changed
* * File with same name and content don't have its name changed
*
* @throws IOException if new created files already exist on temp directory
*/
@Test
public void importAudioWithSameNameTest() throws IOException {
File f1 = directory.newFile("audio.mp3");
File f2 = directory2.newFile("audio.mp3");
// write a line in the file so the file's length isn't 0
try (FileWriter fileWriter = new FileWriter(f1)) {
fileWriter.write("1");
}
// do the same to the second file, but with different data
try (FileWriter fileWriter = new FileWriter(f2)) {
fileWriter.write("2");
}
MediaClipField fld1 = new MediaClipField();
fld1.setAudioPath(f1.getAbsolutePath());
MediaClipField fld2 = new MediaClipField();
fld2.setAudioPath(f2.getAbsolutePath());
// third field to test if name is kept after reimporting the same file
MediaClipField fld3 = new MediaClipField();
fld3.setAudioPath(f1.getAbsolutePath());
NoteService.importMediaToDirectory(mTestCol, fld1);
File o1 = new File(mTestCol.getMedia().dir(), f1.getName());
NoteService.importMediaToDirectory(mTestCol, fld2);
File o2 = new File(mTestCol.getMedia().dir(), f2.getName());
NoteService.importMediaToDirectory(mTestCol, fld3);
// creating a third outfile isn't necessary because it should be equal to the first one
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld1.getAudioPath());
assertNotEquals("path should be different to the new file made in NoteService.importMediaToDirectory", o2.getAbsolutePath(), fld2.getAudioPath());
assertEquals("path should be equal to the new file made in NoteService.importMediaToDirectory", o1.getAbsolutePath(), fld3.getAudioPath());
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class ContentProviderTest method testAnswerCard.
/**
* Test giving the answer for a reviewed card
*/
@Test
public void testAnswerCard() {
Collection col = getCol();
Card card = getFirstCardFromScheduler(col);
long cardId = card.getId();
// the card starts out being new
assertEquals("card is initial new", Consts.CARD_TYPE_NEW, card.getQueue());
ContentResolver cr = getContentResolver();
Uri reviewInfoUri = FlashCardsContract.ReviewInfo.CONTENT_URI;
ContentValues values = new ContentValues();
long noteId = card.note().getId();
int cardOrd = card.getOrd();
int earlyGraduatingEase = (schedVersion == 1) ? AbstractFlashcardViewer.EASE_3 : AbstractFlashcardViewer.EASE_4;
// 5 seconds
long timeTaken = 5000;
values.put(FlashCardsContract.ReviewInfo.NOTE_ID, noteId);
values.put(FlashCardsContract.ReviewInfo.CARD_ORD, cardOrd);
values.put(FlashCardsContract.ReviewInfo.EASE, earlyGraduatingEase);
values.put(FlashCardsContract.ReviewInfo.TIME_TAKEN, timeTaken);
int updateCount = cr.update(reviewInfoUri, values, null, null);
assertEquals("Check if update returns 1", 1, updateCount);
try {
Thread.currentThread().wait(500);
} catch (Exception e) {
/* do nothing */
}
col.reset();
Card newCard = col.getSched().getCard();
if (newCard != null) {
if (newCard.note().getId() == card.note().getId() && newCard.getOrd() == card.getOrd()) {
fail("Next scheduled card has not changed");
}
}
// lookup the card after update, ensure it's not new anymore
Card cardAfterReview = col.getCard(cardId);
assertEquals("card is now type rev", Card.TYPE_REV, cardAfterReview.getQueue());
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by ankidroid.
the class ContentProviderTest method testQueryCardFromCertainDeck.
/**
* Test that query for the next card in the schedule returns a valid result WITH a deck selector
*/
@Test
public synchronized void testQueryCardFromCertainDeck() {
long deckToTest = mTestDeckIds.get(0);
String deckSelector = "deckID=?";
String[] deckArguments = { Long.toString(deckToTest) };
Collection col = getCol();
AbstractSched sched = col.getSched();
long selectedDeckBeforeTest = col.getDecks().selected();
// select Default deck
col.getDecks().select(1);
Cursor reviewInfoCursor = getContentResolver().query(FlashCardsContract.ReviewInfo.CONTENT_URI, null, deckSelector, deckArguments, null);
assertNotNull(reviewInfoCursor);
assertEquals("Check that we actually received one card", 1, reviewInfoCursor.getCount());
try {
reviewInfoCursor.moveToFirst();
int cardOrd = reviewInfoCursor.getInt(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.CARD_ORD));
long noteID = reviewInfoCursor.getLong(reviewInfoCursor.getColumnIndex(FlashCardsContract.ReviewInfo.NOTE_ID));
assertEquals("Check that the selected deck has not changed", 1, col.getDecks().selected());
col.getDecks().select(deckToTest);
Card nextCard = null;
for (int i = 0; i < 10; i++) {
// minimizing fails, when sched.reset() randomly chooses between multiple cards
col.reset();
nextCard = sched.getCard();
if (nextCard != null && nextCard.note().getId() == noteID && nextCard.getOrd() == cardOrd)
break;
// Reset counts is executed in background.
try {
Thread.sleep(500);
} catch (Exception e) {
Timber.e(e);
}
}
assertNotNull("Check that there actually is a next scheduled card", nextCard);
assertEquals("Check that received card and actual card have same note id", nextCard.note().getId(), noteID);
assertEquals("Check that received card and actual card have same card ord", nextCard.getOrd(), cardOrd);
} finally {
reviewInfoCursor.close();
}
col.getDecks().select(selectedDeckBeforeTest);
}
Aggregations