Reformat code style across shared module

Apply consistent formatting: import ordering, line wrapping,
indentation, and XML normalization. No functional changes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-05-15 17:57:18 +08:00
parent d755178b81
commit f618d09458
12 changed files with 97 additions and 77 deletions

View File

@ -1,44 +1,49 @@
<vector <vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:aapt="http://schemas.android.com/aapt"
android:width="450dp" android:width="450dp"
android:height="450dp" android:height="450dp"
android:viewportWidth="64" android:viewportWidth="64"
android:viewportHeight="64"> android:viewportHeight="64">
<path <path
android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z" android:fillColor="#6075f2"
android:fillColor="#6075f2"/> android:pathData="M56.25,18V46L32,60 7.75,46V18L32,4Z" />
<path <path
android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z" android:fillColor="#6b57ff"
android:fillColor="#6b57ff"/> android:pathData="m41.5,26.5v11L32,43V60L56.25,46V18Z" />
<path <path android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z">
android:pathData="m32,43 l-9.5,-5.5v-11L7.75,18V46L32,60Z"> <aapt:attr name="android:fillColor">
<aapt:attr name="android:fillColor"> <gradient
<gradient android:centerX="23.131"
android:centerX="23.131" android:centerY="18.441"
android:centerY="18.441" android:gradientRadius="42.132"
android:gradientRadius="42.132" android:type="radial">
android:type="radial"> <item
<item android:offset="0" android:color="#FF5383EC"/> android:color="#FF5383EC"
<item android:offset="0.867" android:color="#FF7F52FF"/> android:offset="0" />
</gradient> <item
</aapt:attr> android:color="#FF7F52FF"
</path> android:offset="0.867" />
<path </gradient>
android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z"> </aapt:attr>
<aapt:attr name="android:fillColor"> </path>
<gradient <path android:pathData="M22.5,26.5 L32,21 41.5,26.5 56.25,18 32,4 7.75,18Z">
android:startX="44.172" <aapt:attr name="android:fillColor">
android:startY="4.377" <gradient
android:endX="17.973" android:endX="17.973"
android:endY="34.035" android:endY="34.035"
android:type="linear"> android:startX="44.172"
<item android:offset="0" android:color="#FF33C3FF"/> android:startY="4.377"
<item android:offset="0.878" android:color="#FF5383EC"/> android:type="linear">
</gradient> <item
</aapt:attr> android:color="#FF33C3FF"
</path> android:offset="0" />
<path <item
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z" android:color="#FF5383EC"
android:fillColor="#000000"/> android:offset="0.878" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#000000"
android:pathData="m32,21 l9.526,5.5v11L32,43 22.474,37.5v-11z" />
</vector> </vector>

View File

