Add CalendarMonthPage with 6x7 day grid layout
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
00a24e58fd
commit
edf881d1cc
@ -0,0 +1,71 @@
|
|||||||
|
package plus.rua.project.ui
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlinx.datetime.DatePeriod
|
||||||
|
import kotlinx.datetime.LocalDate
|
||||||
|
import kotlinx.datetime.minus
|
||||||
|
import kotlinx.datetime.plus
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun CalendarMonthPage(
|
||||||
|
year: Int,
|
||||||
|
month: Int,
|
||||||
|
selectedDate: LocalDate,
|
||||||
|
today: LocalDate,
|
||||||
|
onDateClick: (LocalDate) -> Unit,
|
||||||
|
modifier: Modifier = Modifier
|
||||||
|
) {
|
||||||
|
val days = remember(year, month) {
|
||||||
|
generateMonthDays(year, month)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(modifier = modifier) {
|
||||||
|
WeekdayHeader(modifier = Modifier.fillMaxWidth())
|
||||||
|
|
||||||
|
days.chunked(7).forEach { week ->
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(vertical = 2.dp)
|
||||||
|
) {
|
||||||
|
week.forEach { dayData ->
|
||||||
|
DayCell(
|
||||||
|
date = dayData.date,
|
||||||
|
isCurrentMonth = dayData.isCurrentMonth,
|
||||||
|
isSelected = dayData.date == selectedDate,
|
||||||
|
isToday = dayData.date == today,
|
||||||
|
onClick = { onDateClick(dayData.date) },
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private data class DayData(
|
||||||
|
val date: LocalDate,
|
||||||
|
val isCurrentMonth: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private fun generateMonthDays(year: Int, month: Int): List<DayData> {
|
||||||
|
val firstOfMonth = LocalDate(year, month, 1)
|
||||||
|
val offset = firstOfMonth.dayOfWeek.ordinal
|
||||||
|
val startDate = firstOfMonth.minus(DatePeriod(days = offset))
|
||||||
|
|
||||||
|
return (0 until 42).map { i ->
|
||||||
|
val date = startDate.plus(DatePeriod(days = i))
|
||||||
|
DayData(
|
||||||
|
date = date,
|
||||||
|
isCurrentMonth = date.monthNumber == month && date.year == year
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user