From 3612efb66519d0825c61627fbe37936a5d7c8634 Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 15 May 2026 10:55:04 +0800 Subject: [PATCH] Replace deprecated dayOfMonth with day and fix naming conventions Co-Authored-By: Claude Opus 4.7 --- .../plus/rua/project/CalendarViewModel.kt | 2 +- .../plus/rua/project/ui/CalendarMonthPage.kt | 19 +++++++++---------- .../plus/rua/project/ui/CalendarPager.kt | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt index 20698c5..d2dcd61 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/CalendarViewModel.kt @@ -137,7 +137,7 @@ class CalendarViewModel(private val coroutineScope: CoroutineScope) { val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal val startDate = firstOfMonth.minus(DatePeriod(days = dayOfWeekOffset)) val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) - val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).dayOfMonth + val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day val rows = ((dayOfWeekOffset + daysInMonth - 1) / 7) + 1 val totalDays = rows * 7 diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index 776967e..b3c79bf 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -52,12 +52,11 @@ fun CalendarMonthPage( } val hasSelectedWeek = selectedWeekIndex >= 0 - val H = rowHeightPx.toFloat() + val h = rowHeightPx.toFloat() // 使用与 CalendarMonthView 一致的 effectiveWeeks 计算高度,避免滑动中高度不匹配 val totalHeightDp = if (rowHeightPx > 0) { - val p = collapseProgress - val totalPx = H * (1 + (effectiveWeeks - 1) * (1f - p)) + val totalPx = h * (1 + (effectiveWeeks - 1) * (1f - collapseProgress)) with(density) { totalPx.toDp() } } else { null @@ -78,7 +77,7 @@ fun CalendarMonthPage( } val rowHeightDp = if (rowHeightPx > 0 && rowScale > 0.01f) { - with(density) { (H * rowScale).toDp() } + with(density) { (h * rowScale).toDp() } } else if (rowHeightPx <= 0) { null } else { @@ -87,14 +86,14 @@ fun CalendarMonthPage( val yOffsetDp = if (rowHeightPx > 0 && hasSelectedWeek) { val yPx = when { - isAbove -> weekIndex * H * (1f - collapseProgress) - isSelected -> selectedWeekIndex * H * (1f - collapseProgress) - isBelow -> selectedWeekIndex * H * (1f - collapseProgress) + H + (weekIndex - selectedWeekIndex - 1) * H * (1f - collapseProgress) - else -> weekIndex * H + isAbove -> weekIndex * h * (1f - collapseProgress) + isSelected -> selectedWeekIndex * h * (1f - collapseProgress) + isBelow -> selectedWeekIndex * h * (1f - collapseProgress) + h + (weekIndex - selectedWeekIndex - 1) * h * (1f - collapseProgress) + else -> weekIndex * h } with(density) { yPx.toDp() } } else if (rowHeightPx > 0) { - val yPx = weekIndex * H + val yPx = weekIndex * h with(density) { yPx.toDp() } } else { 0.dp @@ -147,7 +146,7 @@ private fun generateMonthDays(year: Int, month: Int): List { val offset = firstOfMonth.dayOfWeek.ordinal val startDate = firstOfMonth.minus(DatePeriod(days = offset)) val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) - val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).dayOfMonth + val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day val rows = ((offset + daysInMonth - 1) / 7) + 1 val totalDays = rows * 7 diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt index e43eaa0..4033d04 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -1,9 +1,8 @@ package plus.rua.project.ui -import androidx.compose.foundation.pager.PagerState import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.PagerDefaults -import androidx.compose.foundation.pager.rememberPagerState +import androidx.compose.foundation.pager.PagerState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember @@ -109,6 +108,6 @@ internal fun calculateWeeksCount(year: Int, month: Int): Int { val firstOfMonth = LocalDate(year, month, 1) val offset = firstOfMonth.dayOfWeek.ordinal val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1) - val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).dayOfMonth + val daysInMonth = nextMonth.minus(DatePeriod(days = 1)).day return ((offset + daysInMonth - 1) / 7) + 1 }