Skip to content

Commit

Permalink
flags
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed May 1, 2024
1 parent 4883b00 commit 01a7192
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textview.MaterialTextView
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
Expand Down Expand Up @@ -163,6 +164,14 @@ class ReviewerFragment :
.collectLatestIn(lifecycleScope) { isEnabled ->
redoItem.isEnabled = isEnabled
}

// Flag
val flagItem = menu.findItem(R.id.action_flag)
viewModel.flagCode
.flowWithLifecycle(lifecycle)
.collectLatestIn(lifecycleScope) { flagCode ->
flagItem.setIcon(Flag.fromCode(flagCode).drawableRes)
}
}

private fun setupCounts(view: View) {
Expand Down Expand Up @@ -204,7 +213,15 @@ class ReviewerFragment :
R.id.action_undo -> viewModel.undo()
R.id.action_redo -> viewModel.redo()
R.id.action_open_deck_options -> openDeckOptions()
R.id.action_tag, R.id.action_flag -> showSnackbar("Not yet implemented")
R.id.action_tag -> showSnackbar("Not yet implemented")
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)
R.id.user_action_1 -> viewModel.userAction(1)
R.id.user_action_2 -> viewModel.userAction(2)
R.id.user_action_3 -> viewModel.userAction(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import anki.frontend.SetSchedulingStatesRequest
import com.ichi2.anki.CollectionManager.TR
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
Expand Down Expand Up @@ -80,6 +81,8 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
val goodNextTime: MutableStateFlow<String?> = MutableStateFlow(null)
val easyNextTime: MutableStateFlow<String?> = MutableStateFlow(null)

val flagCode: MutableStateFlow<Int> = MutableStateFlow(Flag.NONE.code)

private val shouldShowNextTimes: Deferred<Boolean> = asyncIO {
withCol { config.get("estTimes") ?: true }
}
Expand Down Expand Up @@ -270,6 +273,16 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
}

fun setFlag(flag: Flag) {
launchCatchingIO {
val card = currentCard.await()
undoableOp(ReviewerOp.FLAG) {
setUserFlagForCards(listOf(card.id), flag.code)
}
flagCode.emit(flag.code)
}
}

/* *********************************************************************************************
*************************************** Internal methods ***************************************
********************************************************************************************* */
Expand Down Expand Up @@ -430,7 +443,8 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
enum class ReviewerOp {
UNDO,
REDO,
ANSWER_CARD
ANSWER_CARD,
FLAG
}

class AutoAdvance(val viewModel: ReviewerViewModel) : DefaultLifecycleObserver {
Expand Down

0 comments on commit 01a7192

Please sign in to comment.