Skip to content

Commit

Permalink
feat: display each time on the time table.
Browse files Browse the repository at this point in the history
  • Loading branch information
ParkJong-Hun committed Aug 11, 2024
1 parent 5128d30 commit dc4edb1
Showing 1 changed file with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@ package io.github.droidkaigi.confsched.sessions.section

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.calculateEndPadding
import androidx.compose.foundation.layout.calculateStartPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import io.github.droidkaigi.confsched.designsystem.theme.LocalRoomTheme
import io.github.droidkaigi.confsched.model.Timetable
import io.github.droidkaigi.confsched.model.TimetableItem
import io.github.droidkaigi.confsched.sessions.component.TimetableTime
import io.github.droidkaigi.confsched.ui.component.TimetableItemCard
import io.github.droidkaigi.confsched.ui.component.TimetableItemTag
import io.github.droidkaigi.confsched.ui.icon
Expand All @@ -24,7 +31,7 @@ import kotlinx.collections.immutable.PersistentMap
const val TimetableListTestTag = "TimetableList"

data class TimetableListUiState(
val timetableItemMap: PersistentMap<String, List<TimetableItem>>,
val timetableItemMap: PersistentMap<Pair<String, String>, List<TimetableItem>>,
val timetable: Timetable,
)

Expand All @@ -37,34 +44,59 @@ fun TimetableList(
contentPadding: PaddingValues,
modifier: Modifier = Modifier,
) {
val layoutDirection = LocalLayoutDirection.current
LazyColumn(
modifier = modifier.testTag(TimetableListTestTag),
state = scrollState,
verticalArrangement = Arrangement.spacedBy(10.dp),
contentPadding = contentPadding,
verticalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(
top = contentPadding.calculateTopPadding(),
bottom = contentPadding.calculateBottomPadding(),
start = 16.dp + contentPadding.calculateStartPadding(layoutDirection),
end = 16.dp + contentPadding.calculateEndPadding(layoutDirection),
),
) {
items(uiState.timetable.timetableItems, key = { it.id.value }) { timetableItem ->
val isBookmarked = uiState.timetable.bookmarks.contains(timetableItem.id)
TimetableItemCard(
isBookmarked = isBookmarked,
timetableItem = timetableItem,
onBookmarkClick = onBookmarkClick,
tags = {
TimetableItemTag(
tagText = timetableItem.room.name.currentLangTitle,
icon = timetableItem.room.icon,
tagColor = LocalRoomTheme.current.primaryColor,
modifier = Modifier.background(LocalRoomTheme.current.containerColor),
)
Spacer(modifier = Modifier.padding(3.dp))
timetableItem.language.labels.forEach { label ->
TimetableItemTag(tagText = label, tagColor = MaterialTheme.colorScheme.onSurfaceVariant)
Spacer(modifier = Modifier.padding(3.dp))
items(
// TODO: Check whether the number of recompositions increases.
items = uiState.timetableItemMap.toList(),
key = { it.first },
) { (time, timetableItems) ->
Row {
TimetableTime(
startTime = time.first,
endTime = time.second,
)
Spacer(modifier = Modifier.width(12.dp))
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
timetableItems.onEach { timetableItem ->
val isBookmarked =
uiState.timetable.bookmarks.contains(timetableItem.id)
TimetableItemCard(
isBookmarked = isBookmarked,
timetableItem = timetableItem,
onBookmarkClick = onBookmarkClick,
tags = {
TimetableItemTag(
tagText = timetableItem.room.name.currentLangTitle,
icon = timetableItem.room.icon,
tagColor = LocalRoomTheme.current.primaryColor,
modifier = Modifier.background(LocalRoomTheme.current.containerColor),
)
Spacer(modifier = Modifier.padding(3.dp))
timetableItem.language.labels.forEach { label ->
TimetableItemTag(
tagText = label,
tagColor = MaterialTheme.colorScheme.onSurfaceVariant
)
Spacer(modifier = Modifier.padding(3.dp))
}
Spacer(modifier = Modifier.weight(1f))
},
onTimetableItemClick = onTimetableItemClick,
)
}
Spacer(modifier = Modifier.weight(1f))
},
onTimetableItemClick = onTimetableItemClick,
)
}
}
}
}
}

0 comments on commit dc4edb1

Please sign in to comment.