Skip to content

Commit

Permalink
Remove workday tab
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Aug 10, 2024
1 parent 64f4a12 commit f978ce6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toInstant
import kotlinx.datetime.toLocalDateTime
import kotlin.time.Duration.Companion.days

public enum class DroidKaigi2024Day(
public val dayIndex: Int,
public val visibleInTab: Boolean,
public val dayOfMonth: Int,
public val start: Instant,
public val end: Instant,
) {
// We are not using Workday sessions in the app
Workday(
dayIndex = 0,
visibleInTab = false,
dayOfMonth = 11,
start = LocalDateTime
.parse("2024-09-11T00:00:00")
Expand All @@ -26,6 +27,7 @@ public enum class DroidKaigi2024Day(
),
ConferenceDay1(
dayIndex = 1,
visibleInTab = true,
dayOfMonth = 12,
start = LocalDateTime
.parse("2024-09-12T00:00:00")
Expand All @@ -36,6 +38,7 @@ public enum class DroidKaigi2024Day(
),
ConferenceDay2(
dayIndex = 2,
visibleInTab = true,
dayOfMonth = 13,
start = LocalDateTime
.parse("2024-09-13T00:00:00")
Expand All @@ -46,30 +49,15 @@ public enum class DroidKaigi2024Day(
),
;

fun getDropDownText(language: String): String {
val japanese = "ja"

val date = this.start.toLocalDateTime(TimeZone.currentSystemDefault())

val year = if (language == japanese) {
"${date.year}"
} else {
"${date.year}"
}

val month = if (language == japanese) {
"${date.monthNumber}"
} else {
date.month.name.lowercase().replaceFirstChar { it.uppercase() }
}

val day = if (language == japanese) {
"${date.dayOfMonth}"
} else {
"${date.dayOfMonth}th"
}
fun tabIndex(): Int {
return entries
.sortedBy { it.dayIndex }
.filter { it.visibleInTab }
.indexOf(this)
}

return "${this.name} ($year $month $day)"
fun monthAndDay(): String {
return "9/$dayOfMonth"
}

public companion object {
Expand All @@ -79,12 +67,15 @@ public enum class DroidKaigi2024Day(
}
}

fun tabDays(): List<DroidKaigi2024Day> {
return entries.filter { it.visibleInTab }
}

/**
* @return appropriate initial day for now
*/
fun initialSelectedDay(clock: Clock): DroidKaigi2024Day {
if (clock.now() < Workday.start.minus(1.days)) return ConferenceDay1
val reversedEntries = entries.sortedByDescending { it.dayIndex }
fun initialSelectedTabDay(clock: Clock): DroidKaigi2024Day {
val reversedEntries = tabDays().sortedByDescending { it.dayIndex }
var selectedDay = reversedEntries.last()
for (entry in reversedEntries) {
if (clock.now() <= entry.end) selectedDay = entry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="workshop">Workshop</string>
<string name="back">Back</string>
<string name="select_language">Select Language</string>
<string name="conference">Conference</string>
<string name="japanese">日本語</string>
<string name="english">English</string>
<string name="timetable">Timetable</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ import io.github.droidkaigi.confsched.model.DroidKaigi2024Day
import io.github.droidkaigi.confsched.model.Timetable
import io.github.droidkaigi.confsched.model.TimetableItem
import io.github.droidkaigi.confsched.model.TimetableUiType
import io.github.droidkaigi.confsched.sessions.section.Timetable
import io.github.droidkaigi.confsched.sessions.section.TimetableListUiState
import io.github.droidkaigi.confsched.sessions.section.TimetableSheet
import io.github.droidkaigi.confsched.sessions.section.TimetableSheetUiState
import io.github.droidkaigi.confsched.ui.SnackbarMessageEffect
import io.github.droidkaigi.confsched.ui.UserMessageStateHolder
Expand Down Expand Up @@ -180,7 +180,7 @@ private fun TimetableScreen(
Column(
modifier = Modifier.padding(top = innerPadding.calculateTopPadding()).fillMaxWidth(),
) {
TimetableSheet(
Timetable(
modifier = Modifier
.fillMaxSize(),
onTimetableItemClick = onTimetableItemClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fun timetableSheet(
}
return if (uiType == TimetableUiType.List) {
TimetableSheetUiState.ListTimetable(
DroidKaigi2024Day.entries.associateWith { day ->
DroidKaigi2024Day.tabDays().associateWith { day ->
val sortAndGroupedTimetableItems = sessionTimetable.filtered(
Filters(
days = listOf(day),
Expand All @@ -99,7 +99,7 @@ fun timetableSheet(
)
} else {
TimetableSheetUiState.GridTimetable(
DroidKaigi2024Day.entries.associateWith { day ->
DroidKaigi2024Day.tabDays().associateWith { day ->
TimetableGridUiState(
timetable = sessionTimetable.dayTimetable(day),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.droidkaigi.confsched.sessions.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -19,18 +18,18 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import conference_app_2024.feature.sessions.generated.resources.conference
import io.github.droidkaigi.confsched.model.DroidKaigi2024Day
import io.github.droidkaigi.confsched.model.DroidKaigi2024Day.ConferenceDay1
import io.github.droidkaigi.confsched.model.DroidKaigi2024Day.ConferenceDay2
import io.github.droidkaigi.confsched.model.DroidKaigi2024Day.Workday
import io.github.droidkaigi.confsched.sessions.SessionsRes
import org.jetbrains.compose.resources.stringResource

@Composable
fun TimetableDayTab(
selectedDay: DroidKaigi2024Day,
onDaySelected: (day: DroidKaigi2024Day) -> Unit,
modifier: Modifier = Modifier,
) {
val selectedTabIndex = selectedDay.dayIndex
val selectedTabIndex = selectedDay.tabIndex()
val selectedColor = Color(0xFF4AFF82)
Column(
modifier = modifier.padding(start = 12.dp),
Expand All @@ -50,86 +49,35 @@ fun TimetableDayTab(
}
},
tabs = {
Tab(
modifier = Modifier.height(64.dp),
selected = true,
onClick = {
onDaySelected(Workday)
},
selectedContentColor = selectedColor,
unselectedContentColor = Color.White,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
if (selectedTabIndex == 0) {
DroidKaigi2024Day.tabDays().forEach { conferenceDay ->
Tab(
modifier = Modifier.height(64.dp),
selected = false,
onClick = {
onDaySelected(conferenceDay)
},
selectedContentColor = selectedColor,
unselectedContentColor = Color.White,
) {
val isSelected = conferenceDay == selectedDay
if (isSelected) {
FloorText(
text = "Workshop",
isSelected = selectedTabIndex == 0,
text = stringResource(SessionsRes.string.conference),
isSelected = isSelected,
)
Text(
text = " (9/11)",
text = " (${conferenceDay.monthAndDay()})",
fontSize = 11.sp,
color = Color(0xFF4AFF82),
)
} else {
FloorText(
text = "9/11",
isSelected = selectedTabIndex == 0,
text = conferenceDay.monthAndDay(),
isSelected = isSelected,
)
}
}
}
Tab(
modifier = Modifier.height(64.dp),
selected = false,
onClick = {
onDaySelected(ConferenceDay1)
},
selectedContentColor = selectedColor,
unselectedContentColor = Color.White,
) {
if (selectedTabIndex == 1) {
FloorText(
text = "Conference",
isSelected = selectedTabIndex == 1,
)
Text(
text = " (9/12)",
fontSize = 11.sp,
color = Color(0xFF4AFF82),
)
} else {
FloorText(
text = "9/12",
isSelected = selectedTabIndex == 1,
)
}
}
Tab(
modifier = Modifier.height(64.dp),
selected = false,
onClick = {
onDaySelected(ConferenceDay2)
},
selectedContentColor = selectedColor,
unselectedContentColor = Color.White,
) {
if (selectedTabIndex == 2) {
FloorText(
text = "Conference",
isSelected = selectedTabIndex == 2,
)
Text(
text = " (9/13)",
fontSize = 11.sp,
color = Color(0xFF4AFF82),
)
} else {
FloorText(
text = "9/13",
isSelected = selectedTabIndex == 2,
)
}
}
},
)
Spacer(modifier = Modifier.height(24.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ sealed interface TimetableSheetUiState {
}

@Composable
fun TimetableSheet(
fun Timetable(
uiState: TimetableSheetUiState,
onTimetableItemClick: (TimetableItem) -> Unit,
onFavoriteClick: (TimetableItem, Boolean) -> Unit,
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
) {
val clock = LocalClock.current
var selectedDay by rememberSaveable { mutableStateOf(DroidKaigi2024Day.initialSelectedDay(clock)) }
var selectedDay by rememberSaveable { mutableStateOf(DroidKaigi2024Day.initialSelectedTabDay(clock)) }
val layoutDirection = LocalLayoutDirection.current
Surface(
modifier = modifier.padding(contentPadding.calculateTopPadding()),
Expand Down

0 comments on commit f978ce6

Please sign in to comment.