use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.
the class CardBrowser method updateCardInList.
private void updateCardInList(Card card, String updatedCardTags) {
Note note = card.note();
int pos;
for (Card c : note.cards()) {
pos = getPosition(mCards, c.getId());
if (pos < 0 || pos >= mCards.size()) {
continue;
}
if (updatedCardTags != null) {
mCards.get(pos).put("tags", updatedCardTags);
}
String sfld = note.getSFld();
mCards.get(pos).put("sfld", sfld);
if (mWholeCollection) {
String deckName;
try {
deckName = mCol.getDecks().get(card.getDid()).getString("name");
} catch (JSONException e) {
throw new RuntimeException(e);
}
mCards.get(pos).put("deck", deckName);
}
String flags = Integer.toString((c.getQueue() == -1 ? 1 : 0) + (note.hasTag("marked") ? 2 : 0));
mCards.get(pos).put("flags", flags);
}
updateList();
}
use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.
the class CardBrowser method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// FIXME:
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == DeckPicker.RESULT_DB_ERROR) {
closeCardBrowser(DeckPicker.RESULT_DB_ERROR);
}
// switching back to the multimedia card editor.
if (requestCode == EDIT_CARD && resultCode == MultimediaCardEditorActivity.RESULT_DELETED) {
deleteNote(sCardBrowserCard);
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDeleteNoteHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, 3));
} else if (requestCode == EDIT_CARD && resultCode != RESULT_CANCELED) {
Log.i(AnkiDroidApp.TAG, "CardBrowser: Saving card...");
DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT, mUpdateCardHandler, new DeckTask.TaskData(mCol.getSched(), sCardBrowserCard, false));
} else if (requestCode == ADD_NOTE && resultCode == RESULT_OK) {
mSearchTerms = mSearchEditText.getText().toString().toLowerCase();
searchCards();
}
}
use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.
the class CardBrowser method deleteNote.
private void deleteNote(Card card) {
ArrayList<Card> cards = card.note().cards();
int pos;
for (Card c : cards) {
pos = getPosition(mCards, c.getId());
if (pos >= 0 && pos < mCards.size()) {
mCards.remove(pos);
}
}
// Delete itself if not deleted
pos = getPosition(mCards, card.getId());
if (pos >= 0 && pos < mCards.size()) {
mCards.remove(pos);
}
updateList();
}
use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.
the class NoteService method saveMedia.
/**
* Saves the multimedia associated with this card to proper path inside anki folder. For each field associated with
* the note it checks for the following condition a. The field content should have changed b. The field content does
* not already point to a media inside anki media path If both condition satisfies then it copies the file inside
* the media path and deletes the file referenced by the note
*
* @param note
*/
public static void saveMedia(final MultimediaEditableNote noteNew) {
// if (noteNew.getModelId() == noteOld.getModelId())
// {
// int fieldCount = noteNew.getNumberOfFields();
// for (int i = 0; i < fieldCount; i++)
// {
// IField newField = noteNew.getField(i);
// IField oldField = noteOld.getField(i);
// if
// (newField.getFormattedValue().equals(oldField.getFormattedValue()))
// {
// continue;
// }
// importMediaToDirectory(newField);
// }
// }
// else
// {
int fieldCount = noteNew.getNumberOfFields();
for (int i = 0; i < fieldCount; i++) {
IField newField = noteNew.getField(i);
importMediaToDirectory(newField);
}
// }
}
use of com.ichi2.libanki.Card in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundUndo.
private TaskData doInBackgroundUndo(TaskData... params) {
Sched sched = params[0].getSched();
Collection col = sched.getCol();
try {
col.getDb().getDatabase().beginTransaction();
Card newCard;
try {
long cid = col.undo();
if (cid != 0) {
// a review was undone,
newCard = col.getCard(cid);
col.reset();
col.getSched().decrementCounts(newCard);
sHadCardQueue = true;
} else {
// TODO: do not fetch new card if a non review operation has
// been undone
col.reset();
newCard = getCard(sched);
}
// TODO: handle leech undoing properly
publishProgress(new TaskData(newCard, 0));
col.getDb().getDatabase().setTransactionSuccessful();
} finally {
col.getDb().getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundUndo - RuntimeException on undoing: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUndo");
return new TaskData(false);
}
return new TaskData(true);
}
Aggregations