From 0e702a7c125b518ae6254211cc94eb1339bfc49d Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+brayandso@users.noreply.github.com> Date: Mon, 27 May 2024 20:16:05 -0300 Subject: [PATCH] feat(new reviewer): flag --- .../ui/windows/reviewer/ReviewerFragment.kt | 24 +++++++++++ .../ui/windows/reviewer/ReviewerViewModel.kt | 13 ++++++ AnkiDroid/src/main/res/menu/reviewer2.xml | 42 ++++++++++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) 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 84fadc078ae4..6757e7214074 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 @@ -34,6 +34,7 @@ import androidx.lifecycle.lifecycleScope import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.button.MaterialButton import com.ichi2.anki.AbstractFlashcardViewer.Companion.RESULT_NO_MORE_CARDS +import com.ichi2.anki.Flag import com.ichi2.anki.NoteEditor import com.ichi2.anki.R import com.ichi2.anki.cardviewer.CardMediaPlayer @@ -121,6 +122,14 @@ class ReviewerFragment : R.id.action_open_deck_options -> launchDeckOptions() R.id.action_suspend_card -> viewModel.suspendCard() R.id.action_suspend_note -> viewModel.suspendNote() + R.id.action_flag_zero -> viewModel.setFlag(Flag.NONE) + R.id.action_flag_one -> viewModel.setFlag(Flag.RED) + R.id.action_flag_two -> viewModel.setFlag(Flag.ORANGE) + R.id.action_flag_three -> viewModel.setFlag(Flag.GREEN) + R.id.action_flag_four -> viewModel.setFlag(Flag.BLUE) + R.id.action_flag_five -> viewModel.setFlag(Flag.PINK) + R.id.action_flag_six -> viewModel.setFlag(Flag.TURQUOISE) + R.id.action_flag_seven -> viewModel.setFlag(Flag.PURPLE) } return true } @@ -197,6 +206,21 @@ class ReviewerFragment : suspendItem.isVisible = true } } + + menu.findItem(R.id.action_flag_zero).title = Flag.NONE.displayName() + menu.findItem(R.id.action_flag_one).title = Flag.RED.displayName() + menu.findItem(R.id.action_flag_two).title = Flag.ORANGE.displayName() + menu.findItem(R.id.action_flag_three).title = Flag.GREEN.displayName() + menu.findItem(R.id.action_flag_four).title = Flag.BLUE.displayName() + menu.findItem(R.id.action_flag_five).title = Flag.PINK.displayName() + menu.findItem(R.id.action_flag_six).title = Flag.TURQUOISE.displayName() + menu.findItem(R.id.action_flag_seven).title = Flag.PURPLE.displayName() + + // TODO show that the card is marked somehow when the menu item is overflowed or not shown + viewModel.flagCodeFlow.flowWithLifecycle(lifecycle) + .collectLatestIn(lifecycleScope) { flagCode -> + menu.findItem(R.id.action_flag).setIcon(Flag.fromCode(flagCode).drawableRes) + } } 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 632324b7f79b..2dafb4cb8e78 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 @@ -23,6 +23,7 @@ import anki.frontend.SetSchedulingStatesRequest import com.ichi2.anki.CollectionManager import com.ichi2.anki.CollectionManager.withCol import com.ichi2.anki.Ease +import com.ichi2.anki.Flag import com.ichi2.anki.NoteEditor import com.ichi2.anki.asyncIO import com.ichi2.anki.cardviewer.CardMediaPlayer @@ -62,6 +63,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : } var isQueueFinishedFlow = MutableSharedFlow() val isMarkedFlow = MutableStateFlow(false) + val flagCodeFlow = MutableStateFlow(Flag.NONE.code) val actionFeedbackFlow = MutableSharedFlow() val canBuryNoteFlow = MutableStateFlow(true) val canSuspendNoteFlow = MutableStateFlow(true) @@ -128,6 +130,16 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : } } + fun setFlag(flag: Flag) { + launchCatchingIO { + val card = currentCard.await() + undoableOp { + setUserFlagForCards(listOf(card.id), flag.code) + } + flagCodeFlow.emit(flag.code) + } + } + fun onStateMutationCallback() { statesMutated = true } @@ -310,6 +322,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : showQuestion() loadAndPlaySounds(CardSide.QUESTION) updateMarkedStatus() + flagCodeFlow.emit(card.userFlag()) canBuryNoteFlow.emit(isBuryNoteAvailable(card)) canSuspendNoteFlow.emit(isSuspendNoteAvailable(card)) } diff --git a/AnkiDroid/src/main/res/menu/reviewer2.xml b/AnkiDroid/src/main/res/menu/reviewer2.xml index 7b64ccc43606..6872767ab3dd 100644 --- a/AnkiDroid/src/main/res/menu/reviewer2.xml +++ b/AnkiDroid/src/main/res/menu/reviewer2.xml @@ -15,7 +15,47 @@ ~ this program. If not, see . --> + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + + + + + + + + + + + +