use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class SelfStudyActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// FIXME:
Timber.d("onActivityResult(requestCode=%d, resultCode=%d)", requestCode, resultCode);
if (data != null) {
Timber.d("onActivityResult data (reloadRequired=%s, noteChanged=%s)", data.getBooleanExtra("reloadRequired", false), data.getBooleanExtra("noteChanged", false));
}
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == DeckPicker.RESULT_DB_ERROR) {
closeCardBrowser(DeckPicker.RESULT_DB_ERROR);
}
if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
Timber.i("CardBrowser:: CardBrowser: Saving card...");
CollectionTask.launchCollectionTask(UPDATE_NOTE, updateCardHandler(), new TaskData(sCardBrowserCard, false));
} else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
if (mSearchView != null) {
mSearchTerms = mSearchView.getQuery().toString();
searchCards();
} else {
Timber.w("Note was added from browser and on return mSearchView == null");
}
}
// }
if (requestCode == PREVIEW_CARDS && data != null && (data.getBooleanExtra("reloadRequired", false) || data.getBooleanExtra("noteChanged", false))) {
searchCards();
if (getReviewerCardId() == mCurrentCardId) {
mReloadRequired = true;
}
}
if (requestCode == EDIT_CARD && data != null && (data.getBooleanExtra("reloadRequired", false) || data.getBooleanExtra("noteChanged", false))) {
// if reloadRequired or noteChanged flag was sent from note editor then reload card list
searchCards();
// in use by reviewer?
if (getReviewerCardId() == mCurrentCardId) {
mReloadRequired = true;
}
}
// maybe the availability of undo changed
invalidateOptionsMenu();
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class CardContentProvider method buryOrSuspendCard.
private void buryOrSuspendCard(Collection col, AbstractSched sched, Card card, boolean bury) {
try {
DB db = col.getDb();
db.getDatabase().beginTransaction();
try {
if (card != null) {
if (bury) {
// bury
sched.buryCards(new long[] { card.getId() });
} else {
// suspend
sched.suspendCards(new long[] { card.getId() });
}
}
db.getDatabase().setTransactionSuccessful();
} finally {
db.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Timber.e(e, "buryOrSuspendCard - RuntimeException on burying or suspending card");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundBurySuspendCard");
return;
}
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class CardContentProvider method getCard.
private Card getCard(long noteId, int ord, Collection col) {
Note currentNote = col.getNote(noteId);
Card currentCard = null;
for (Card card : currentNote.cards()) {
if (card.getOrd() == ord) {
currentCard = card;
}
}
if (currentCard == null) {
throw new IllegalArgumentException("Card with ord " + ord + " does not exist for note " + noteId);
}
return currentCard;
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class CardContentProvider method answerCard.
private void answerCard(Collection col, AbstractSched sched, Card cardToAnswer, @Consts.BUTTON_TYPE int ease, long timeTaken) {
try {
DB db = col.getDb();
db.getDatabase().beginTransaction();
try {
if (cardToAnswer != null) {
if (timeTaken != -1) {
cardToAnswer.setTimerStarted(col.getTime().intTime() - timeTaken / 1000);
}
sched.answerCard(cardToAnswer, ease);
}
db.getDatabase().setTransactionSuccessful();
} finally {
db.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Timber.e(e, "answerCard - RuntimeException on answering card");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
return;
}
}
use of com.ichi2.anki.CardBrowser.Column.CARD in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundAnswerCard.
private TaskData doInBackgroundAnswerCard(TaskData param) {
Collection col = getCol();
AbstractSched sched = col.getSched();
Card oldCard = param.getCard();
@Consts.BUTTON_TYPE int ease = param.getInt();
Card newCard = null;
Timber.i(oldCard != null ? "Answering card" : "Obtaining card");
try {
DB db = col.getDb();
db.getDatabase().beginTransaction();
try {
if (oldCard != null) {
Timber.i("Answering card %d", oldCard.getId());
sched.answerCard(oldCard, ease);
}
newCard = sched.getCard();
if (newCard != null) {
// render cards before locking database
newCard._getQA(true);
}
publishProgress(new TaskData(newCard));
db.getDatabase().setTransactionSuccessful();
} finally {
db.getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Timber.e(e, "doInBackgroundAnswerCard - RuntimeException on answering card");
AnkiDroidApp.sendExceptionReport(e, "doInBackgroundAnswerCard");
return new TaskData(false);
}
return new TaskData(true);
}
Aggregations