Skip to content

Commit c99b6b5

Browse files
david-allisonBrayanDSO
authored andcommitted
refactor(card-browser): browser destination
* ToCard => ScrollToCard * Move EXTRA_CARD_ID_KEY to ViewModel This should be a responsibility of the browser, not the destination Assisted-by: Claude Opus 4.7 - all
1 parent dabe866 commit c99b6b5

4 files changed

Lines changed: 9 additions & 10 deletions

File tree

AnkiDroid/src/main/java/com/ichi2/anki/browser/BrowserDestination.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,17 @@ sealed interface BrowserDestination : Destination {
3737
}
3838

3939
/**
40-
* Opens the [CardBrowser] with the specified deck selected,
41-
* and automatically scrolls to [cardId] if the card is present on the deck.
40+
* Opens the [CardBrowser] scoped to [deckId], auto-scrolling to [cardId]
41+
* if the card is present on the deck.
4242
*/
43-
data class ToCard(
43+
data class ScrollToCard(
4444
val deckId: DeckId,
4545
val cardId: CardId,
4646
) : BrowserDestination {
4747
override fun toIntent(context: Context): Intent =
4848
Intent(context, CardBrowser::class.java).apply {
4949
putExtra(CardBrowserViewModel.EXTRA_DECK_ID, deckId)
50-
putExtra(EXTRA_CARD_ID_KEY, cardId)
50+
putExtra(CardBrowserViewModel.EXTRA_CARD_ID_KEY, cardId)
5151
}
52-
53-
companion object {
54-
const val EXTRA_CARD_ID_KEY = "cardId"
55-
}
5652
}
5753
}

AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserLaunchOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun Intent.toCardBrowserLaunchOptions(): CardBrowserLaunchOptions? {
5454
return CardBrowserLaunchOptions.SearchQueryJs(it, getBooleanExtra("all_decks", false))
5555
}
5656

57-
getLongExtra(BrowserDestination.ToCard.EXTRA_CARD_ID_KEY)?.let { cardId ->
57+
getLongExtra(CardBrowserViewModel.EXTRA_CARD_ID_KEY)?.let { cardId ->
5858
return CardBrowserLaunchOptions.ScrollToCard(cardId)
5959
}
6060

AnkiDroid/src/main/java/com/ichi2/anki/browser/CardBrowserViewModel.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,9 @@ class CardBrowserViewModel(
14301430
/** Intent extra carrying the [DeckId] the browser should open scoped to. */
14311431
const val EXTRA_DECK_ID = "deckId"
14321432

1433+
/** Intent extra carrying a [CardId] to auto-scroll to once the browser opens. */
1434+
const val EXTRA_CARD_ID_KEY = "cardId"
1435+
14331436
/** Prevents one-shot extras from being re-applied after process death. */
14341437
private const val STATE_LAUNCH_INTENT_CONSUMED = "launchIntentConsumed"
14351438

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/ReviewerViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ class ReviewerViewModel(
346346
private suspend fun emitBrowseDestination() {
347347
val deckId = withCol { decks.getCurrentId() }
348348
val cardId = currentCard.await().id
349-
val destination = BrowserDestination.ToCard(deckId, cardId)
349+
val destination = BrowserDestination.ScrollToCard(deckId, cardId)
350350
Timber.i("Launching 'browse options' for deck %d", deckId)
351351
destinationFlow.emit(destination)
352352
}

0 commit comments

Comments
 (0)