Search in sources :

Example 11 with UNDO

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();
}
Also used : Collection(com.ichi2.libanki.Collection)

Example 12 with UNDO

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);
}
Also used : Collection(com.ichi2.libanki.Collection) Deck(com.ichi2.libanki.Deck) DeckManager(com.ichi2.libanki.DeckManager) Card(com.ichi2.libanki.Card) RobolectricTest(com.ichi2.anki.RobolectricTest) Test(org.junit.Test)

Example 13 with 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)));
    }
}
Also used : Bundle(android.os.Bundle) MaxExecFunction(com.ichi2.utils.MaxExecFunction) JsResult(android.webkit.JsResult) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ClipboardUtil(com.ichi2.utils.ClipboardUtil) AbstractSched(com.ichi2.libanki.sched.AbstractSched) RenderProcessGoneDetail(android.webkit.RenderProcessGoneDetail) HitTestResult(android.webkit.WebView.HitTestResult) ActionBar(androidx.appcompat.app.ActionBar) Decks(com.ichi2.libanki.Decks) AndroidUiUtils(com.ichi2.utils.AndroidUiUtils) CookieManager(android.webkit.CookieManager) Handler(android.os.Handler) GestureProcessor(com.ichi2.anki.cardviewer.GestureProcessor) AutomaticAnswer(com.ichi2.anki.reviewer.AutomaticAnswer) AssetHelper(com.ichi2.utils.AssetHelper) PreviousAnswerIndicator(com.ichi2.anki.reviewer.PreviousAnswerIndicator) TargetApi(android.annotation.TargetApi) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) FullDraggableContainer(com.drakeet.drawer.FullDraggableContainer) CoordinatorLayout(androidx.coordinatorlayout.widget.CoordinatorLayout) IntentFilter(android.content.IntentFilter) TTS(com.ichi2.anki.cardviewer.TTS) TypeAnswer(com.ichi2.anki.cardviewer.TypeAnswer) IdRes(androidx.annotation.IdRes) StringRes(androidx.annotation.StringRes) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) TagsDialogListener(com.ichi2.anki.dialogs.tags.TagsDialogListener) Consts(com.ichi2.libanki.Consts) CompatHelper(com.ichi2.compat.CompatHelper) WebViewDebugging(com.ichi2.utils.WebViewDebugging) TagsDialogFactory(com.ichi2.anki.dialogs.tags.TagsDialogFactory) SoundOrVideoTag(com.ichi2.libanki.SoundOrVideoTag) WebResourceResponse(android.webkit.WebResourceResponse) RustCleanup(net.ankiweb.rsdroid.RustCleanup) GestureDetector(android.view.GestureDetector) ViewParent(android.view.ViewParent) HandlerUtils(com.ichi2.utils.HandlerUtils) TagsDialog(com.ichi2.anki.dialogs.tags.TagsDialog) Direction(com.ichi2.anim.ActivityTransitionAnimation.Direction) SystemClock(android.os.SystemClock) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Supplier(java.util.function.Supplier) ViewAnimation(com.ichi2.anim.ViewAnimation) ArrayList(java.util.ArrayList) WebResourceRequest(android.webkit.WebResourceRequest) CardAppearance(com.ichi2.anki.cardviewer.CardAppearance) WebChromeClient(android.webkit.WebChromeClient) CheckResult(androidx.annotation.CheckResult) MissingImageHandler(com.ichi2.anki.cardviewer.MissingImageHandler) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) IOException(java.io.IOException) SoundSide(com.ichi2.libanki.Sound.SoundSide) File(java.io.File) Gravity(android.view.Gravity) Lock(java.util.concurrent.locks.Lock) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) AnkiMethod(com.ichi2.anki.servicelayer.AnkiMethod) SchedulerService(com.ichi2.anki.servicelayer.SchedulerService) LinearLayout(android.widget.LinearLayout) URLDecoder(java.net.URLDecoder) TaskManager(com.ichi2.async.TaskManager) EaseButton(com.ichi2.anki.reviewer.EaseButton) AutomaticAnswerAction(com.ichi2.anki.reviewer.AutomaticAnswerAction) WindowManager(android.view.WindowManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ViewerCommand(com.ichi2.anki.cardviewer.ViewerCommand) WebViewClient(android.webkit.WebViewClient) View(android.view.View) Button(android.widget.Button) WebViewAssetLoader(androidx.webkit.WebViewAssetLoader) WebView(android.webkit.WebView) HashUtil(com.ichi2.utils.HashUtil) SimpleOnGestureListener(android.view.GestureDetector.SimpleOnGestureListener) TaskListenerBuilder(com.ichi2.anki.servicelayer.TaskListenerBuilder) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) Objects(java.util.Objects) UndoService(com.ichi2.anki.servicelayer.UndoService) List(java.util.List) SoundPlayer(com.ichi2.anki.cardviewer.SoundPlayer) ActivityNotFoundException(android.content.ActivityNotFoundException) RelativeLayout(android.widget.RelativeLayout) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) FixedEditText(com.ichi2.ui.FixedEditText) EditorInfo(android.view.inputmethod.EditorInfo) Snackbar(com.google.android.material.snackbar.Snackbar) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Note(com.ichi2.libanki.Note) Context(android.content.Context) NextCard(com.ichi2.anki.servicelayer.SchedulerService.NextCard) TaskListener(com.ichi2.async.TaskListener) KeyEvent(android.view.KeyEvent) CardHtml(com.ichi2.anki.cardviewer.CardHtml) Pair(android.util.Pair) Intent(android.content.Intent) HashMap(java.util.HashMap) Collection(com.ichi2.libanki.Collection) Function(java.util.function.Function) InputMethodManager(android.view.inputmethod.InputMethodManager) ClipData(android.content.ClipData) HashSet(java.util.HashSet) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TTSTag(com.ichi2.libanki.TTSTag) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) Sound(com.ichi2.libanki.Sound) Utils(com.ichi2.libanki.Utils) NoteService(com.ichi2.anki.servicelayer.NoteService) Computation(com.ichi2.utils.Computation) LayoutInflater(android.view.LayoutInflater) ReviewerUi(com.ichi2.anki.reviewer.ReviewerUi) CollectionTask(com.ichi2.async.CollectionTask) FileInputStream(java.io.FileInputStream) HtmlGenerator(com.ichi2.anki.cardviewer.HtmlGenerator) Side(com.ichi2.anki.cardviewer.Side) Themes(com.ichi2.themes.Themes) Color(android.graphics.Color) WebResourceError(android.webkit.WebResourceError) LanguageHintService(com.ichi2.anki.servicelayer.LanguageHintService) Consumer(java.util.function.Consumer) AdaptionUtil(com.ichi2.utils.AdaptionUtil) OnRenderProcessGoneDelegate(com.ichi2.anki.cardviewer.OnRenderProcessGoneDelegate) Card(com.ichi2.libanki.Card) VisibleForTesting(androidx.annotation.VisibleForTesting) FullScreenMode(com.ichi2.anki.reviewer.FullScreenMode) Resources(android.content.res.Resources) OnClickListener(android.view.View.OnClickListener) UndoService(com.ichi2.anki.servicelayer.UndoService) Resources(android.content.res.Resources)

