-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6103f75
commit a190b5c
Showing
12 changed files
with
368 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package club.nito.feature.schedule | ||
|
||
sealed class ScheduleListEvent { | ||
data class NavigateToScheduleDetail(val scheduleId: String) : ScheduleListEvent() | ||
} |
9 changes: 9 additions & 0 deletions
9
feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package club.nito.feature.schedule | ||
|
||
import club.nito.core.domain.model.ParticipantSchedule | ||
|
||
sealed class ScheduleListIntent { | ||
data class ClickShowConfirmParticipateDialog(val schedule: ParticipantSchedule) : ScheduleListIntent() | ||
data class ClickParticipateSchedule(val schedule: ParticipantSchedule) : ScheduleListIntent() | ||
data object ClickDismissConfirmParticipateDialog : ScheduleListIntent() | ||
} |
16 changes: 16 additions & 0 deletions
16
...e/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListScreenUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package club.nito.feature.schedule | ||
|
||
import club.nito.core.common.NitoDateTimeFormatter | ||
import club.nito.core.domain.model.ParticipantSchedule | ||
import club.nito.core.model.FetchMultipleContentResult | ||
|
||
data class ScheduleListScreenUiState( | ||
val dateTimeFormatter: NitoDateTimeFormatter, | ||
val scheduleList: FetchMultipleContentResult<ParticipantSchedule>, | ||
val confirmParticipateDialog: ConfirmParticipateDialogUiState, | ||
) | ||
|
||
sealed class ConfirmParticipateDialogUiState { | ||
data class Show(val schedule: ParticipantSchedule) : ConfirmParticipateDialogUiState() | ||
data object Hide : ConfirmParticipateDialogUiState() | ||
} |
73 changes: 73 additions & 0 deletions
73
feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleListViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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.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 | ||
|
||
@HiltViewModel | ||
class ScheduleListViewModel @Inject constructor( | ||
getParticipantScheduleListUseCase: GetParticipantScheduleListUseCase, | ||
val userMessageStateHolder: UserMessageStateHolder, | ||
private val dateTimeFormatter: NitoDateTimeFormatter, | ||
) : ViewModel(), | ||
UserMessageStateHolder by userMessageStateHolder { | ||
private val showConfirmParticipateSchedule = MutableStateFlow<ParticipantSchedule?>(null) | ||
|
||
private val scheduleList = getParticipantScheduleListUseCase().stateIn( | ||
scope = viewModelScope, | ||
started = SharingStarted.WhileSubscribed(5_000), | ||
initialValue = FetchMultipleContentResult.Loading, | ||
) | ||
|
||
val uiState: StateFlow<ScheduleListScreenUiState> = buildUiState( | ||
showConfirmParticipateSchedule, | ||
scheduleList, | ||
) { showConfirmParticipateSchedule, scheduleList -> | ||
ScheduleListScreenUiState( | ||
dateTimeFormatter = dateTimeFormatter, | ||
scheduleList = scheduleList, | ||
confirmParticipateDialog = showConfirmParticipateSchedule | ||
?.let(ConfirmParticipateDialogUiState::Show) | ||
?: ConfirmParticipateDialogUiState.Hide, | ||
) | ||
} | ||
|
||
private val _events = MutableStateFlow<List<ScheduleListEvent>>(emptyList()) | ||
val event: Flow<ScheduleListEvent?> = _events.map { it.firstOrNull() } | ||
|
||
fun dispatch(intent: ScheduleListIntent) { | ||
viewModelScope.launch { | ||
when (intent) { | ||
is ScheduleListIntent.ClickShowConfirmParticipateDialog -> showConfirmParticipateSchedule.emit(intent.schedule) | ||
is ScheduleListIntent.ClickParticipateSchedule -> { | ||
showConfirmParticipateSchedule.emit(null) | ||
|
||
val scheduledAt = dateTimeFormatter.formatDateTimeString(intent.schedule.scheduledAt) | ||
userMessageStateHolder.showMessage("$scheduledAt に参加登録しました 🎉") | ||
} | ||
|
||
ScheduleListIntent.ClickDismissConfirmParticipateDialog -> showConfirmParticipateSchedule.emit(null) | ||
} | ||
} | ||
} | ||
|
||
fun consume(event: ScheduleListEvent) { | ||
viewModelScope.launch { | ||
_events.emit(_events.value.filterNot { it == event }) | ||
} | ||
} | ||
} |
106 changes: 97 additions & 9 deletions
106
feature/schedule/src/androidMain/kotlin/club/nito/feature/schedule/ScheduleScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,124 @@ | ||
package club.nito.feature.schedule | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.SnackbarHost | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
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.message.SnackbarMessageEffect | ||
import club.nito.feature.schedule.component.ScheduleListSection | ||
|
||
@Composable | ||
fun ScheduleRoute() { | ||
ScheduleScreen() | ||
fun ScheduleRoute( | ||
viewModel: ScheduleListViewModel = hiltViewModel(), | ||
) { | ||
viewModel.event.collectAsState(initial = null).value?.let { | ||
LaunchedEffect(it.hashCode()) { | ||
when (it) { | ||
is ScheduleListEvent.NavigateToScheduleDetail -> {} | ||
} | ||
viewModel.consume(it) | ||
} | ||
} | ||
|
||
val uiState by viewModel.uiState.collectAsState() | ||
val snackbarHostState = remember { SnackbarHostState() } | ||
|
||
SnackbarMessageEffect( | ||
snackbarHostState = snackbarHostState, | ||
userMessageStateHolder = viewModel.userMessageStateHolder, | ||
) | ||
|
||
ScheduleScreen( | ||
uiState = uiState, | ||
snackbarHostState = snackbarHostState, | ||
dispatch = viewModel::dispatch, | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
private fun ScheduleScreen() { | ||
private fun ScheduleScreen( | ||
uiState: ScheduleListScreenUiState, | ||
snackbarHostState: SnackbarHostState, | ||
dispatch: (ScheduleListIntent) -> Unit = {}, | ||
) { | ||
val confirmParticipateDialog = uiState.confirmParticipateDialog | ||
|
||
Scaffold( | ||
topBar = { | ||
CenterAlignedTopAppBar( | ||
title = { | ||
Text( | ||
text = "Schedule", | ||
text = "スケジュール一覧", | ||
) | ||
}, | ||
) | ||
}, | ||
content = { padding -> | ||
Text( | ||
text = "Schedule", | ||
modifier = Modifier.padding(padding), | ||
) | ||
snackbarHost = { SnackbarHost(snackbarHostState) }, | ||
content = { innerPadding -> | ||
if (confirmParticipateDialog is ConfirmParticipateDialogUiState.Show) { | ||
ConfirmParticipateDialog( | ||
schedule = confirmParticipateDialog.schedule, | ||
dateTimeFormatter = uiState.dateTimeFormatter, | ||
onParticipateRequest = { dispatch(ScheduleListIntent.ClickParticipateSchedule(it)) }, | ||
onDismissRequest = { dispatch(ScheduleListIntent.ClickDismissConfirmParticipateDialog) }, | ||
) | ||
} | ||
|
||
Column( | ||
modifier = Modifier.padding(innerPadding), | ||
) { | ||
ScheduleListSection( | ||
scheduleList = uiState.scheduleList, | ||
dateTimeFormatter = uiState.dateTimeFormatter, | ||
modifier = Modifier.fillMaxSize(), | ||
onScheduleClick = { dispatch(ScheduleListIntent.ClickShowConfirmParticipateDialog(it)) }, | ||
) | ||
} | ||
}, | ||
) | ||
} | ||
|
||
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(), | ||
) | ||
} | ||
} |
Oops, something went wrong.