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 df0ea40e0a7f..7e3340b7fe5d 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 @@ -42,6 +42,7 @@ import com.ichi2.anki.previewer.CardViewerActivity import com.ichi2.anki.previewer.CardViewerFragment import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider import com.ichi2.anki.snackbar.SnackbarBuilder +import com.ichi2.anki.snackbar.showSnackbar import com.ichi2.anki.utils.ext.collectIn import com.ichi2.anki.utils.ext.collectLatestIn import com.ichi2.anki.utils.navBarNeedsScrim @@ -86,6 +87,11 @@ class ReviewerFragment : } } + viewModel.actionFeedbackFlow.flowWithLifecycle(lifecycle) + .collectIn(lifecycleScope) { message -> + showSnackbar(message, duration = 500) + } + viewModel.isQueueFinishedFlow.collectIn(lifecycleScope) { isQueueFinished -> if (isQueueFinished) { requireActivity().run { @@ -107,6 +113,7 @@ class ReviewerFragment : when (item.itemId) { R.id.action_add_note -> launchAddNote() R.id.action_card_info -> launchCardInfo() + R.id.action_delete -> viewModel.deleteNote() R.id.action_edit -> launchEditNote() R.id.action_mark -> viewModel.toggleMark() R.id.action_open_deck_options -> launchDeckOptions() 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 fe3589dacca9..05bcf995563f 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 @@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import anki.frontend.SetSchedulingStatesRequest +import com.ichi2.anki.CollectionManager import com.ichi2.anki.CollectionManager.withCol import com.ichi2.anki.Ease import com.ichi2.anki.NoteEditor @@ -57,6 +58,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : } var isQueueFinishedFlow = MutableSharedFlow() val isMarkedFlow = MutableStateFlow(false) + val actionFeedbackFlow = MutableSharedFlow() private val server = AnkiServer(this).also { it.start() } private val stateMutationKey = TimeManager.time.intTimeMS().toString() @@ -154,6 +156,16 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : } } + fun deleteNote() { + launchCatchingIO { + val cardId = currentCard.await().id + val noteCount = undoableOp { + removeNotes(cids = listOf(cardId)) + }.count + actionFeedbackFlow.emit(CollectionManager.TR.browsingCardsDeleted(noteCount)) + } + } + /* ********************************************************************************************* *************************************** Internal methods *************************************** ********************************************************************************************* */ diff --git a/AnkiDroid/src/main/res/menu/reviewer2.xml b/AnkiDroid/src/main/res/menu/reviewer2.xml index 46b1bc3dab74..1bf5f20cdabd 100644 --- a/AnkiDroid/src/main/res/menu/reviewer2.xml +++ b/AnkiDroid/src/main/res/menu/reviewer2.xml @@ -41,4 +41,9 @@ android:title="@string/menu_add_note" android:icon="@drawable/ic_add" app:showAsAction="never"/> + \ No newline at end of file