Skip to content

Commit 9c8bda9

Browse files
committed
refactor(card-browser): AppBar methods
* `updateAppBarInfo` should is called `onDeckIdChanged` so it should not be necessary onCollectionLoaded * inline numberOfCardsOrNoteShown * split into deck name changed and count changed * inline into onDeckIdChanged
1 parent b4168e4 commit 9c8bda9

1 file changed

Lines changed: 11 additions & 26 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/CardBrowser.kt

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,15 @@ open class CardBrowser :
478478
}
479479

480480
fun onDeckIdChanged(deckId: DeckId?) {
481-
updateAppBarInfo(deckId)
481+
if (useSearchView) return
482+
launchCatchingTask {
483+
findViewById<TextView>(R.id.deck_name)?.text =
484+
when (deckId) {
485+
null -> getString(R.string.card_browser_all_decks)
486+
ALL_DECKS_ID -> getString(R.string.card_browser_all_decks)
487+
else -> withCol { decks.getLegacy(deckId)?.name }
488+
}
489+
}
482490
}
483491

484492
fun onMultiSelectModeChanged(modeChange: ChangeMultiSelectMode) {
@@ -514,7 +522,8 @@ open class CardBrowser :
514522
}
515523
is SearchState.Completed -> {
516524
Timber.i("CardBrowser:: Completed searchCards() Successfully")
517-
updateAppBarInfo(viewModel.deckId)
525+
// TODO: obtain these values from 'Completed'
526+
findViewById<TextView>(R.id.subtitle)?.text = formatCardCount(viewModel.rowCount, viewModel.cardsOrNotes)
518527
// HACK: required now we use MenuProvider for searches
519528
// this causes a very brief flicker, as we call `setQuery` to restore the menu state
520529
searchView?.post { searchView?.clearFocus() }
@@ -602,7 +611,6 @@ open class CardBrowser :
602611
registerReceiver()
603612

604613
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
605-
updateAppBarInfo(viewModel.deckId)
606614
}
607615

608616
override fun onKeyUp(
@@ -816,12 +824,6 @@ open class CardBrowser :
816824
}
817825
}
818826

819-
/**
820-
* @return A message stating the number of cards/notes shown by the browser.
821-
*/
822-
val numberOfCardsOrNoteShown: String
823-
get() = formatCardCount(viewModel.rowCount, viewModel.cardsOrNotes)
824-
825827
fun formatCardCount(
826828
count: Int,
827829
cardsOrNotes: CardsOrNotes,
@@ -916,23 +918,6 @@ open class CardBrowser :
916918
override val shortcuts
917919
get() = cardBrowserFragment.shortcuts
918920

919-
/**
920-
* Sets the selected deck name and current selection count based on [numberOfCardsOrNoteShown]
921-
*/
922-
private fun updateAppBarInfo(deckId: DeckId?) {
923-
if (useSearchView) return
924-
findViewById<TextView>(R.id.subtitle)?.text = numberOfCardsOrNoteShown
925-
launchCatchingTask {
926-
val deckName =
927-
when (deckId) {
928-
null -> getString(R.string.card_browser_all_decks)
929-
ALL_DECKS_ID -> getString(R.string.card_browser_all_decks)
930-
else -> withCol { decks.getLegacy(deckId)?.name }
931-
}
932-
findViewById<TextView>(R.id.deck_name)?.text = deckName
933-
}
934-
}
935-
936921
// region MenuHost delegation
937922

938923
// This only supports delegation of menus defined using MenuProvider, not `onCreateOptionsMenu`

0 commit comments

Comments
 (0)