Skip to content

Commit

Permalink
feat(new reviewer): delete note
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed May 27, 2024
1 parent 0fb241e commit 7eb6c1f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.ichi2.anki.previewer.CardViewerActivity
import com.ichi2.anki.previewer.CardViewerFragment
import com.ichi2.anki.snackbar.BaseSnackbarBuilderProvider
import com.ichi2.anki.snackbar.SnackbarBuilder
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.utils.ext.collectIn
import com.ichi2.anki.utils.ext.collectLatestIn
import com.ichi2.anki.utils.navBarNeedsScrim
Expand Down Expand Up @@ -86,6 +87,11 @@ class ReviewerFragment :
}
}

viewModel.actionFeedbackFlow.flowWithLifecycle(lifecycle)
.collectIn(lifecycleScope) { message ->
showSnackbar(message, duration = 500)
}

viewModel.isQueueFinishedFlow.collectIn(lifecycleScope) { isQueueFinished ->
if (isQueueFinished) {
requireActivity().run {
Expand All @@ -107,6 +113,7 @@ class ReviewerFragment :
when (item.itemId) {
R.id.action_add_note -> launchAddNote()
R.id.action_card_info -> launchCardInfo()
R.id.action_delete -> viewModel.deleteNote()
R.id.action_edit -> launchEditNote()
R.id.action_mark -> viewModel.toggleMark()
R.id.action_open_deck_options -> launchDeckOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import anki.frontend.SetSchedulingStatesRequest
import com.ichi2.anki.CollectionManager
import com.ichi2.anki.CollectionManager.withCol
import com.ichi2.anki.Ease
import com.ichi2.anki.NoteEditor
Expand Down Expand Up @@ -57,6 +58,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
var isQueueFinishedFlow = MutableSharedFlow<Boolean>()
val isMarkedFlow = MutableStateFlow(false)
val actionFeedbackFlow = MutableSharedFlow<String>()

private val server = AnkiServer(this).also { it.start() }
private val stateMutationKey = TimeManager.time.intTimeMS().toString()
Expand Down Expand Up @@ -154,6 +156,16 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
}
}

fun deleteNote() {
launchCatchingIO {
val cardId = currentCard.await().id
val noteCount = undoableOp {
removeNotes(cids = listOf(cardId))
}.count
actionFeedbackFlow.emit(CollectionManager.TR.browsingCardsDeleted(noteCount))
}
}

/* *********************************************************************************************
*************************************** Internal methods ***************************************
********************************************************************************************* */
Expand Down
5 changes: 5 additions & 0 deletions AnkiDroid/src/main/res/menu/reviewer2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@
android:title="@string/menu_add_note"
android:icon="@drawable/ic_add"
app:showAsAction="never"/>
<item
android:id="@+id/action_delete"
android:title="@string/menu_delete_note"
android:icon="@drawable/ic_delete_white"
app:showAsAction="never"/>
</menu>

0 comments on commit 7eb6c1f

Please sign in to comment.