From 31446c8e6c5e13ba981aacc1d6f2b5ca7240dc96 Mon Sep 17 00:00:00 2001 From: junior-od Date: Tue, 6 Jan 2026 14:08:55 +0100 Subject: [PATCH] Interests: used filterIsInstance to find the TopicNavKey and get its ID instead of explicit type check and cast approach. --- .../feature/interests/impl/InterestsViewModel.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/feature/interests/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/interests/impl/InterestsViewModel.kt b/feature/interests/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/interests/impl/InterestsViewModel.kt index 7bf709b3e..afda1a453 100644 --- a/feature/interests/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/interests/impl/InterestsViewModel.kt +++ b/feature/interests/impl/src/main/kotlin/com/google/samples/apps/nowinandroid/feature/interests/impl/InterestsViewModel.kt @@ -48,8 +48,9 @@ class InterestsViewModel @AssistedInject constructor( private val selectedTopicId: StateFlow = snapshotFlow { navigationState.currentSubStack - .lastOrNull { it is TopicNavKey } - ?.let { (it as TopicNavKey).id } + .filterIsInstance() + .lastOrNull() + ?.id }.stateIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(5_000),