Skip to content

Commit

Permalink
Merge pull request #43 from 2rabs/rt/schedule-feature-compose
Browse files Browse the repository at this point in the history
✨ Schedule モジュールを Compose Multiplatform 化
  • Loading branch information
tatsutakein authored Nov 22, 2023
2 parents 4abda4e + 62c2d8f commit 95a09da
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 108 deletions.
2 changes: 2 additions & 0 deletions app/android/src/main/java/club/nito/app/di/FeatureModules.kt
Original file line number Diff line number Diff line change
@@ -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<Module> = listOf(
topFeatureModule,
scheduleFeatureModule,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,8 +25,9 @@ fun NitoNavHost(
initialRoute = topNavigationRoute,
) {
topScreen(
onScheduleListClick = {},
onScheduleListClick = navigator::navigateToSchedule,
onSettingsClick = {},
)
scheduleScreen()
}
}
2 changes: 2 additions & 0 deletions feature/schedule/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ kotlin {
implementation(projects.core.designsystem)

implementation(libs.kotlinxCoroutinesCore)

implementation(libs.koin)
}
}
androidMain {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
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
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<ParticipantSchedule?>(null)

Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -97,28 +91,3 @@ private fun ScheduleScreen(
},
)
}

private class ScheduleListScreenUiStatePreviewParameterProvider :
PreviewParameterProvider<ScheduleListScreenUiState> {
private val dateTimeFormatter = previewNitoDateTimeFormatter
override val values: Sequence<ScheduleListScreenUiState> = 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(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,30 +108,3 @@ private fun FailureParticipantSchedule(
) {
Text(text = error?.message ?: "スケジュールの取得に失敗しました")
}

private class FetchParticipantScheduleListPreviewParameterProvider :
PreviewParameterProvider<FetchMultipleContentResult<ParticipantSchedule>> {
override val values: Sequence<FetchMultipleContentResult<ParticipantSchedule>> = sequenceOf(
FetchMultipleContentResult.Loading,
FetchMultipleContentResult.NoContent,
FetchMultipleContentResult.Success(
data = listOf(),
),
FetchMultipleContentResult.Failure(
error = UnknownException(null),
),
)
}

@Preview
@Composable
fun PreviewScheduleListSection(
@PreviewParameter(FetchParticipantScheduleListPreviewParameterProvider::class) scheduleList: FetchMultipleContentResult<ParticipantSchedule>,
) {
NitoTheme {
ScheduleListSection(
scheduleList = scheduleList,
dateTimeFormatter = previewNitoDateTimeFormatter,
)
}
}
Original file line number Diff line number Diff line change
@@ -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(),
)
}
}
Empty file.

This file was deleted.

0 comments on commit 95a09da

Please sign in to comment.