Skip to content

Commit

Permalink
feat(new reviewer): counts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO committed Jun 22, 2024
1 parent 16c23cf commit 8b196f6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -70,6 +74,7 @@ class ReviewerFragment :
super.onViewCreated(view, savedInstanceState)

setupAnswerButtons(view)
setupCounts(view)

view.findViewById<MaterialToolbar>(R.id.toolbar).apply {
setOnMenuItemClickListener(this@ReviewerFragment)
Expand Down Expand Up @@ -178,6 +183,28 @@ class ReviewerFragment :
}
}

private fun setupCounts(view: View) {
val newCount = view.findViewById<MaterialTextView>(R.id.new_count)
val learnCount = view.findViewById<MaterialTextView>(R.id.lrn_count)
val reviewCount = view.findViewById<MaterialTextView>(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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,6 +72,7 @@ class ReviewerViewModel(cardMediaPlayer: CardMediaPlayer) :
val canSuspendNoteFlow = MutableStateFlow(true)
val undoLabelFlow = MutableStateFlow<String?>(null)
val redoLabelFlow = MutableStateFlow<String?>(null)
val countsFlow = MutableStateFlow(Counts() to Counts.Queue.NEW)

override val server = AnkiServer(this).also { it.start() }
private val stateMutationKey = TimeManager.time.intTimeMS().toString()
Expand Down Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion AnkiDroid/src/main/res/layout/reviewer2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,40 @@
android:layout_height="wrap_content"
android:background="?attr/alternativeBackgroundColor"
app:menu="@menu/reviewer2"
/>
>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/new_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/newCountColor"
app:layout_constraintEnd_toStartOf="@id/lrn_count"
android:paddingEnd="5dp"
tools:text="27"
/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/lrn_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/learnCountColor"
app:layout_constraintStart_toEndOf="@id/new_count"
app:layout_constraintEnd_toStartOf="@id/rev_count"
android:paddingEnd="5dp"
tools:text="81"
/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/rev_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/reviewCountColor"
app:layout_constraintStart_toEndOf="@id/lrn_count"
tools:text="54"
/>


</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>

<com.google.android.material.card.MaterialCardView
Expand Down

0 comments on commit 8b196f6

Please sign in to comment.