Skip to content

Commit

Permalink
feat(new reviewer): close action
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Feb 15, 2025
1 parent 8ab6be8 commit dd76d2b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ enum class ViewerAction(
FLIP_OR_ANSWER_EASE4,
SHOW_HINT,
SHOW_ALL_HINTS,
EXIT,
;

override val preferenceKey: String get() = "binding_$name"
Expand Down Expand Up @@ -151,6 +152,7 @@ enum class ViewerAction(
SHOW_ANSWER,
DELETE,
CARD_INFO,
EXIT,
USER_ACTION_1,
USER_ACTION_2,
USER_ACTION_3,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import com.google.android.material.card.MaterialCardView
import com.google.android.material.shape.ShapeAppearanceModel
import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textview.MaterialTextView
import com.ichi2.anki.AbstractFlashcardViewer.Companion.RESULT_NO_MORE_CARDS
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.DispatchKeyEventListener
import com.ichi2.anki.NoteEditor
Expand Down Expand Up @@ -87,7 +86,6 @@ import com.ichi2.anki.utils.ext.removeSubMenu
import com.ichi2.anki.utils.ext.sharedPrefs
import com.ichi2.anki.utils.ext.window
import com.ichi2.libanki.sched.Counts
import kotlinx.coroutines.launch

class ReviewerFragment :
CardViewerFragment(R.layout.reviewer2),
Expand Down Expand Up @@ -141,12 +139,10 @@ class ReviewerFragment :
showSnackbar(message, duration = 500)
}

viewModel.isQueueFinishedFlow.collectIn(lifecycleScope) { isQueueFinished ->
if (isQueueFinished) {
requireActivity().run {
setResult(RESULT_NO_MORE_CARDS)
finish()
}
viewModel.finishResultFlow.collectIn(lifecycleScope) { result ->
requireActivity().run {
setResult(result)
finish()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import anki.collection.OpChanges
import anki.frontend.SetSchedulingStatesRequest
import com.ichi2.anki.AbstractFlashcardViewer
import com.ichi2.anki.AbstractFlashcardViewer.Companion.RESULT_NO_MORE_CARDS
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.Ease
Expand Down Expand Up @@ -79,7 +81,7 @@ class ReviewerViewModel(
asyncIO {
queueState.await()!!.topCard
}
var isQueueFinishedFlow = MutableSharedFlow<Boolean>()
var finishResultFlow = MutableSharedFlow<Int>()
val isMarkedFlow = MutableStateFlow(false)
val flagFlow = MutableStateFlow(Flag.NONE)
val actionFeedbackFlow = MutableSharedFlow<String>()
Expand Down Expand Up @@ -434,7 +436,7 @@ class ReviewerViewModel(
}
val state = queueState.await()
if (state == null) {
isQueueFinishedFlow.emit(true)
finishResultFlow.emit(RESULT_NO_MORE_CARDS)
return
}

Expand Down Expand Up @@ -516,6 +518,7 @@ class ReviewerViewModel(
ViewerAction.FLIP_OR_ANSWER_EASE4 -> flipOrAnswer(Ease.EASY)
ViewerAction.SHOW_HINT -> eval.emit("ankidroid.showHint()")
ViewerAction.SHOW_ALL_HINTS -> eval.emit("ankidroid.showAllHints()")
ViewerAction.EXIT -> finishResultFlow.emit(AbstractFlashcardViewer.RESULT_DEFAULT)
ViewerAction.USER_ACTION_1 -> userAction(1)
ViewerAction.USER_ACTION_2 -> userAction(2)
ViewerAction.USER_ACTION_3 -> userAction(3)
Expand Down

0 comments on commit dd76d2b

Please sign in to comment.