Replace deprecated dayOfMonth with day and fix naming conventions
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7e972bb4fb
commit
3612efb665
@ -137,7 +137,7 @@ class CalendarViewModel(private val coroutineScope: CoroutineScope) {
|
|||||||
val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal
|
val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal
|
||||||
val startDate = firstOfMonth.minus(DatePeriod(days = dayOfWeekOffset))
|
val startDate = firstOfMonth.minus(DatePeriod(days = dayOfWeekOffset))
|
||||||
val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1)
|
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 rows = ((dayOfWeekOffset + daysInMonth - 1) / 7) + 1
|
||||||
val totalDays = rows * 7
|
val totalDays = rows * 7
|
||||||
|
|
||||||
|
|||||||
@ -52,12 +52,11 @@ fun CalendarMonthPage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val hasSelectedWeek = selectedWeekIndex >= 0
|
val hasSelectedWeek = selectedWeekIndex >= 0
|
||||||
val H = rowHeightPx.toFloat()
|
val h = rowHeightPx.toFloat()
|
||||||
|
|
||||||
// 使用与 CalendarMonthView 一致的 effectiveWeeks 计算高度,避免滑动中高度不匹配
|
// 使用与 CalendarMonthView 一致的 effectiveWeeks 计算高度,避免滑动中高度不匹配
|
||||||
val totalHeightDp = if (rowHeightPx > 0) {
|
val totalHeightDp = if (rowHeightPx > 0) {
|
||||||
val p = collapseProgress
|
val totalPx = h * (1 + (effectiveWeeks - 1) * (1f - collapseProgress))
|
||||||
val totalPx = H * (1 + (effectiveWeeks - 1) * (1f - p))
|
|
||||||
with(density) { totalPx.toDp() }
|
with(density) { totalPx.toDp() }
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@ -78,7 +77,7 @@ fun CalendarMonthPage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val rowHeightDp = if (rowHeightPx > 0 && rowScale > 0.01f) {
|
val rowHeightDp = if (rowHeightPx > 0 && rowScale > 0.01f) {
|
||||||
with(density) { (H * rowScale).toDp() }
|
with(density) { (h * rowScale).toDp() }
|
||||||
} else if (rowHeightPx <= 0) {
|
} else if (rowHeightPx <= 0) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
@ -87,14 +86,14 @@ fun CalendarMonthPage(
|
|||||||
|
|
||||||
val yOffsetDp = if (rowHeightPx > 0 && hasSelectedWeek) {
|
val yOffsetDp = if (rowHeightPx > 0 && hasSelectedWeek) {
|
||||||
val yPx = when {
|
val yPx = when {
|
||||||
isAbove -> weekIndex * H * (1f - collapseProgress)
|
isAbove -> weekIndex * h * (1f - collapseProgress)
|
||||||
isSelected -> selectedWeekIndex * H * (1f - collapseProgress)
|
isSelected -> selectedWeekIndex * h * (1f - collapseProgress)
|
||||||
isBelow -> selectedWeekIndex * H * (1f - collapseProgress) + H + (weekIndex - selectedWeekIndex - 1) * H * (1f - collapseProgress)
|
isBelow -> selectedWeekIndex * h * (1f - collapseProgress) + h + (weekIndex - selectedWeekIndex - 1) * h * (1f - collapseProgress)
|
||||||
else -> weekIndex * H
|
else -> weekIndex * h
|
||||||
}
|
}
|
||||||
with(density) { yPx.toDp() }
|
with(density) { yPx.toDp() }
|
||||||
} else if (rowHeightPx > 0) {
|
} else if (rowHeightPx > 0) {
|
||||||
val yPx = weekIndex * H
|
val yPx = weekIndex * h
|
||||||
with(density) { yPx.toDp() }
|
with(density) { yPx.toDp() }
|
||||||
} else {
|
} else {
|
||||||
0.dp
|
0.dp
|
||||||
@ -147,7 +146,7 @@ private fun generateMonthDays(year: Int, month: Int): List<DayData> {
|
|||||||
val offset = firstOfMonth.dayOfWeek.ordinal
|
val offset = firstOfMonth.dayOfWeek.ordinal
|
||||||
val startDate = firstOfMonth.minus(DatePeriod(days = offset))
|
val startDate = firstOfMonth.minus(DatePeriod(days = offset))
|
||||||
val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1)
|
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 rows = ((offset + daysInMonth - 1) / 7) + 1
|
||||||
val totalDays = rows * 7
|
val totalDays = rows * 7
|
||||||
|
|
||||||
|
|||||||
@ -1,9 +1,8 @@
|
|||||||
package plus.rua.project.ui
|
package plus.rua.project.ui
|
||||||
|
|
||||||
import androidx.compose.foundation.pager.PagerState
|
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.PagerDefaults
|
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.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
@ -109,6 +108,6 @@ internal fun calculateWeeksCount(year: Int, month: Int): Int {
|
|||||||
val firstOfMonth = LocalDate(year, month, 1)
|
val firstOfMonth = LocalDate(year, month, 1)
|
||||||
val offset = firstOfMonth.dayOfWeek.ordinal
|
val offset = firstOfMonth.dayOfWeek.ordinal
|
||||||
val nextMonth = if (month == 12) LocalDate(year + 1, 1, 1) else LocalDate(year, month + 1, 1)
|
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
|
return ((offset + daysInMonth - 1) / 7) + 1
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user