Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Day3 shows the 1st floor and the rest show the basement. #1123

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@ import io.github.droidkaigi.confsched2023.floormap.FloorMapContentUiState.LargeF
import io.github.droidkaigi.confsched2023.floormap.FloorMapContentUiState.SmallFloorMapContentUiState
import io.github.droidkaigi.confsched2023.floormap.section.FloorMapSideEventListUiState
import io.github.droidkaigi.confsched2023.floormap.section.FloorMapUiState
import io.github.droidkaigi.confsched2023.model.DroidKaigi2023Day.Day3
import io.github.droidkaigi.confsched2023.model.FloorLevel
import io.github.droidkaigi.confsched2023.model.SideEvents
import io.github.droidkaigi.confsched2023.ui.UserMessageStateHolder
import io.github.droidkaigi.confsched2023.ui.buildUiState
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime
import javax.inject.Inject

@HiltViewModel
class FloorMapScreenViewModel @Inject constructor(
val userMessageStateHolder: UserMessageStateHolder,
) : ViewModel(), UserMessageStateHolder by userMessageStateHolder {
private val floorLevelStateFlow = MutableStateFlow(FloorLevel.Basement)
private val floorLevelStateFlow = MutableStateFlow(
if (isTodayDay3()) {
FloorLevel.Ground
} else {
FloorLevel.Basement
},
)
private val floorMapSideEventListUiState = FloorMapSideEventListUiState(
sideEvents = SideEvents,
)
Expand Down Expand Up @@ -57,6 +68,15 @@ class FloorMapScreenViewModel @Inject constructor(
)
}

private fun isTodayDay3(): Boolean {
val now = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault())

val currentInTokyo = now.toInstant(TimeZone.currentSystemDefault()).toLocalDateTime(
TimeZone.of("Asia/Tokyo"),
)
return currentInTokyo >= Day3.start.toLocalDateTime(TimeZone.of("Asia/Tokyo")) &&
currentInTokyo < Day3.end.toLocalDateTime(TimeZone.of("Asia/Tokyo"))
}
fun onClickFloorLevelSwitcher(floorLevel: FloorLevel) {
floorLevelStateFlow.value = floorLevel
}
Expand Down
Loading