Migrate topic module to cmp

pull/2064/head
lihenggui 1 year ago
parent 8af712c226
commit bc784d8824

@ -71,6 +71,7 @@ import nowinandroid.feature.topic.generated.resources.feature_topic_loading
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.Preview
import org.jetbrains.compose.ui.tooling.preview.PreviewParameter
import org.koin.compose.viewmodel.koinViewModel
@Composable
internal fun TopicScreen(
@ -78,7 +79,7 @@ internal fun TopicScreen(
onBackClick: () -> Unit,
onTopicClick: (String) -> Unit,
modifier: Modifier = Modifier,
viewModel: TopicViewModel,
viewModel: TopicViewModel = koinViewModel(),
) {
val topicUiState: TopicUiState by viewModel.topicUiState.collectAsStateWithLifecycle()
val newsUiState: NewsUiState by viewModel.newsUiState.collectAsStateWithLifecycle()

@ -37,9 +37,10 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
import org.koin.android.annotation.KoinViewModel
class TopicViewModel @Inject constructor(
@KoinViewModel
class TopicViewModel(
savedStateHandle: SavedStateHandle,
private val userDataRepository: UserDataRepository,
topicsRepository: TopicsRepository,

@ -0,0 +1,26 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.samples.apps.nowinandroid.feature.topic.di
import com.google.samples.apps.nowinandroid.feature.topic.TopicViewModel
import org.koin.core.module.dsl.viewModel
import org.koin.core.module.dsl.viewModelOf
import org.koin.dsl.module
val topicModule = module {
viewModelOf(::TopicViewModel)
}

@ -20,6 +20,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptionsBuilder
import androidx.navigation.compose.composable
import com.google.samples.apps.nowinandroid.feature.topic.TopicScreen
import kotlinx.serialization.Serializable
@Serializable data class TopicRoute(val id: String)
@ -36,10 +37,10 @@ fun NavGraphBuilder.topicScreen(
onTopicClick: (String) -> Unit,
) {
composable<TopicRoute> {
// TopicScreen(
// showBackButton = showBackButton,
// onBackClick = onBackClick,
// onTopicClick = onTopicClick,
// )
TopicScreen(
showBackButton = showBackButton,
onBackClick = onBackClick,
onTopicClick = onTopicClick,
)
}
}

Loading…
Cancel
Save