Example 14 with UNDO

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);
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) StartupFailure(com.ichi2.anki.InitialActivity.StartupFailure) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) DialogHandler(com.ichi2.anki.dialogs.DialogHandler) Drawable(android.graphics.drawable.Drawable) ShortcutManagerCompat(androidx.core.content.pm.ShortcutManagerCompat) Manifest(android.Manifest) Decks(com.ichi2.libanki.Decks) Fragment(androidx.fragment.app.Fragment) JSONException(com.ichi2.utils.JSONException) ContextCompat(androidx.core.content.ContextCompat) DeckPickerBackupNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerBackupNoSpaceLeftDialog) IntentFilter(android.content.IntentFilter) Triple(com.ichi2.utils.Triple) SearchView(androidx.appcompat.widget.SearchView) DeckPickerContextMenu(com.ichi2.anki.dialogs.DeckPickerContextMenu) Cancellable(com.ichi2.async.Cancellable) DeckRenameException(com.ichi2.libanki.backend.exception.DeckRenameException) StringRes(androidx.annotation.StringRes) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) Message(android.os.Message) HostNumFactory(com.ichi2.anki.web.HostNumFactory) CompatHelper(com.ichi2.compat.CompatHelper) DeckAdapter(com.ichi2.anki.widgets.DeckAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DeckPickerNoSpaceToDowngradeDialog(com.ichi2.anki.dialogs.DeckPickerNoSpaceToDowngradeDialog) DeckPickerConfirmDeleteDeckDialog(com.ichi2.anki.dialogs.DeckPickerConfirmDeleteDeckDialog) Direction(com.ichi2.anim.ActivityTransitionAnimation.Direction) FULL_DOWNLOAD(com.ichi2.async.Connection.ConflictResolution.FULL_DOWNLOAD) SdCardReceiver(com.ichi2.anki.receiver.SdCardReceiver) Editor(android.content.SharedPreferences.Editor) CustomSyncServerUrlException(com.ichi2.libanki.sync.CustomSyncServerUrlException) FileSizeFormatter(com.ichi2.anki.dialogs.DeckPickerNoSpaceToDowngradeDialog.FileSizeFormatter) DeckPickerNoSpaceLeftDialog(com.ichi2.anki.dialogs.DeckPickerNoSpaceLeftDialog) StudyOptionsListener(com.ichi2.anki.StudyOptionsFragment.StudyOptionsListener) BadgeDrawableBuilder(com.ichi2.ui.BadgeDrawableBuilder) Menu(android.view.Menu) DeckService(com.ichi2.anki.servicelayer.DeckService) Connection(com.ichi2.async.Connection) Settings(android.provider.Settings) AnkiPackageImporter(com.ichi2.libanki.importer.AnkiPackageImporter) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) CollectionIntegrityStorageCheck(com.ichi2.anki.CollectionHelper.CollectionIntegrityStorageCheck) ActivityExportingDelegate(com.ichi2.anki.export.ActivityExportingDelegate) TextUtils(android.text.TextUtils) File(java.io.File) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) IconCompat(androidx.core.graphics.drawable.IconCompat) ImportUtils(com.ichi2.utils.ImportUtils) EditText(android.widget.EditText) SchedulerService(com.ichi2.anki.servicelayer.SchedulerService) LinearLayout(android.widget.LinearLayout) AsyncDialogFragment(com.ichi2.anki.dialogs.AsyncDialogFragment) PackageManager(android.content.pm.PackageManager) TaskManager(com.ichi2.async.TaskManager) WindowManager(android.view.WindowManager) UsageAnalytics(com.ichi2.anki.analytics.UsageAnalytics) ModelManager(com.ichi2.libanki.ModelManager) ConfirmationDialog(com.ichi2.anki.dialogs.ConfirmationDialog) AnkiStatsTaskHandler(com.ichi2.anki.stats.AnkiStatsTaskHandler) Permissions(com.ichi2.utils.Permissions) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SyncStatus(com.ichi2.utils.SyncStatus) FragmentTransaction(androidx.fragment.app.FragmentTransaction) BroadcastReceiver(android.content.BroadcastReceiver) DatabaseErrorDialog(com.ichi2.anki.dialogs.DatabaseErrorDialog) CustomStudyDialogFactory(com.ichi2.anki.dialogs.customstudy.CustomStudyDialogFactory) Timber(timber.log.Timber) UndoService(com.ichi2.anki.servicelayer.UndoService) List(java.util.List) TextView(android.widget.TextView) ImportFileSelectionFragment(com.ichi2.anki.dialogs.ImportFileSelectionFragment) RelativeLayout(android.widget.RelativeLayout) Filterable(android.widget.Filterable) TaskListenerWithContext(com.ichi2.async.TaskListenerWithContext) ViewPropertyAnimator(android.view.ViewPropertyAnimator) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Snackbar(com.google.android.material.snackbar.Snackbar) Window(android.view.Window) VersionUtils(com.ichi2.utils.VersionUtils) Context(android.content.Context) TaskListener(com.ichi2.async.TaskListener) KeyEvent(android.view.KeyEvent) GravityEnum(com.afollestad.materialdialogs.GravityEnum) Pair(android.util.Pair) DeckPickerAnalyticsOptInDialog(com.ichi2.anki.dialogs.DeckPickerAnalyticsOptInDialog) ImportDialog(com.ichi2.anki.dialogs.ImportDialog) Intent(android.content.Intent) Collection(com.ichi2.libanki.Collection) StyledProgressDialog(com.ichi2.themes.StyledProgressDialog) PixelFormat(android.graphics.PixelFormat) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) WidgetStatus(com.ichi2.widget.WidgetStatus) SyncErrorDialog(com.ichi2.anki.dialogs.SyncErrorDialog) Payload(com.ichi2.async.Connection.Payload) Model(com.ichi2.libanki.Model) Build(android.os.Build) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) Utils(com.ichi2.libanki.Utils) DialogInterface(android.content.DialogInterface) ConfirmModSchemaException(com.ichi2.anki.exception.ConfirmModSchemaException) Computation(com.ichi2.utils.Computation) AbstractDeckTreeNode(com.ichi2.libanki.sched.AbstractDeckTreeNode) ActivityCompat(androidx.core.app.ActivityCompat) CreateDeckDialog(com.ichi2.anki.dialogs.CreateDeckDialog) CollectionTask(com.ichi2.async.CollectionTask) SQLException(android.database.SQLException) CustomStudyDialog(com.ichi2.anki.dialogs.customstudy.CustomStudyDialog) Syncer(com.ichi2.libanki.sync.Syncer) MediaCheckDialog(com.ichi2.anki.dialogs.MediaCheckDialog) AdaptionUtil(com.ichi2.utils.AdaptionUtil) VisibleForTesting(androidx.annotation.VisibleForTesting) Resources(android.content.res.Resources) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) Resources(android.content.res.Resources) CreateDeckDialog(com.ichi2.anki.dialogs.CreateDeckDialog)

Example 15 with UNDO

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);
}
Also used : JSONObject(com.ichi2.utils.JSONObject) JSONArray(com.ichi2.utils.JSONArray) Collection(com.ichi2.libanki.Collection) MockTime(com.ichi2.testutils.MockTime) Test(org.junit.Test)

Aggregations

Collection (com.ichi2.libanki.Collection)22 Card (com.ichi2.libanki.Card)15 JSONObject (com.ichi2.utils.JSONObject)13 Intent (android.content.Intent)8 JSONException (com.ichi2.utils.JSONException)7 ArrayList (java.util.ArrayList)7 MenuItem (android.view.MenuItem)6 View (android.view.View)6 VisibleForTesting (androidx.annotation.VisibleForTesting)6 Context (android.content.Context)5 SharedPreferences (android.content.SharedPreferences)5 Bundle (android.os.Bundle)5 Menu (android.view.Menu)5 WindowManager (android.view.WindowManager)5 TextView (android.widget.TextView)5 NonNull (androidx.annotation.NonNull)5 Nullable (androidx.annotation.Nullable)5 SearchView (androidx.appcompat.widget.SearchView)5 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)5 Snackbar (com.google.android.material.snackbar.Snackbar)5