use of com.ichi2.async.CollectionTask.TASK_TYPE.UNDO in project AnkiChinaAndroid by ankichinateam.
the class CollectionTask method doInBackgroundDeleteDeck.
private void doInBackgroundDeleteDeck(TaskData param) {
Timber.d("doInBackgroundDeleteDeck");
Collection col = getCol();
long did = param.getLong();
col.getDecks().rem(did, true);
// TODO: if we had "undo delete note" like desktop client then we won't need this.
getCol().clearUndo();
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.UNDO in project Anki-Android by ankidroid.
the class SchedV2Test method regression_test_preview.
@Test
public void regression_test_preview() throws Exception {
// "https://github.com/ankidroid/Anki-Android/issues/7285"
Collection col = getColV2();
DeckManager decks = col.getDecks();
AbstractSched sched = col.getSched();
addNoteUsingBasicModel("foo", "bar");
long did = addDynamicDeck("test");
Deck deck = decks.get(did);
deck.put("resched", false);
sched.rebuildDyn(did);
col.reset();
Card card;
for (int i = 0; i < 3; i++) {
advanceRobolectricLooperWithSleep();
card = sched.getCard();
assertNotNull(card);
sched.answerCard(card, BUTTON_ONE);
}
advanceRobolectricLooperWithSleep();
assertEquals(1, sched.lrnCount());
card = sched.getCard();
assertEquals(1, sched.counts(card).getLrn());
advanceRobolectricLooperWithSleep();
sched.answerCard(card, BUTTON_ONE);
assertDoesNotThrow(col::undo);
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.UNDO in project Anki-Android by ankidroid.
the class AbstractFlashcardViewer method undo.
protected void undo() {
if (isUndoAvailable()) {
Resources res = getResources();
String undoName = getCol().undoName(res);
new UndoService.Undo().runWithHandler(answerCardHandler(false).alsoExecuteAfter(computation -> UIUtils.showThemedToast(AbstractFlashcardViewer.this, res.getString(R.string.undo_succeeded, undoName), false)));
}
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.UNDO in project Anki-Android by ankidroid.
the class DeckPicker method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Resources res = getResources();
if (getDrawerToggle().onOptionsItemSelected(item)) {
return true;
}
int itemId = item.getItemId();
if (itemId == R.id.action_undo) {
Timber.i("DeckPicker:: Undo button pressed");
undo();
return true;
} else if (itemId == R.id.action_sync) {
Timber.i("DeckPicker:: Sync button pressed");
sync();
return true;
} else if (itemId == R.id.action_import) {
Timber.i("DeckPicker:: Import button pressed");
showDialogFragment(ImportFileSelectionFragment.createInstance(this));
return true;
} else if (itemId == R.id.action_new_filtered_deck) {
CreateDeckDialog createFilteredDeckDialog = new CreateDeckDialog(DeckPicker.this, R.string.new_deck, CreateDeckDialog.DeckDialogType.FILTERED_DECK, null);
createFilteredDeckDialog.setOnNewDeckCreated((id) -> {
// a filtered deck was created
openStudyOptions(true);
});
createFilteredDeckDialog.showFilteredDeckDialog();
return true;
} else if (itemId == R.id.action_check_database) {
Timber.i("DeckPicker:: Check database button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_DATABASE_CHECK);
return true;
} else if (itemId == R.id.action_check_media) {
Timber.i("DeckPicker:: Check media button pressed");
showMediaCheckDialog(MediaCheckDialog.DIALOG_CONFIRM_MEDIA_CHECK);
return true;
} else if (itemId == R.id.action_empty_cards) {
Timber.i("DeckPicker:: Empty cards button pressed");
handleEmptyCards();
return true;
} else if (itemId == R.id.action_model_browser_open) {
Timber.i("DeckPicker:: Model browser button pressed");
Intent noteTypeBrowser = new Intent(this, ModelBrowser.class);
startActivityForResultWithAnimation(noteTypeBrowser, 0, START);
return true;
} else if (itemId == R.id.action_restore_backup) {
Timber.i("DeckPicker:: Restore from backup button pressed");
showDatabaseErrorDialog(DatabaseErrorDialog.DIALOG_CONFIRM_RESTORE_BACKUP);
return true;
} else if (itemId == R.id.action_export) {
Timber.i("DeckPicker:: Export collection button pressed");
String msg = getResources().getString(R.string.confirm_apkg_export);
mExportingDelegate.showExportDialog(msg);
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.ichi2.async.CollectionTask.TASK_TYPE.UNDO in project Anki-Android by ankidroid.
the class ReviewerTest method testMultipleCards.
@Test
public synchronized void testMultipleCards() throws ConfirmModSchemaException {
addNoteWithThreeCards();
Collection col = getCol();
JSONObject nw = col.getDecks().confForDid(1).getJSONObject("new");
MockTime time = getCollectionTime();
nw.put("delays", new JSONArray(new int[] { 1, 10, 60, 120 }));
waitForAsyncTasksToComplete();
Reviewer reviewer = startReviewer();
waitForAsyncTasksToComplete();
assertCounts(reviewer, 3, 0, 0);
// card 1 is shown
answerCardOrdinalAsGood(reviewer, 1);
// card get scheduler in [10, 12.5] minutes
time.addM(3);
// We wait 3 minutes to ensure card 2 is scheduled after card 1
// card 2 is shown
answerCardOrdinalAsGood(reviewer, 2);
// Same as above
time.addM(3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
undo(reviewer);
assertCurrentOrdIs(reviewer, 3);
// card 3 is shown
answerCardOrdinalAsGood(reviewer, 3);
// Anki Desktop shows "1"
assertCurrentOrdIsNot(reviewer, 3);
}
Aggregations