Skip to content

Commit 627a08b

Browse files
BrayanDSOlukstbit
authored andcommitted
refactor: use sealed interface in BrowserDestination
so other "destinations" can be added later
1 parent 50955b1 commit 627a08b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import com.ichi2.anki.utils.Destination
2626
/**
2727
* Opens the [CardBrowser]
2828
*/
29-
class BrowserDestination(
30-
val deckId: DeckId,
31-
) : Destination {
32-
override fun toIntent(context: Context): Intent {
33-
AnkiDroidApp.instance.sharedPrefsLastDeckIdRepository.lastDeckId = deckId
34-
return Intent(context, CardBrowser::class.java)
29+
sealed interface BrowserDestination : Destination {
30+
data class ToDeck(
31+
val deckId: DeckId,
32+
) : BrowserDestination {
33+
override fun toIntent(context: Context): Intent {
34+
AnkiDroidApp.instance.sharedPrefsLastDeckIdRepository.lastDeckId = deckId
35+
return Intent(context, CardBrowser::class.java)
36+
}
3537
}
3638
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class DeckPickerViewModel :
253253
fun browseCards(deckId: DeckId) =
254254
launchCatchingIO {
255255
withCol { decks.select(deckId) }
256-
flowOfDestination.emit(BrowserDestination(deckId))
256+
flowOfDestination.emit(BrowserDestination.ToDeck(deckId))
257257
}
258258

259259
fun addNote(

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
@@ -291,7 +291,7 @@ class ReviewerViewModel(
291291

292292
private suspend fun emitBrowseDestination() {
293293
val deckId = withCol { decks.getCurrentId() }
294-
val destination = BrowserDestination(deckId)
294+
val destination = BrowserDestination.ToDeck(deckId)
295295
Timber.i("Launching 'browse options' for deck %d", deckId)
296296
destinationFlow.emit(destination)
297297
}

0 commit comments

Comments
 (0)