From 62c2d8f908e79052700ff2ce72d4dbe2576b309b Mon Sep 17 00:00:00 2001 From: Ryo Takeuchi Date: Thu, 23 Nov 2023 00:39:16 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Schedule=20=E3=83=A2=E3=82=B8?= =?UTF-8?q?=E3=83=A5=E3=83=BC=E3=83=AB=E3=82=92=20Compose=20Multiplatform?= =?UTF-8?q?=20=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/club/nito/app/di/FeatureModules.kt | 2 ++ .../club/nito/app/shared/NitoNavHost.kt | 5 ++- feature/schedule/build.gradle.kts | 2 ++ .../nito/feature/schedule/Platform.android.kt | 7 ---- ...ation.kt => ScheduleNavigation.android.kt} | 2 -- .../club/nito/feature/schedule/Greeting.kt | 9 ----- .../club/nito/feature/schedule/Platform.kt | 7 ---- .../feature/schedule/ScheduleListEvent.kt | 0 .../feature/schedule/ScheduleListIntent.kt | 0 .../schedule/ScheduleListScreenUiState.kt | 0 .../feature/schedule/ScheduleListViewModel.kt | 11 +++--- .../feature/schedule/ScheduleNavigation.kt | 19 ++++++++++ .../nito/feature/schedule/ScheduleScreen.kt | 35 ++----------------- .../component/ParticipantScheduleSection.kt | 33 ----------------- .../schedule/di/ScheduleFeatureModule.kt | 15 ++++++++ .../club/nito/feature/schedule/.gitkeep | 0 .../nito/feature/schedule/Platform.ios.kt | 9 ----- 17 files changed, 48 insertions(+), 108 deletions(-) delete mode 100644 feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/Platform.android.kt rename feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/{ScheduleNavigation.kt => ScheduleNavigation.android.kt} (89%) delete mode 100644 feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Greeting.kt delete mode 100644 feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Platform.kt rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt (100%) rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt (100%) rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt (100%) rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt (92%) create mode 100644 feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/ScheduleScreen.kt (71%) rename feature/schedule/src/{androidMain => commonMain}/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt (74%) create mode 100644 feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/di/ScheduleFeatureModule.kt create mode 100644 feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/.gitkeep delete mode 100644 feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/Platform.ios.kt diff --git a/app/android/src/main/java/club/nito/app/di/FeatureModules.kt b/app/android/src/main/java/club/nito/app/di/FeatureModules.kt index d23afee0..29fc8261 100644 --- a/app/android/src/main/java/club/nito/app/di/FeatureModules.kt +++ b/app/android/src/main/java/club/nito/app/di/FeatureModules.kt @@ -1,8 +1,10 @@ package club.nito.app.di +import club.nito.feature.schedule.di.scheduleFeatureModule import club.nito.feature.top.di.topFeatureModule import org.koin.core.module.Module val featureModules: List = listOf( topFeatureModule, + scheduleFeatureModule, ) diff --git a/app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoNavHost.kt b/app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoNavHost.kt index cdc5a6c2..8673f2b6 100644 --- a/app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoNavHost.kt +++ b/app/shared/src/commonMain/kotlin/club/nito/app/shared/NitoNavHost.kt @@ -3,6 +3,8 @@ package club.nito.app.shared import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import club.nito.core.model.AuthStatus +import club.nito.feature.schedule.navigateToSchedule +import club.nito.feature.schedule.scheduleScreen import club.nito.feature.top.topNavigationRoute import club.nito.feature.top.topScreen import moe.tlaster.precompose.navigation.NavHost @@ -23,8 +25,9 @@ fun NitoNavHost( initialRoute = topNavigationRoute, ) { topScreen( - onScheduleListClick = {}, + onScheduleListClick = navigator::navigateToSchedule, onSettingsClick = {}, ) + scheduleScreen() } } diff --git a/feature/schedule/build.gradle.kts b/feature/schedule/build.gradle.kts index 33896b39..93ac3710 100644 --- a/feature/schedule/build.gradle.kts +++ b/feature/schedule/build.gradle.kts @@ -19,6 +19,8 @@ kotlin { implementation(projects.core.designsystem) implementation(libs.kotlinxCoroutinesCore) + + implementation(libs.koin) } } androidMain { diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/Platform.android.kt b/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/Platform.android.kt deleted file mode 100644 index babe048f..00000000 --- a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/Platform.android.kt +++ /dev/null @@ -1,7 +0,0 @@ -package club.nito.feature.schedule - -class AndroidPlatform : Platform { - override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}" -} - -actual fun getPlatform(): Platform = AndroidPlatform() \ No newline at end of file diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt b/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.android.kt similarity index 89% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt rename to feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.android.kt index 84525cfb..21b83b63 100644 --- a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt +++ b/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.android.kt @@ -5,8 +5,6 @@ import androidx.navigation.NavGraphBuilder import androidx.navigation.NavOptions import androidx.navigation.compose.composable -const val scheduleNavigationRoute = "schedule_route" - fun NavController.navigateToSchedule(navOptions: NavOptions? = null) { this.navigate(scheduleNavigationRoute, navOptions) } diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Greeting.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Greeting.kt deleted file mode 100644 index 07382cbf..00000000 --- a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Greeting.kt +++ /dev/null @@ -1,9 +0,0 @@ -package club.nito.feature.schedule - -class Greeting { - private val platform: Platform = getPlatform() - - fun greet(): String { - return "Hello, ${platform.name}!" - } -} \ No newline at end of file diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Platform.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Platform.kt deleted file mode 100644 index 0e84cf73..00000000 --- a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/Platform.kt +++ /dev/null @@ -1,7 +0,0 @@ -package club.nito.feature.schedule - -interface Platform { - val name: String -} - -expect fun getPlatform(): Platform \ No newline at end of file diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt similarity index 100% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt similarity index 100% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt similarity index 100% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt similarity index 92% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt index 0e164903..48ef5fb9 100644 --- a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt @@ -1,14 +1,12 @@ package club.nito.feature.schedule -import androidx.lifecycle.ViewModel -import androidx.lifecycle.viewModelScope import club.nito.core.common.NitoDateTimeFormatter import club.nito.core.domain.GetParticipantScheduleListUseCase import club.nito.core.domain.model.ParticipantSchedule import club.nito.core.model.FetchMultipleContentResult +import club.nito.core.ui.StateMachine import club.nito.core.ui.buildUiState import club.nito.core.ui.message.UserMessageStateHolder -import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted @@ -16,14 +14,13 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch -import javax.inject.Inject +import moe.tlaster.precompose.viewmodel.viewModelScope -@HiltViewModel -class ScheduleListViewModel @Inject constructor( +class ScheduleListViewModel internal constructor( getParticipantScheduleListUseCase: GetParticipantScheduleListUseCase, val userMessageStateHolder: UserMessageStateHolder, private val dateTimeFormatter: NitoDateTimeFormatter, -) : ViewModel(), +) : StateMachine(), UserMessageStateHolder by userMessageStateHolder { private val showConfirmParticipateSchedule = MutableStateFlow(null) diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt new file mode 100644 index 00000000..ba05c906 --- /dev/null +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleNavigation.kt @@ -0,0 +1,19 @@ +package club.nito.feature.schedule + +import moe.tlaster.precompose.navigation.NavOptions +import moe.tlaster.precompose.navigation.Navigator +import moe.tlaster.precompose.navigation.RouteBuilder + +const val scheduleNavigationRoute = "schedule_route" + +fun Navigator.navigateToSchedule(navOptions: NavOptions? = null) { + this.navigate(scheduleNavigationRoute, navOptions) +} + +fun RouteBuilder.scheduleScreen() { + scene( + route = scheduleNavigationRoute, + ) { + ScheduleRoute() + } +} diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt similarity index 71% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt index 52619b03..60f5c24f 100644 --- a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt @@ -12,23 +12,17 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.PreviewParameterProvider -import androidx.hilt.navigation.compose.hiltViewModel -import club.nito.core.common.previewNitoDateTimeFormatter import club.nito.core.designsystem.component.CenterAlignedTopAppBar import club.nito.core.designsystem.component.Scaffold import club.nito.core.designsystem.component.Text -import club.nito.core.designsystem.theme.NitoTheme -import club.nito.core.model.FetchMultipleContentResult import club.nito.core.ui.ConfirmParticipateDialog +import club.nito.core.ui.koinStateMachine import club.nito.core.ui.message.SnackbarMessageEffect import club.nito.feature.schedule.component.ScheduleListSection @Composable fun ScheduleRoute( - viewModel: ScheduleListViewModel = hiltViewModel(), + viewModel: ScheduleListViewModel = koinStateMachine(), ) { viewModel.event.collectAsState(initial = null).value?.let { LaunchedEffect(it.hashCode()) { @@ -97,28 +91,3 @@ private fun ScheduleScreen( }, ) } - -private class ScheduleListScreenUiStatePreviewParameterProvider : - PreviewParameterProvider { - private val dateTimeFormatter = previewNitoDateTimeFormatter - override val values: Sequence = sequenceOf( - ScheduleListScreenUiState( - dateTimeFormatter = dateTimeFormatter, - scheduleList = FetchMultipleContentResult.Loading, - confirmParticipateDialog = ConfirmParticipateDialogUiState.Hide, - ), - ) -} - -@Preview -@Composable -fun PreviewScheduleScreen( - @PreviewParameter(ScheduleListScreenUiStatePreviewParameterProvider::class) uiState: ScheduleListScreenUiState, -) { - NitoTheme { - ScheduleScreen( - uiState = uiState, - snackbarHostState = SnackbarHostState(), - ) - } -} diff --git a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt similarity index 74% rename from feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt rename to feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt index 04dc331e..d0524087 100644 --- a/feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/component/ParticipantScheduleSection.kt @@ -13,18 +13,12 @@ import androidx.compose.material3.CircularProgressIndicator import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.tooling.preview.PreviewParameter -import androidx.compose.ui.tooling.preview.PreviewParameterProvider import androidx.compose.ui.unit.dp import club.nito.core.common.NitoDateTimeFormatter -import club.nito.core.common.previewNitoDateTimeFormatter import club.nito.core.designsystem.component.Text -import club.nito.core.designsystem.theme.NitoTheme import club.nito.core.domain.model.ParticipantSchedule import club.nito.core.model.FetchMultipleContentResult import club.nito.core.model.NitoError -import club.nito.core.model.UnknownException import club.nito.core.ui.ParticipantScheduleItem @Composable @@ -114,30 +108,3 @@ private fun FailureParticipantSchedule( ) { Text(text = error?.message ?: "スケジュールの取得に失敗しました") } - -private class FetchParticipantScheduleListPreviewParameterProvider : - PreviewParameterProvider> { - override val values: Sequence> = sequenceOf( - FetchMultipleContentResult.Loading, - FetchMultipleContentResult.NoContent, - FetchMultipleContentResult.Success( - data = listOf(), - ), - FetchMultipleContentResult.Failure( - error = UnknownException(null), - ), - ) -} - -@Preview -@Composable -fun PreviewScheduleListSection( - @PreviewParameter(FetchParticipantScheduleListPreviewParameterProvider::class) scheduleList: FetchMultipleContentResult, -) { - NitoTheme { - ScheduleListSection( - scheduleList = scheduleList, - dateTimeFormatter = previewNitoDateTimeFormatter, - ) - } -} diff --git a/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/di/ScheduleFeatureModule.kt b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/di/ScheduleFeatureModule.kt new file mode 100644 index 00000000..f40c112a --- /dev/null +++ b/feature/schedule/src/commonMain/kotlin/club/nito/feature/schedule/di/ScheduleFeatureModule.kt @@ -0,0 +1,15 @@ +package club.nito.feature.schedule.di + +import club.nito.feature.schedule.ScheduleListViewModel +import org.koin.core.module.Module +import org.koin.dsl.module + +val scheduleFeatureModule: Module = module { + factory { + ScheduleListViewModel( + getParticipantScheduleListUseCase = get(), + userMessageStateHolder = get(), + dateTimeFormatter = get(), + ) + } +} diff --git a/feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/.gitkeep b/feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/Platform.ios.kt b/feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/Platform.ios.kt deleted file mode 100644 index 39a5c3df..00000000 --- a/feature/schedule/src/iosMain/kotlin/club/nito/feature/schedule/Platform.ios.kt +++ /dev/null @@ -1,9 +0,0 @@ -package club.nito.feature.schedule - -import platform.UIKit.UIDevice - -class IOSPlatform: Platform { - override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion -} - -actual fun getPlatform(): Platform = IOSPlatform() \ No newline at end of file