- Add KDoc to all public Composable functions with parameter descriptions - Add inline comments for non-obvious algorithms (42-cell grid, pager mapping) - Add @Suppress reason comments for monthNumber deprecation - Document collapseProgress range and physical meaning - Add named constant comments for START_PAGE - Add Preview name to App() Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
63 lines
1.9 KiB
Kotlin
63 lines
1.9 KiB
Kotlin
package plus.rua.project.ui
|
|
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.aspectRatio
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import kotlinx.datetime.LocalDate
|
|
|
|
/**
|
|
* 单个日期单元格,显示日期数字并支持选中/今天/非当月状态。
|
|
*
|
|
* @param date 日期
|
|
* @param isCurrentMonth 是否属于当前显示月份
|
|
* @param isSelected 是否为选中日期
|
|
* @param isToday 是否为今天
|
|
* @param onClick 点击回调
|
|
* @param modifier 外部布局修饰符
|
|
*/
|
|
@Composable
|
|
fun DayCell(
|
|
date: LocalDate,
|
|
isCurrentMonth: Boolean,
|
|
isSelected: Boolean,
|
|
isToday: Boolean,
|
|
onClick: () -> Unit,
|
|
modifier: Modifier = Modifier
|
|
) {
|
|
val contentColor = when {
|
|
isSelected -> MaterialTheme.colorScheme.onPrimary
|
|
!isCurrentMonth -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.38f)
|
|
else -> MaterialTheme.colorScheme.onSurface
|
|
}
|
|
|
|
val backgroundColor = when {
|
|
isSelected -> MaterialTheme.colorScheme.primary
|
|
else -> MaterialTheme.colorScheme.surface
|
|
}
|
|
|
|
Box(
|
|
modifier = modifier
|
|
.aspectRatio(1f)
|
|
.clip(CircleShape)
|
|
.background(backgroundColor)
|
|
.clickable(onClick = onClick),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Text(
|
|
text = date.day.toString(),
|
|
textAlign = TextAlign.Center,
|
|
color = contentColor,
|
|
style = MaterialTheme.typography.bodyMedium
|
|
)
|
|
}
|
|
}
|