Skip to content

Commit

Permalink
Remove due property from DeckAdapter
Browse files Browse the repository at this point in the history
DeckPicker was modified to calculate itself the due count because it
has the required data, there's no need to go through the adapter.

I also refactored a bit the code around setting the subtitle to the due
count, I think this looks and reads better.
  • Loading branch information
lukstbit authored and mikehardy committed Jan 9, 2025
1 parent 8f16958 commit 0b7deff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
22 changes: 7 additions & 15 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ import net.ankiweb.rsdroid.Translations
import org.json.JSONException
import timber.log.Timber
import java.io.File
import kotlin.runCatching as runCatchingKotlin

/**
* The current entry point for AnkiDroid. Displays decks, allowing users to study. Many other functions.
Expand Down Expand Up @@ -2297,24 +2298,15 @@ open class DeckPicker :
deckListAdapter.buildDeckList(tree, currentFilter)

// Set the "x due" subtitle
try {
val due = deckListAdapter.due
val res = resources

if (due != null && supportActionBar != null) {
val subTitle =
if (due == 0) {
null
} else {
res.getQuantityString(R.plurals.widget_cards_due, due, due)
}
supportActionBar!!.subtitle = subTitle

runCatchingKotlin {
val dueCount = tree.newCount + tree.revCount + tree.lrnCount
supportActionBar?.apply {
subtitle = if (dueCount == 0) null else resources.getQuantityString(R.plurals.widget_cards_due, dueCount, dueCount)
val toolbar = findViewById<Toolbar>(R.id.toolbar)
TooltipCompat.setTooltipText(toolbar, toolbar.subtitle)
}
} catch (e: RuntimeException) {
Timber.e(e, "RuntimeException setting time remaining")
}.onFailure {
Timber.w(it, "Failed to set the due count as the subtitle in the toolbar")
}
val current = withCol { decks.current().optLong("id") }
if (viewModel.focusedDeck != current) {
Expand Down
17 changes: 0 additions & 17 deletions AnkiDroid/src/main/java/com/ichi2/anki/widgets/DeckAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ class DeckAdapter(
private val nestedIndent = context.resources.getDimension(R.dimen.keyline_1).toInt()
private var currentDeckId: DeckId = 0

// Totals accumulated as each deck is processed
private var new = 0
private var lrn = 0
private var rev = 0
private var numbersComputed = false

// Flags
private var hasSubdecks = false

Expand Down Expand Up @@ -126,10 +120,6 @@ class DeckAdapter(
deckTree = node
hasSubdecks = node.children.any { it.children.any() }
currentDeckId = withCol { decks.current().optLong("id") }
rev = node.revCount
lrn = node.lrnCount
new = node.newCount
numbersComputed = true
// Filtering performs notifyDataSetChanged after the async work is complete
getFilter()?.filter(filter)
}
Expand Down Expand Up @@ -246,13 +236,6 @@ class DeckAdapter(
return findDeckPosition(parent.did)
}

val due: Int?
get() =
if (numbersComputed) {
new + lrn + rev
} else {
null
}
private val deckList: List<DeckNode>
get() = filteredDeckList

Expand Down

0 comments on commit 0b7deff

Please sign in to comment.