From 0ab166e0abb67b6484016f4398f8f2ed8dd7b60e Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Mon, 27 May 2024 19:56:57 -0300 Subject: [PATCH] feat(new reviewer): suspend --- .../ichi2/anki/servicelayer/NoteService.kt | 10 +++++++++ .../ui/windows/reviewer/ReviewerFragment.kt | 15 +++++++++++++ .../ui/windows/reviewer/ReviewerViewModel.kt | 22 +++++++++++++++++++ AnkiDroid/src/main/res/menu/reviewer2.xml | 17 ++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt index 2ddcf2665a1b..ee5fa223e9ff 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt @@ -252,3 +252,13 @@ suspend fun isBuryNoteAvailable(card: Card): Boolean { ) == 1 } } + +suspend fun isSuspendNoteAvailable(card: Card): Boolean { + return withCol { + db.queryScalar( + "select 1 from cards where nid = ? and id != ? and queue != " + Consts.QUEUE_TYPE_SUSPENDED + " limit 1", + card.nid, + card.id + ) == 1 + } +} diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt index 939a0351f0bd..6e3d50556921 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt @@ -119,6 +119,8 @@ class ReviewerFragment : R.id.action_edit -> launchEditNote() R.id.action_mark -> viewModel.toggleMark() R.id.action_open_deck_options -> launchDeckOptions() + R.id.action_suspend_card -> viewModel.suspendCard() + R.id.action_suspend_note -> viewModel.suspendNote() } return true } @@ -182,6 +184,19 @@ class ReviewerFragment : buryCardItem.isVisible = true } } + + val suspendItem = menu.findItem(R.id.action_suspend) + val suspendCardItem = menu.findItem(R.id.action_suspend_card) + viewModel.canSuspendNoteFlow.flowWithLifecycle(lifecycle) + .collectLatestIn(lifecycleScope) { canSuspendNote -> + if (canSuspendNote) { + suspendItem.isVisible = true + suspendCardItem.isVisible = false + } else { + suspendItem.isVisible = false + suspendItem.isVisible = true + } + } } private val noteEditorLauncher = diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt index 8ea2ae0c29e2..7dd9daa09295 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt @@ -193,6 +193,28 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : } } + fun suspendCard() { + launchCatchingIO { + val cardId = currentCard.await().id + undoableOp { + sched.suspendCards(ids = listOf(cardId)) + }.count + actionFeedbackFlow.emit(CollectionManager.TR.studyingCardSuspended()) + updateCurrentCard() + } + } + + fun suspendNote() { + launchCatchingIO { + val noteId = currentCard.await().nid + undoableOp { + sched.suspendNotes(ids = listOf(noteId)) + } + actionFeedbackFlow.emit(CollectionManager.TR.studyingNoteSuspended()) + updateCurrentCard() + } + } + /* ********************************************************************************************* *************************************** Internal methods *************************************** ********************************************************************************************* */ diff --git a/AnkiDroid/src/main/res/menu/reviewer2.xml b/AnkiDroid/src/main/res/menu/reviewer2.xml index 98dc03467555..7b64ccc43606 100644 --- a/AnkiDroid/src/main/res/menu/reviewer2.xml +++ b/AnkiDroid/src/main/res/menu/reviewer2.xml @@ -65,4 +65,21 @@ android:title="@string/menu_bury_note" /> + + + + + + + \ No newline at end of file