Skip to content

Commit

Permalink
feat(new reviewer): suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed May 27, 2024
1 parent c1975cf commit 0ab166e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/servicelayer/NoteService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,13 @@ suspend fun isBuryNoteAvailable(card: Card): Boolean {
) == 1
}
}

suspend fun isSuspendNoteAvailable(card: Card): Boolean {
return withCol {
db.queryScalar(
"select 1 from cards where nid = ? and id != ? and queue != " + Consts.QUEUE_TYPE_SUSPENDED + " limit 1",
card.nid,
card.id
) == 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class ReviewerFragment :
R.id.action_edit -> launchEditNote()
R.id.action_mark -> viewModel.toggleMark()
R.id.action_open_deck_options -> launchDeckOptions()
R.id.action_suspend_card -> viewModel.suspendCard()
R.id.action_suspend_note -> viewModel.suspendNote()
}
return true
}
Expand Down Expand Up @@ -182,6 +184,19 @@ class ReviewerFragment :
buryCardItem.isVisible = true
}
}

val suspendItem = menu.findItem(R.id.action_suspend)
val suspendCardItem = menu.findItem(R.id.action_suspend_card)
viewModel.canSuspendNoteFlow.flowWithLifecycle(lifecycle)
.collectLatestIn(lifecycleScope) { canSuspendNote ->
if (canSuspendNote) {
suspendItem.isVisible = true
suspendCardItem.isVisible = false
} else {
suspendItem.isVisible = false
suspendItem.isVisible = true
}
}
}

private val noteEditorLauncher =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
}

fun suspendCard() {
launchCatchingIO {
val cardId = currentCard.await().id
undoableOp {
sched.suspendCards(ids = listOf(cardId))
}.count
actionFeedbackFlow.emit(CollectionManager.TR.studyingCardSuspended())
updateCurrentCard()
}
}

fun suspendNote() {
launchCatchingIO {
val noteId = currentCard.await().nid
undoableOp {
sched.suspendNotes(ids = listOf(noteId))
}
actionFeedbackFlow.emit(CollectionManager.TR.studyingNoteSuspended())
updateCurrentCard()
}
}

/* *********************************************************************************************
*************************************** Internal methods ***************************************
********************************************************************************************* */
Expand Down
17 changes: 17 additions & 0 deletions AnkiDroid/src/main/res/menu/reviewer2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,21 @@
android:title="@string/menu_bury_note" />
</menu>
</item>
<item android:id="@+id/action_suspend_card"
android:title="@string/menu_suspend_card"
android:icon="@drawable/ic_suspend"
android:visible="false"/>
<item
android:id="@+id/action_suspend"
android:title="@string/menu_suspend"
android:icon="@drawable/ic_suspend">
<menu>
<item
android:id="@+id/action_suspend_card"
android:title="@string/menu_suspend_card" />
<item
android:id="@+id/action_suspend_note"
android:title="@string/menu_suspend_note" />
</menu>
</item>
</menu>

0 comments on commit 0ab166e

Please sign in to comment.