Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import com.androidmakers.ui.model.UISession
@Composable
fun AgendaColumn(
sessionsPerStartTime: Map<String, List<UISession>>,
initialFirstVisibleItemIndex: Int = 0,
onSessionClick: (UISession) -> Unit,
onSessionBookmark: (UISession, Boolean) -> Unit,
onApplyForAppClinicClick: () -> Unit,
) {
val listState = rememberLazyListState()
val listState = rememberLazyListState(initialFirstVisibleItemIndex = initialFirstVisibleItemIndex)

LazyColumn(
state = listState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import androidx.compose.ui.Modifier
import com.androidmakers.ui.common.EmptyLayout
import com.androidmakers.ui.common.SessionFilter
import com.androidmakers.ui.model.UISession
import fr.androidmakers.domain.utils.eventTimeZone
import fr.androidmakers.domain.utils.formatShortTime
import kotlin.time.Clock
import kotlinx.coroutines.launch
import kotlinx.datetime.todayIn

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -81,11 +84,18 @@ fun AgendaPager(
onRefresh = onRefresh,
state = pullRefreshState
) {
val isToday = remember(page) {
days[page].date == Clock.System.todayIn(eventTimeZone)
}
Comment on lines +87 to +89
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isToday is memoized only by page, but it depends on days[page].date and on Clock.System.todayIn(eventTimeZone). With the current remember(page) it can become stale (e.g., if days updates while staying on the same page index, or if the date changes while the screen stays in the back stack). Consider computing isToday directly from day.date (no remember), or at least keying remember on day.date (and avoid indexing back into days since day is already available).

Suggested change
val isToday = remember(page) {
days[page].date == Clock.System.todayIn(eventTimeZone)
}
val isToday = day.date == Clock.System.todayIn(eventTimeZone)

Copilot uses AI. Check for mistakes.
val initialScrollIndex = remember(sessionsPerStartTime, isToday) {
if (isToday) sessionsPerStartTime.currentTimeScrollIndex() else 0
}
if (sessionsPerStartTime.isEmpty()) {
EmptyLayout()
} else {
AgendaColumn(
sessionsPerStartTime = sessionsPerStartTime,
initialFirstVisibleItemIndex = initialScrollIndex,
onSessionClick = onSessionClick,
onApplyForAppClinicClick = onApplyForAppClinicClick,
onSessionBookmark = onSessionBookmark
Expand Down Expand Up @@ -117,3 +127,28 @@ private fun List<UISession>.filter(
}
}
}

/**
* Computes the lazy list item index of the sticky header for the last time slot
* that has already started (i.e., whose start time <= now). Returns 0 if all
* slots are in the future. The lazy list structure is:
* index 0 : sticky header for slot 0
* index 1..n : sessions of slot 0
* index n+1 : sticky header for slot 1
* ...
*/
private fun Map<String, List<UISession>>.currentTimeScrollIndex(): Int {
val now = Clock.System.now()
var itemIndex = 0
var targetIndex = 0

for ((_, sessions) in this) {
val slotStart = sessions.firstOrNull()?.startDate
if (slotStart != null && slotStart <= now) {
targetIndex = itemIndex
}
itemIndex += 1 + sessions.size // 1 for sticky header + N for sessions
}

return targetIndex
}