Fix lint warnings: remove unused variable, replace monthNumber, use range check
- Remove unused currentWeeksCount variable and onWeeksChanged callback
- Replace deprecated monthNumber with month.number (requires explicit import)
- Remove all @Suppress("DEPRECATION") annotations for monthNumber
- Convert double comparison to range check (today in weekMonday..weekSunday)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
b794601134
commit
7e972bb4fb
@ -12,6 +12,7 @@ import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.daysUntil
|
||||
import kotlinx.datetime.minus
|
||||
import kotlinx.datetime.number
|
||||
import kotlinx.datetime.plus
|
||||
import kotlinx.datetime.todayIn
|
||||
import kotlin.time.Clock
|
||||
@ -42,8 +43,7 @@ class CalendarViewModel(private val coroutineScope: CoroutineScope) {
|
||||
val collapseProgress: Float get() = _collapseAnimatable.value
|
||||
|
||||
val currentYear: Int get() = selectedDate.year
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
val currentMonth: Int get() = selectedDate.monthNumber
|
||||
val currentMonth: Int get() = selectedDate.month.number
|
||||
|
||||
fun selectDate(date: LocalDate) {
|
||||
selectedDate = date
|
||||
@ -132,7 +132,6 @@ class CalendarViewModel(private val coroutineScope: CoroutineScope) {
|
||||
return diff / 7 + 1
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
fun getMonthDays(year: Int, month: Int): List<CalendarDay> {
|
||||
val firstOfMonth = LocalDate(year, month, 1)
|
||||
val dayOfWeekOffset = firstOfMonth.dayOfWeek.ordinal
|
||||
@ -146,7 +145,7 @@ class CalendarViewModel(private val coroutineScope: CoroutineScope) {
|
||||
val date = startDate.plus(DatePeriod(days = i))
|
||||
CalendarDay(
|
||||
date = date,
|
||||
isCurrentMonth = date.monthNumber == month && date.year == year,
|
||||
isCurrentMonth = date.month.number == month && date.year == year,
|
||||
isToday = date == today,
|
||||
isSelected = date == selectedDate
|
||||
)
|
||||
|
||||
@ -17,6 +17,7 @@ import androidx.compose.ui.zIndex
|
||||
import kotlinx.datetime.DatePeriod
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.minus
|
||||
import kotlinx.datetime.number
|
||||
import kotlinx.datetime.plus
|
||||
|
||||
/**
|
||||
@ -141,7 +142,6 @@ private data class DayData(
|
||||
val isCurrentMonth: Boolean
|
||||
)
|
||||
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
private fun generateMonthDays(year: Int, month: Int): List<DayData> {
|
||||
val firstOfMonth = LocalDate(year, month, 1)
|
||||
val offset = firstOfMonth.dayOfWeek.ordinal
|
||||
@ -155,7 +155,7 @@ private fun generateMonthDays(year: Int, month: Int): List<DayData> {
|
||||
val date = startDate.plus(DatePeriod(days = i))
|
||||
DayData(
|
||||
date = date,
|
||||
isCurrentMonth = date.monthNumber == month && date.year == year
|
||||
isCurrentMonth = date.month.number == month && date.year == year
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import androidx.compose.ui.unit.dp
|
||||
import kotlinx.datetime.DatePeriod
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.TimeZone
|
||||
import kotlinx.datetime.number
|
||||
import kotlinx.datetime.plus
|
||||
import kotlinx.datetime.todayIn
|
||||
import kotlin.math.abs
|
||||
@ -56,8 +57,6 @@ fun CalendarMonthView(
|
||||
var monthHeaderHeightPx by remember { mutableIntStateOf(0) }
|
||||
var weekdayHeaderHeightPx by remember { mutableIntStateOf(0) }
|
||||
var rowHeightPx by remember { mutableIntStateOf(0) }
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
var currentWeeksCount by remember { mutableIntStateOf(calculateWeeksCount(today.year, today.monthNumber)) }
|
||||
var screenWidthPx by remember { mutableIntStateOf(0) }
|
||||
var screenHeightPx by remember { mutableIntStateOf(0) }
|
||||
|
||||
@ -153,11 +152,10 @@ fun CalendarMonthView(
|
||||
onDateClick = { date -> viewModel.selectDate(date) },
|
||||
onWeekChanged = { weekMonday ->
|
||||
val weekSunday = weekMonday.plus(DatePeriod(days = 6))
|
||||
val date = if (today >= weekMonday && today <= weekSunday) today else weekMonday
|
||||
val date = if (today in weekMonday..weekSunday) today else weekMonday
|
||||
viewModel.selectDate(date)
|
||||
currentYear = date.year
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
currentMonth = date.monthNumber
|
||||
currentMonth = date.month.number
|
||||
}
|
||||
)
|
||||
} else {
|
||||
@ -166,7 +164,7 @@ fun CalendarMonthView(
|
||||
today = today,
|
||||
onDateClick = { date -> viewModel.selectDate(date) },
|
||||
onMonthChanged = { year, month ->
|
||||
val date = if (year == today.year && today.monthNumber == month) today
|
||||
val date = if (year == today.year && today.month.number == month) today
|
||||
else LocalDate(year, month, 1)
|
||||
viewModel.selectDate(date)
|
||||
currentYear = year
|
||||
@ -175,9 +173,6 @@ fun CalendarMonthView(
|
||||
collapseProgress = viewModel.collapseProgress,
|
||||
rowHeightPx = rowHeightPx,
|
||||
effectiveWeeks = effectiveWeeks,
|
||||
onWeeksChanged = { weeks ->
|
||||
currentWeeksCount = weeks
|
||||
},
|
||||
onRowHeightMeasured = { h ->
|
||||
if (h > 0 && rowHeightPx == 0) rowHeightPx = h
|
||||
},
|
||||
@ -201,10 +196,9 @@ fun CalendarMonthView(
|
||||
|
||||
private fun lerp(start: Float, end: Float, fraction: Float): Float = start + (end - start) * fraction
|
||||
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
private fun calculateWeeksCountForPage(page: Int, today: LocalDate): Int {
|
||||
val initialYear = today.year
|
||||
val initialMonth = today.monthNumber
|
||||
val initialMonth = today.month.number
|
||||
val offset = page - START_PAGE
|
||||
val totalMonths = initialYear * 12 + (initialMonth - 1) + offset
|
||||
val year = totalMonths / 12
|
||||
|
||||
@ -15,6 +15,7 @@ import kotlinx.coroutines.launch
|
||||
import kotlinx.datetime.DatePeriod
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.minus
|
||||
import kotlinx.datetime.number
|
||||
|
||||
/** 无限分页中心页,用于 HorizontalPager 的起始位置 */
|
||||
private const val START_PAGE = Int.MAX_VALUE / 2
|
||||
@ -39,7 +40,6 @@ fun CalendarPager(
|
||||
collapseProgress: Float,
|
||||
rowHeightPx: Int,
|
||||
effectiveWeeks: Float,
|
||||
onWeeksChanged: ((Int) -> Unit)? = null,
|
||||
onRowHeightMeasured: ((Int) -> Unit)? = null,
|
||||
pagerState: PagerState,
|
||||
modifier: Modifier = Modifier
|
||||
@ -51,7 +51,6 @@ fun CalendarPager(
|
||||
LaunchedEffect(pagerState) {
|
||||
snapshotFlow { pagerState.settledPage }.drop(1).collect { page ->
|
||||
val yearMonth = pageToYearMonth(page, initialYearMonth)
|
||||
onWeeksChanged?.invoke(calculateWeeksCount(yearMonth.first, yearMonth.second))
|
||||
onMonthChanged(yearMonth.first, yearMonth.second)
|
||||
}
|
||||
}
|
||||
@ -89,8 +88,7 @@ fun CalendarPager(
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION") // monthNumber 无替代 API,kotlinx-datetime 尚未提供新接口
|
||||
private fun LocalDate.toYearMonth(): Pair<Int, Int> = Pair(year, monthNumber)
|
||||
private fun LocalDate.toYearMonth(): Pair<Int, Int> = Pair(year, month.number)
|
||||
|
||||
// 页码→年月:偏移量 + 初始月份的绝对月数,再拆分回年月
|
||||
private fun pageToYearMonth(page: Int, initial: Pair<Int, Int>): Pair<Int, Int> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user