Remove string-based argument name from navigation code

Change-Id: I7c880cc73374e053ea0d41df00a4bda95ed4b551
pull/1413/head
Don Turner 5 months ago
parent ec71b2a07e
commit fc58680c06

@ -25,7 +25,6 @@ import com.google.samples.apps.nowinandroid.core.domain.GetFollowableTopicsUseCa
import com.google.samples.apps.nowinandroid.core.domain.TopicSortField
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsRoute
import com.google.samples.apps.nowinandroid.feature.interests.navigation.TOPIC_ID_KEY
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
@ -41,9 +40,12 @@ class InterestsViewModel @Inject constructor(
getFollowableTopics: GetFollowableTopicsUseCase,
) : ViewModel() {
// Key used to save and retrieve the currently selected topic id from saved state.
private val selectedTopicIdKey = "selectedTopicIdKey"
private val interestsRoute: InterestsRoute = savedStateHandle.toRoute()
private val selectedTopicId = savedStateHandle.getStateFlow(
key = TOPIC_ID_KEY,
key = selectedTopicIdKey,
initialValue = interestsRoute.initialTopicId,
)
@ -64,7 +66,7 @@ class InterestsViewModel @Inject constructor(
}
fun onTopicClick(topicId: String?) {
savedStateHandle[TOPIC_ID_KEY] = topicId
savedStateHandle[selectedTopicIdKey] = topicId
}
}

@ -20,8 +20,6 @@ import androidx.navigation.NavController
import androidx.navigation.NavOptions
import kotlinx.serialization.Serializable
const val TOPIC_ID_KEY = "topicId"
@Serializable data class InterestsRoute(
// The ID of the topic which will be initially selected at this destination
val initialTopicId: String?,

Loading…
Cancel
Save