feat: support swipe to switch week#17
Open
Kaltsit-cell wants to merge 1 commit intoOpenAHU:masterfrom
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces horizontal paging to the schedule screen so users can swipe between weeks, and wires the week selector to control the pager.
Changes:
- Added
HorizontalPager/rememberPagerStateto enable week-to-week swiping. - Updated week selector taps and “locate current week” action to scroll the pager.
- Added effects to synchronize pager scrolling with the week selector list position.
Comments suppressed due to low confidence (1)
app/src/main/java/com/ahu/ahutong/ui/screen/main/Schedule.kt:257
- Inside
HorizontalPager { … }, the page index parameter isn’t used; all pages render based on the single globalcurrentWeek. This means every page’s content is identical and changes globally whencurrentWeekchanges, which defeats paging and can produce confusing swipe behavior (especially with prefetch/offscreen pages). Derive aweekForPage = page + 1and use that forweekDates, course filtering, and highlighting, instead ofcurrentWeekinside the pager content.
HorizontalPager(
state = pagerState,
modifier = Modifier.fillMaxWidth()
) {
Box(
modifier = with(CourseCardSpec) {
Modifier
.fillMaxWidth()
.height(mainRowHeight + (cellHeight + cellSpacing) * 13 + 24.dp)
.clip(SmoothRoundedCornerShape(32.dp))
.background(99.n1 withNight 20.n1)
.padding(top = 8.dp)
.padding(cellSpacing)
}
) {
// TODO: current time indicator
// weekday tags
val weekDates by remember(currentWeek, scheduleConfig?.startTime) {
mutableStateOf(
List(7) { index ->
Calendar.getInstance().apply {
time = scheduleConfig?.startTime
?: SimpleDateFormat("MM-dd", Locale.CHINA).parse("09-01")
add(Calendar.DATE, ((currentWeek - 1) * 7) + index)
}
}
)
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
80
to
+106
| var currentWeek by rememberSaveable { mutableStateOf(scheduleConfig?.week ?: 1) } | ||
| val pagerState = rememberPagerState( | ||
| initialPage = (currentWeek - 1).coerceAtLeast(0), | ||
| pageCount = { 20 } | ||
| ) | ||
| val state = rememberLazyListState( | ||
| initialFirstVisibleItemIndex = (currentWeek - 3).coerceAtLeast(0) | ||
| ) | ||
| val scheduleResult = scheduleViewModel.schedule.observeAsState().value | ||
| val schedule = scheduleResult?.getOrNull() ?: emptyList() | ||
| val context = LocalContext.current | ||
|
|
||
| LaunchedEffect(pagerState.isScrollInProgress) { | ||
| if (!pagerState.isScrollInProgress) { | ||
| state.animateScrollToItem( | ||
| (currentWeek - 3).coerceAtLeast(0) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| LaunchedEffect(scheduleConfig?.week) { | ||
| scheduleConfig?.week?.let { currentWeek = it } | ||
| } | ||
|
|
||
|
|
||
| LaunchedEffect(pagerState.currentPage) { | ||
| currentWeek = pagerState.currentPage + 1 | ||
| } |
Comment on lines
201
to
+205
| scope.launch { | ||
| state.animateScrollToItem((currentWeek - 3).coerceAtLeast(0)) | ||
| } | ||
| scope.launch { | ||
| pagerState.animateScrollToPage((scheduleConfig?.week ?: 1) - 1) |
| @@ -120,7 +138,6 @@ fun Schedule(scheduleViewModel: ScheduleViewModel = hiltViewModel()) { | |||
| ) { | |||
| Row( | |||
| modifier = Modifier.padding(end = 8.dp), | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.