Skip to content

Commit a9452f3

Browse files
committed
refactor(deck-picker): move deck selection to ViewModel
Assisted-by: Claude Opus 4.6
1 parent 13a30fe commit a9452f3

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,9 @@ open class DeckPicker :
451451

452452
private fun showDeckPickerContextMenu(deckId: DeckId) =
453453
launchCatchingTask {
454-
withCol { decks.select(deckId) }
454+
viewModel.selectDeck(deckId).join()
455455
val menu = DeckPickerContextMenu.newInstance(deckId)
456456
CardBrowser.clearLastDeckId()
457-
updateDeckList()
458457
showDialogFragment(menu)
459458
}
460459

@@ -463,8 +462,7 @@ open class DeckPicker :
463462
x: Float,
464463
y: Float,
465464
) = launchCatchingTask {
466-
withCol { decks.select(deckId) }
467-
updateDeckList()
465+
viewModel.selectDeck(deckId).join()
468466
DeckPickerMenuContentProvider.show(
469467
deckPicker = this@DeckPicker,
470468
deckId = deckId,

AnkiDroid/src/main/java/com/ichi2/anki/deckpicker/DeckPickerViewModel.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ class DeckPickerViewModel :
275275
flowOfDeckCountsChanged.emit(Unit)
276276
}
277277

278+
/**
279+
* Marks [deckId] as the currently selected deck and updates the selection in the deck list.
280+
*/
281+
fun selectDeck(deckId: DeckId) =
282+
viewModelScope.launch {
283+
// TODO: should we always reset the Card Browser default deck here?
284+
withCol { decks.select(deckId) }
285+
focusedDeck = deckId
286+
flowOfRefreshDeckList.emit(Unit)
287+
}
288+
278289
fun browseCards(deckId: DeckId) =
279290
launchCatchingIO {
280291
withCol { decks.select(deckId) }

0 commit comments

Comments
 (0)