@ -15,9 +15,9 @@ import kotlinx.datetime.minus
import kotlinx.datetime.number import kotlinx.datetime.number
import kotlinx.datetime.plus import kotlinx.datetime.plus
import kotlinx.datetime.todayIn import kotlinx.datetime.todayIn
import kotlin.time.Clock
import plus.rua.project.ui.COLLAPSE_THRESHOLD import plus.rua.project.ui.COLLAPSE_THRESHOLD
import plus.rua.project.ui.FLING_VELOCITY_THRESHOLD_DP import plus.rua.project.ui.FLING_VELOCITY_THRESHOLD_DP
import kotlin.time.Clock
/** /**
* 日历日期数据用于网格单元格渲染 * 日历日期数据用于网格单元格渲染
@ -198,7 +198,8 @@ class CalendarViewModel(
val firstOfMonth = LocalDate(year, month, 1) val firstOfMonth = LocalDate(year, month, 1)
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)).day 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

View File

@ -11,7 +11,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip

View File

@ -73,10 +73,12 @@ fun CalendarMonthPage(
null null
} }
Box(modifier = modifier.clipToBounds().then( Box(
if (totalHeightDp != null) Modifier.height(totalHeightDp) modifier = modifier.clipToBounds().then(
else Modifier if (totalHeightDp != null) Modifier.height(totalHeightDp)
)) { else Modifier
)
) {
weeks.forEachIndexed { weekIndex, week -> weeks.forEachIndexed { weekIndex, week ->
val isSelected = hasSelectedWeek && weekIndex == selectedWeekIndex val isSelected = hasSelectedWeek && weekIndex == selectedWeekIndex
val isAbove = hasSelectedWeek && weekIndex < selectedWeekIndex val isAbove = hasSelectedWeek && weekIndex < selectedWeekIndex
@ -135,7 +137,9 @@ fun CalendarMonthPage(
) )
.padding(vertical = ROW_PADDING_DP.dp) .padding(vertical = ROW_PADDING_DP.dp)
.then( .then(
if (isAbove || isBelow) Modifier.graphicsLayer { alpha = 1f - collapseProgress } if (isAbove || isBelow) Modifier.graphicsLayer {
alpha = 1f - collapseProgress
}
else Modifier else Modifier
) )
) { ) {

View File

@ -27,9 +27,9 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.number import kotlinx.datetime.number
import kotlinx.datetime.plus import kotlinx.datetime.plus
import kotlinx.datetime.todayIn import kotlinx.datetime.todayIn
import plus.rua.project.CalendarViewModel
import kotlin.math.abs import kotlin.math.abs
import kotlin.time.Clock import kotlin.time.Clock
import plus.rua.project.CalendarViewModel
/** /**
* 日历主界面包含月/周视图切换和折叠动画 * 日历主界面包含月/周视图切换和折叠动画
@ -47,6 +47,7 @@ fun CalendarMonthView(
val viewModel = remember { CalendarViewModel(coroutineScope) } val viewModel = remember { CalendarViewModel(coroutineScope) }
val today = remember { Clock.System.todayIn(TimeZone.currentSystemDefault()) } val today = remember { Clock.System.todayIn(TimeZone.currentSystemDefault()) }
val currentYear by remember { derivedStateOf { viewModel.selectedDate.year } } val currentYear by remember { derivedStateOf { viewModel.selectedDate.year } }
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
val currentMonth by remember { derivedStateOf { viewModel.selectedDate.month.number } } val currentMonth by remember { derivedStateOf { viewModel.selectedDate.month.number } }
val density = LocalDensity.current val density = LocalDensity.current
@ -62,7 +63,13 @@ fun CalendarMonthView(
val collapseProgress = viewModel.collapseProgress val collapseProgress = viewModel.collapseProgress
val headerHeightPx = monthHeaderHeightPx + weekdayHeaderHeightPx val headerHeightPx = monthHeaderHeightPx + weekdayHeaderHeightPx
val rowPaddingPx = with(density) { ROW_PADDING_DP.dp.toPx() }.toInt() val rowPaddingPx = with(density) { ROW_PADDING_DP.dp.toPx() }.toInt()
val cardGapPx = with(density) { lerp(CARD_GAP_EXPANDED_DP.toFloat(), CARD_GAP_COLLAPSED_DP.toFloat(), collapseProgress).dp.toPx() }.toInt() val cardGapPx = with(density) {
lerp(
CARD_GAP_EXPANDED_DP.toFloat(),
CARD_GAP_COLLAPSED_DP.toFloat(),
collapseProgress
).dp.toPx()
}.toInt()
// 翻页时在相邻月份行数之间插值,使 BottomCard 高度平滑过渡 // 翻页时在相邻月份行数之间插值,使 BottomCard 高度平滑过渡
// abs(fraction) > 阈值时启用插值,避免静止时的浮点抖动 // abs(fraction) > 阈值时启用插值,避免静止时的浮点抖动
@ -85,7 +92,8 @@ fun CalendarMonthView(
// 加上 Row 的 vertical padding (6dp × 2) // 加上 Row 的 vertical padding (6dp × 2)
// 用于 rowHeightPx 尚未测量时的 fallback避免首次布局高度为 0 // 用于 rowHeightPx 尚未测量时的 fallback避免首次布局高度为 0
val estimatedRowHeightPx = if (screenWidthPx > 0) { val estimatedRowHeightPx = if (screenWidthPx > 0) {
val cellWidth = (screenWidthPx - with(density) { (HORIZONTAL_PADDING_DP * 2).dp.toPx() }) / 7 val cellWidth =
(screenWidthPx - with(density) { (HORIZONTAL_PADDING_DP * 2).dp.toPx() }) / 7
val rowPadding = with(density) { (ROW_PADDING_DP * 2).dp.toPx() } val rowPadding = with(density) { (ROW_PADDING_DP * 2).dp.toPx() }
(cellWidth + rowPadding).toInt() (cellWidth + rowPadding).toInt()
} else 0 } else 0
@ -110,7 +118,8 @@ fun CalendarMonthView(
// BottomCard 高度 = 屏幕剩余空间(屏幕高度 - 日历区域高度) // BottomCard 高度 = 屏幕剩余空间(屏幕高度 - 日历区域高度)
val calendarAreaHeightPx = headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx val calendarAreaHeightPx = headerHeightPx + gridHeightPx + rowPaddingPx + cardGapPx
val cardHeightPx = if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0 val cardHeightPx =
if (screenHeightPx > 0 && calendarAreaHeightPx > 0) screenHeightPx - calendarAreaHeightPx else 0
// 行高已知时约束 pager 高度防止内容溢出;否则让 pager 自由扩展以触发首次行高测量 // 行高已知时约束 pager 高度防止内容溢出;否则让 pager 自由扩展以触发首次行高测量
val pagerModifier = if (rowHeightPx > 0 && gridHeightPx > 0) { val pagerModifier = if (rowHeightPx > 0 && gridHeightPx > 0) {
@ -140,9 +149,10 @@ fun CalendarMonthView(
} }
) )
WeekdayHeader( WeekdayHeader(
modifier = Modifier.fillMaxWidth().padding(bottom = ROW_PADDING_DP.dp).onSizeChanged { size -> modifier = Modifier.fillMaxWidth().padding(bottom = ROW_PADDING_DP.dp)
weekdayHeaderHeightPx = size.height .onSizeChanged { size ->
} weekdayHeaderHeightPx = size.height
}
) )
// 完全折叠且无动画时切换到 WeekPager单行高效渲染 // 完全折叠且无动画时切换到 WeekPager单行高效渲染
// 否则使用 CalendarPager含折叠动画和下拉恢复过程 // 否则使用 CalendarPager含折叠动画和下拉恢复过程
@ -168,7 +178,7 @@ fun CalendarMonthView(
// 优先选中当月内的今天否则选中该月1号 // 优先选中当月内的今天否则选中该月1号
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
val date = if (year == today.year && today.month.number == month) today val date = if (year == today.year && today.month.number == month) today
else LocalDate(year, month, 1) else LocalDate(year, month, 1)
viewModel.selectDate(date) viewModel.selectDate(date)
}, },
collapseProgress = viewModel.collapseProgress, collapseProgress = viewModel.collapseProgress,
@ -184,14 +194,14 @@ fun CalendarMonthView(
} }
// 拖拽范围 = 折叠时日历实际高度变化量 (weeks-1)×rowHeight使手指移动与视觉变化 1:1 对应 // 拖拽范围 = 折叠时日历实际高度变化量 (weeks-1)×rowHeight使手指移动与视觉变化 1:1 对应
val dragRangeMinPx = with(density) { DRAG_RANGE_MIN_DP.dp.toPx() } val dragRangeMinPx = with(density) { DRAG_RANGE_MIN_DP.dp.toPx() }
val dragRangePx = if (effectiveRowHeightPx > 0) { val dragRangePx = if (effectiveRowHeightPx > 0) {
maxOf((effectiveWeeks - 1) * effectiveRowHeightPx.toFloat(), dragRangeMinPx) maxOf((effectiveWeeks - 1) * effectiveRowHeightPx.toFloat(), dragRangeMinPx)
} else { } else {
dragRangeMinPx dragRangeMinPx
} }
if (cardHeightPx > 0) { if (cardHeightPx > 0) {
BottomCard( BottomCard(
viewModel = viewModel, viewModel = viewModel,
dragRangePx = dragRangePx, dragRangePx = dragRangePx,

View File

@ -47,6 +47,7 @@ fun CalendarPager(
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
val initialYear = remember { today.year } val initialYear = remember { today.year }
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
val initialMonth = remember { today.month.number } val initialMonth = remember { today.month.number }
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
@ -74,13 +75,15 @@ fun CalendarPager(
selectedDate = selectedDate, selectedDate = selectedDate,
today = today, today = today,
onDateClick = { date -> onDateClick = { date ->
onDateClick(date) onDateClick(date)
// 点击跨月日期时,滚动到该月对应的页 // 点击跨月日期时,滚动到该月对应的页
val clickedYear = date.year val clickedYear = date.year
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
val clickedMonth = date.month.number val clickedMonth = date.month.number
if (clickedYear != year || clickedMonth != month) { if (clickedYear != year || clickedMonth != month) {
val targetPage = yearMonthToPage(clickedYear, clickedMonth, initialYear, initialMonth) val targetPage =
yearMonthToPage(clickedYear, clickedMonth, initialYear, initialMonth)
if (targetPage != pagerState.currentPage) { if (targetPage != pagerState.currentPage) {
coroutineScope.launch { coroutineScope.launch {
pagerState.animateScrollToPage(targetPage) pagerState.animateScrollToPage(targetPage)

View File

@ -60,6 +60,7 @@ fun calculateWeeksCount(year: Int, month: Int): Int {
*/ */
fun calculateWeeksCountForPage(page: Int, today: LocalDate): Int { fun calculateWeeksCountForPage(page: Int, today: LocalDate): Int {
val initialYear = today.year val initialYear = today.year
@Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口 @Suppress("DEPRECATION") // monthNumber 无替代 APIkotlinx-datetime 尚未提供新接口
val initialMonth = today.month.number val initialMonth = today.month.number
val offset = page - START_PAGE val offset = page - START_PAGE

View File

@ -1,12 +1,12 @@
package plus.rua.project.ui package plus.rua.project.ui
import androidx.compose.animation.AnimatedContent import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically import androidx.compose.animation.slideOutVertically
import androidx.compose.animation.togetherWith import androidx.compose.animation.togetherWith
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
@ -45,10 +45,10 @@ fun MonthHeader(
transitionSpec = { transitionSpec = {
if (targetState.second > initialState.second) { if (targetState.second > initialState.second) {
slideInVertically(tween(250)) { -it } + fadeIn(tween(250)) togetherWith slideInVertically(tween(250)) { -it } + fadeIn(tween(250)) togetherWith
slideOutVertically(tween(250)) { it } + fadeOut(tween(250)) slideOutVertically(tween(250)) { it } + fadeOut(tween(250))
} else { } else {
slideInVertically(tween(250)) { it } + fadeIn(tween(250)) togetherWith slideInVertically(tween(250)) { it } + fadeIn(tween(250)) togetherWith
slideOutVertically(tween(250)) { -it } + fadeOut(tween(250)) slideOutVertically(tween(250)) { -it } + fadeOut(tween(250))
} }
} }
) { (y, m) -> ) { (y, m) ->
@ -63,10 +63,10 @@ fun MonthHeader(
transitionSpec = { transitionSpec = {
if (targetState > initialState) { if (targetState > initialState) {
slideInVertically(tween(250)) { -it } + fadeIn(tween(250)) togetherWith slideInVertically(tween(250)) { -it } + fadeIn(tween(250)) togetherWith
slideOutVertically(tween(250)) { it } + fadeOut(tween(250)) slideOutVertically(tween(250)) { it } + fadeOut(tween(250))
} else { } else {
slideInVertically(tween(250)) { it } + fadeIn(tween(250)) togetherWith slideInVertically(tween(250)) { it } + fadeIn(tween(250)) togetherWith
slideOutVertically(tween(250)) { -it } + fadeOut(tween(250)) slideOutVertically(tween(250)) { -it } + fadeOut(tween(250))
} }
} }
) { week -> ) { week ->

View File

@ -13,11 +13,11 @@ import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import kotlin.math.abs
import kotlinx.coroutines.flow.drop import kotlinx.coroutines.flow.drop
import kotlinx.datetime.DatePeriod import kotlinx.datetime.DatePeriod
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus import kotlinx.datetime.plus
import kotlin.math.abs
/** /**
* 周视图分页器折叠状态下显示选中日期所在周支持左右滑动切换周 * 周视图分页器折叠状态下显示选中日期所在周支持左右滑动切换周

View File

@ -5,7 +5,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.datetime.Clock import kotlinx.datetime.Clock
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import kotlinx.datetime.TimeZone
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFalse import kotlin.test.assertFalse

View File

@ -1,9 +1,6 @@
package plus.rua.project.ui package plus.rua.project.ui
import kotlinx.datetime.DatePeriod
import kotlinx.datetime.LocalDate import kotlinx.datetime.LocalDate
import kotlinx.datetime.minus
import kotlinx.datetime.plus
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals

View File

@ -2,8 +2,9 @@ package plus.rua.project
import platform.UIKit.UIDevice import platform.UIKit.UIDevice
class IOSPlatform: Platform { class IOSPlatform : Platform {
override val name: String = UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion override val name: String =
UIDevice.currentDevice.systemName() + " " + UIDevice.currentDevice.systemVersion
} }
actual fun getPlatform(): Platform = IOSPlatform() actual fun getPlatform(): Platform = IOSPlatform()