use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundUpdateNote.
private TaskData doInBackgroundUpdateNote(TaskData[] params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundUpdateNote");
// Save the note
Sched sched = params[0].getSched();
Collection col = sched.getCol();
Card editCard = params[0].getCard();
Note editNote = editCard.note();
boolean fromReviewer = params[0].getBoolean();
// mark undo
col.markUndo(Collection.UNDO_EDIT_NOTE, new Object[] { col.getNote(editNote.getId()), editCard.getId(), fromReviewer });
try {
col.getDb().getDatabase().beginTransaction();
try {
// TODO: undo integration
editNote.flush();
// flush card too, in case, did has been changed
editCard.flush();
if (fromReviewer) {
Card newCard;
if (col.getDecks().active().contains(editCard.getDid())) {
newCard = editCard;
newCard.load();
// reload qa-cache
newCard.getQuestion(true);
} else {
newCard = getCard(sched);
}
publishProgress(new TaskData(newCard));
} else {
publishProgress(new TaskData(editCard, editNote.stringTags()));
}
col.getDb().getDatabase().setTransactionSuccessful();
} finally {
col.getDb().getDatabase().endTransaction();
}
} catch (RuntimeException e) {
Log.e(AnkiDroidApp.TAG, "doInBackgroundUpdateNote - RuntimeException on updating fact: " + e);
AnkiDroidApp.saveExceptionReportFile(e, "doInBackgroundUpdateNote");
return new TaskData(false);
}
return new TaskData(true);
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project Anki-Android by Ramblurr.
the class DeckTask method doInBackgroundConfSetSubdecks.
private TaskData doInBackgroundConfSetSubdecks(TaskData... params) {
// Log.i(AnkiDroidApp.TAG, "doInBackgroundConfSetSubdecks");
Object[] data = params[0].getObjArray();
Collection col = (Collection) data[0];
JSONObject deck = (JSONObject) data[1];
JSONObject conf = (JSONObject) data[2];
try {
TreeMap<String, Long> children = col.getDecks().children(deck.getLong("id"));
for (Map.Entry<String, Long> entry : children.entrySet()) {
JSONObject child = col.getDecks().get(entry.getValue());
if (child.getInt("dyn") == 1) {
continue;
}
TaskData newParams = new TaskData(new Object[] { col, child, conf });
boolean changed = doInBackgroundConfChange(newParams).getBoolean();
if (!changed) {
return new TaskData(false);
}
}
return new TaskData(true);
} catch (JSONException e) {
return new TaskData(false);
}
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED 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.anki.CardBrowser.Column.CHANGED in project AnkiChinaAndroid by ankichinateam.
the class CardBrowser method updateCardsInList.
/**
* @param cards Cards that were changed
* @param updatedCardTags Mapping note id -> updated tags
*/
private void updateCardsInList(List<Card> cards, Map<Long, String> updatedCardTags) {
List<CardCache> cardList = getCards();
Map<Long, Integer> idToPos = getPositionMap(cardList);
for (Card c : cards) {
// get position in the mCards search results HashMap
Integer pos = idToPos.get(c.getId());
if (pos == null || pos >= getCardCount()) {
continue;
}
// update Q & A etc
cardList.get(pos).load(true, mColumn1Index, mColumn2Index);
}
updateList();
}
use of com.ichi2.anki.CardBrowser.Column.CHANGED in project AnkiChinaAndroid by ankichinateam.
the class AbstractFlashcardViewer method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Timber.i("onActivityResult:" + requestCode);
if (requestCode == BE_VIP || requestCode == REFRESH_LOGIN_STATE_AND_TURN_TO_VIP_HTML) {
mRefreshVipStateOnResume = true;
mTurnToVipHtml = requestCode == REFRESH_LOGIN_STATE_AND_TURN_TO_VIP_HTML;
} else if (requestCode == REFRESH_VOICE_INFO) {
mRefreshVoiceInfoStateOnResume = true;
} else if (resultCode == DeckPicker.RESULT_DB_ERROR) {
closeReviewer(DeckPicker.RESULT_DB_ERROR, false);
} else if (resultCode == DeckPicker.RESULT_MEDIA_EJECTED) {
finishNoStorageAvailable();
} else if (requestCode == REFRESH_TOP_BUTTONS) {
restorePreferences();
supportInvalidateOptionsMenu();
invalidateOptionsMenu();
} else if (requestCode == REQUEST_CODE_SPEAK_SETTING) {
restorePreferences();
mReInitBDVoice = true;
} else if (requestCode == REFRESH_GESTURE) {
restorePreferences();
} else if (requestCode == REFRESH_CONTROLLER) {
restorePreferences();
}
/* Reset the schedule and reload the latest card off the top of the stack if required.
The card could have been rescheduled, the deck could have changed, or a change of
note type could have lead to the card being deleted */
if (data != null && data.hasExtra("reloadRequired")) {
performReload();
}
if (requestCode == EDIT_CURRENT_CARD) {
if (resultCode == RESULT_OK) {
// content of note was changed so update the note and current card
Timber.i("AbstractFlashcardViewer:: Saving card...");
CollectionTask.launchCollectionTask(UPDATE_NOTE, mUpdateCardHandler, new TaskData(sEditorCard, true));
onEditedNoteChanged();
} else if (resultCode == RESULT_CANCELED && !(data != null && data.hasExtra("reloadRequired"))) {
// nothing was changed by the note editor so just redraw the card
redrawCard();
}
} else if (requestCode == DECK_OPTIONS && resultCode == RESULT_OK) {
performReload();
}
if (!mDisableClipboard) {
clipboardSetText("");
}
}
Aggregations