diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index eb02672..559e70d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ junit = "4.13.2" kotlin = "2.3.21" material3 = "1.10.0-alpha05" kotlinx-datetime = "0.8.0" +tyme4kt = "1.4.4" [libraries] kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } @@ -28,6 +29,7 @@ compose-components-resources = { module = "org.jetbrains.compose.components:comp compose-uiToolingPreview = { module = "org.jetbrains.compose.ui:ui-tooling-preview", version.ref = "composeMultiplatform" } kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" } kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version = "1.11.0" } +tyme4kt = { module = "cn.6tail:tyme4kt", version.ref = "tyme4kt" } [plugins] androidApplication = { id = "com.android.application", version.ref = "agp" } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 34aaf6b..433742c 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -45,6 +45,7 @@ kotlin { implementation(libs.androidx.lifecycle.viewmodelCompose) implementation(libs.androidx.lifecycle.runtimeCompose) implementation(libs.kotlinx.datetime) + implementation(libs.tyme4kt) } commonTest.dependencies { implementation(libs.kotlin.test) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt index 72f9f46..ff0f69c 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/DayCell.kt @@ -7,12 +7,15 @@ import androidx.compose.animation.core.tween import androidx.compose.animation.core.updateTransition import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -23,7 +26,10 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.Stroke import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.tyme.solar.SolarDay import kotlinx.datetime.LocalDate enum class DayCellState { @@ -105,6 +111,30 @@ fun DayCell( val todayBorderColor = MaterialTheme.colorScheme.primary + val lunarText = remember(date) { + val lunarDay = SolarDay.fromYmd(date.year, date.monthNumber, date.day).getLunarDay() + val name = lunarDay.getName() + if (name == "εˆδΈ€") { + val lunarMonth = lunarDay.getLunarMonth() + "${lunarMonth.getName()}月" + } else { + name + } + } + + val lunarColor by transition.animateColor( + transitionSpec = { tween(250, easing = FastOutSlowInEasing) }, + label = "lunarColor" + ) { state -> + when (state) { + DayCellState.SELECTED_TODAY -> MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.7f) + DayCellState.SELECTED -> MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.7f) + DayCellState.TODAY -> MaterialTheme.colorScheme.primary.copy(alpha = 0.6f) + DayCellState.OTHER_MONTH -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.26f) + DayCellState.NORMAL -> MaterialTheme.colorScheme.onSurface.copy(alpha = 0.5f) + } + } + Box( modifier = modifier .aspectRatio(1f) @@ -134,11 +164,24 @@ fun DayCell( .clickable(onClick = onClick), contentAlignment = Alignment.Center ) { - Text( - text = date.day.toString(), - textAlign = TextAlign.Center, - color = contentColor, - style = MaterialTheme.typography.bodyMedium - ) + Column( + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text( + text = date.day.toString(), + textAlign = TextAlign.Center, + color = contentColor, + style = MaterialTheme.typography.bodyMedium + ) + Text( + text = lunarText, + textAlign = TextAlign.Center, + color = lunarColor, + fontSize = 7.sp, + maxLines = 1, + overflow = TextOverflow.Clip, + lineHeight = 9.sp + ) + } } }