diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt index 3e46527dc926..e24b9b57d7bd 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerFragment.kt @@ -18,6 +18,8 @@ package com.ichi2.anki.ui.windows.reviewer import android.content.Context import android.content.Intent import android.os.Bundle +import android.text.SpannableString +import android.text.style.UnderlineSpan import android.view.Menu import android.view.MenuItem import android.view.View @@ -33,6 +35,7 @@ import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import com.google.android.material.appbar.MaterialToolbar import com.google.android.material.button.MaterialButton +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.Flag @@ -47,6 +50,7 @@ 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 +import com.ichi2.libanki.sched.Counts import com.ichi2.utils.increaseHorizontalPaddingOfOverflowMenuIcons import kotlinx.coroutines.launch @@ -70,6 +74,7 @@ class ReviewerFragment : super.onViewCreated(view, savedInstanceState) setupAnswerButtons(view) + setupCounts(view) view.findViewById(R.id.toolbar).apply { setOnMenuItemClickListener(this@ReviewerFragment) @@ -178,6 +183,28 @@ class ReviewerFragment : } } + private fun setupCounts(view: View) { + val newCount = view.findViewById(R.id.new_count) + val learnCount = view.findViewById(R.id.lrn_count) + val reviewCount = view.findViewById(R.id.rev_count) + + viewModel.countsFlow.flowWithLifecycle(lifecycle) + .collectLatestIn(lifecycleScope) { (counts, countsType) -> + newCount.text = counts.new.toString() + learnCount.text = counts.lrn.toString() + reviewCount.text = counts.rev.toString() + + val currentCount = when (countsType) { + Counts.Queue.NEW -> newCount + Counts.Queue.LRN -> learnCount + Counts.Queue.REV -> reviewCount + } + val spannableString = SpannableString(currentCount.text) + spannableString.setSpan(UnderlineSpan(), 0, currentCount.text.length, 0) + currentCount.text = spannableString + } + } + private fun setupFlagMenu(menu: Menu) { val submenu = menu.findItem(R.id.action_flag).subMenu lifecycleScope.launch { diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt index 02679dc28456..35f823cca03f 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt @@ -42,6 +42,7 @@ import com.ichi2.libanki.ChangeManager import com.ichi2.libanki.hasTag import com.ichi2.libanki.note import com.ichi2.libanki.redo +import com.ichi2.libanki.sched.Counts import com.ichi2.libanki.sched.CurrentQueueState import com.ichi2.libanki.undo import com.ichi2.libanki.undoableOp @@ -71,6 +72,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : val canSuspendNoteFlow = MutableStateFlow(true) val undoLabelFlow = MutableStateFlow(null) val redoLabelFlow = MutableStateFlow(null) + val countsFlow = MutableStateFlow(Counts() to Counts.Queue.NEW) override val server = AnkiServer(this).also { it.start() } private val stateMutationKey = TimeManager.time.intTimeMS().toString() @@ -360,6 +362,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) : flagCodeFlow.emit(card.userFlag()) canBuryNoteFlow.emit(isBuryNoteAvailable(card)) canSuspendNoteFlow.emit(isSuspendNoteAvailable(card)) + countsFlow.emit(state.counts to state.countsIndex) } // TODO diff --git a/AnkiDroid/src/main/res/layout/reviewer2.xml b/AnkiDroid/src/main/res/layout/reviewer2.xml index f2ed634dc489..5f5b525c008d 100644 --- a/AnkiDroid/src/main/res/layout/reviewer2.xml +++ b/AnkiDroid/src/main/res/layout/reviewer2.xml @@ -28,7 +28,40 @@ android:layout_height="wrap_content" android:background="?attr/alternativeBackgroundColor" app:menu="@menu/reviewer2" - /> + > + + + + + + + + +