Migrate interest module to use koin

pull/2064/head
lihenggui 1 year ago
parent 41b0cf19f7
commit 2657cb75c7

@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.nowinandroid.cmp.feature)
alias(libs.plugins.nowinandroid.android.library.jacoco)
alias(libs.plugins.roborazzi)
alias(libs.plugins.kotlin.serialization)
}
android {
namespace = "com.google.samples.apps.nowinandroid.feature.interests"
@ -34,6 +35,7 @@ kotlin {
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.kotlinx.serialization.core)
}
commonMain.dependencies {
implementation(projects.core.testing)

@ -35,13 +35,14 @@ import nowinandroid.feature.interests.generated.resources.feature_interests_empt
import nowinandroid.feature.interests.generated.resources.feature_interests_loading
import org.jetbrains.compose.resources.stringResource
import org.jetbrains.compose.ui.tooling.preview.PreviewParameter
import org.koin.compose.viewmodel.koinViewModel
@Composable
fun InterestsRoute(
onTopicClick: (String) -> Unit,
modifier: Modifier = Modifier,
highlightSelectedTopic: Boolean = false,
viewModel: InterestsViewModel,
viewModel: InterestsViewModel = koinViewModel(),
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

@ -30,9 +30,8 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import me.tatarka.inject.annotations.Inject
class InterestsViewModel @Inject constructor(
class InterestsViewModel(
private val savedStateHandle: SavedStateHandle,
val userDataRepository: UserDataRepository,
getFollowableTopics: GetFollowableTopicsUseCase,

@ -0,0 +1,25 @@
/*
* 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.interests.di
import com.google.samples.apps.nowinandroid.feature.interests.InterestsViewModel
import org.koin.core.module.dsl.viewModel
import org.koin.dsl.module
val interestModule = module {
viewModel { InterestsViewModel(get(), get(), get()) }
}

@ -29,5 +29,5 @@ fun NavController.navigateToInterests(
initialTopicId: String? = null,
navOptions: NavOptions? = null,
) {
// navigate(route = InterestsRoute(initialTopicId), navOptions)
navigate(route = InterestsRoute(initialTopicId), navOptions)
}

Loading…
Cancel
Save