Skip to content

Commit

Permalink
add keyboard shortcuts to flag and mark in previewer
Browse files Browse the repository at this point in the history
  • Loading branch information
RobozinhoD committed May 3, 2024
1 parent 057693c commit b5d917d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,27 @@ class PreviewerFragment :
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
if (event.action != KeyEvent.ACTION_DOWN) return false

if (event.isCtrlPressed) {
when (event.keyCode) {
KeyEvent.KEYCODE_1 -> viewModel.toggleFlag(Flag.RED)
KeyEvent.KEYCODE_2 -> viewModel.toggleFlag(Flag.ORANGE)
KeyEvent.KEYCODE_3 -> viewModel.toggleFlag(Flag.GREEN)
KeyEvent.KEYCODE_4 -> viewModel.toggleFlag(Flag.BLUE)
KeyEvent.KEYCODE_5 -> viewModel.toggleFlag(Flag.PINK)
KeyEvent.KEYCODE_6 -> viewModel.toggleFlag(Flag.TURQUOISE)
KeyEvent.KEYCODE_7 -> viewModel.toggleFlag(Flag.PURPLE)
else -> return false
}
return true
}

when (event.unicodeChar.toChar()) {
'*' -> {
viewModel.toggleMark()
return true
}
}

when (event.keyCode) {
KeyEvent.KEYCODE_DPAD_LEFT -> {
requireView().findViewById<MaterialButton>(R.id.show_previous).performClickIfEnabled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ class PreviewerViewModel(previewerIdsFile: PreviewerIdsFile, firstIndex: Int, ca
}
}

fun toggleFlag(flag: Flag) {
if (flagCode.value == flag.code) {
setFlag(Flag.NONE)
} else {
setFlag(flag)
}
}

/**
* Shows the current card's answer
* or the next question if the answer is already being shown
Expand Down

0 comments on commit b5d917d

Please sign in to comment.