From 95b8b95a50f353ae0f73c5b3149aace76d5c905e Mon Sep 17 00:00:00 2001 From: merenyimiklos Date: Thu, 19 Nov 2026 23:21:56 +0100 Subject: [PATCH 1/4] feat(timetable, substitutions): add date-based navigation and refactor A/B week filtering * Extract shared `SchoolWeekDaySelector` composable and date utilities for timetable and substitution views. * Add week switcher and day selector to `SubstitutionScreen` to filter substitutions and moved lessons by date. * Implement A/B week determination logic (`LessonWeekFilter`) and add support for manual A/B week toggling in `TimetableScreen`. * Add unit tests in `LessonWeekFilterTest` and `SchoolWeekDaySelectorTest` for week calculation and lesson filtering logic. ``` (cherry picked from commit a5d88bd9609bed3323f76d1828f5025b656acc90) --- .../components/SchoolWeekDaySelector.kt | 140 +++++++++ .../petrik/filcapp/data/LessonWeekFilter.kt | 57 ++++ .../filcapp/screens/SubstitutionScreen.kt | 186 ++++++++--- .../petrik/filcapp/screens/TimetableScreen.kt | 289 +++++------------- .../components/SchoolWeekDaySelectorTest.kt | 50 +++ .../filcapp/data/LessonWeekFilterTest.kt | 46 +++ 6 files changed, 517 insertions(+), 251 deletions(-) create mode 100644 composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt create mode 100644 composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt create mode 100644 composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt create mode 100644 composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt new file mode 100644 index 0000000..e9ca638 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt @@ -0,0 +1,140 @@ +package hu.petrik.filcapp.components + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import hu.petrik.filcapp.settings.tr +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate + +/** Shared date picker for timetable and substitutions. */ +@Composable +fun SchoolWeekDaySelector( + today: LocalDate, + weekOffset: Int, + selectedDayOrder: Int, + onDaySelected: (Int) -> Unit, +) { + val monday = schoolWeekMonday(today, weekOffset) + + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(4.dp), + ) { + (1..5).forEach { dayIndex -> + val date = LocalDate.fromEpochDays(monday.toEpochDays() + dayIndex - 1) + val selected = selectedDayOrder == dayIndex + + Surface( + modifier = + Modifier + .weight(1f) + .heightIn(min = 53.dp) + .clickable { + onDaySelected(dayIndex) + }, + shape = RoundedCornerShape(12.dp), + color = + if (selected) { + MaterialTheme.colorScheme.primary + } else { + MaterialTheme.colorScheme.surface + }, + shadowElevation = if (selected) 3.dp else 0.dp, + ) { + Column( + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center, + modifier = Modifier.padding(vertical = 5.dp), + ) { + Text( + text = schoolShortDayName(dayIndex), + style = MaterialTheme.typography.bodySmall, + color = + if (selected) { + Color.White + } else { + MaterialTheme.colorScheme.onSurface.copy(alpha = 0.75f) + }, + fontWeight = if (selected) FontWeight.Bold else FontWeight.Medium, + ) + + Text( + text = date.day.toString(), + style = MaterialTheme.typography.titleSmall, + color = + if (selected) { + Color.White + } else { + MaterialTheme.colorScheme.onSurface + }, + fontWeight = if (selected) FontWeight.ExtraBold else FontWeight.Bold, + ) + } + } + } + } +} + +internal fun schoolWeekMonday( + date: LocalDate, + weekOffset: Int, +): LocalDate { + val daysSinceMonday = + when (date.dayOfWeek) { + DayOfWeek.MONDAY -> 0 + DayOfWeek.TUESDAY -> 1 + DayOfWeek.WEDNESDAY -> 2 + DayOfWeek.THURSDAY -> 3 + DayOfWeek.FRIDAY -> 4 + DayOfWeek.SATURDAY -> 5 + DayOfWeek.SUNDAY -> 6 + } + + return LocalDate.fromEpochDays( + date.toEpochDays() - daysSinceMonday + weekOffset * 7, + ) +} + +internal fun schoolDefaultDay(day: DayOfWeek): Int = + when (day) { + DayOfWeek.MONDAY -> 1 + DayOfWeek.TUESDAY -> 2 + DayOfWeek.WEDNESDAY -> 3 + DayOfWeek.THURSDAY -> 4 + DayOfWeek.FRIDAY -> 5 + DayOfWeek.SATURDAY, DayOfWeek.SUNDAY -> 1 + } + +private fun schoolShortDayName(dayOrder: Int): String = + when (dayOrder) { + 1 -> tr("Hét", "Mon") + 2 -> tr("Ked", "Tue") + 3 -> tr("Sze", "Wed") + 4 -> tr("Csü", "Thu") + 5 -> tr("Pén", "Fri") + else -> "" + } + +/** Translate a selected school weekday and week offset to the actual date. */ +internal fun schoolDateFor( + today: LocalDate, + weekOffset: Int, + dayOrder: Int, +): LocalDate { + require(dayOrder in 1..5) + return LocalDate.fromEpochDays(schoolWeekMonday(today, weekOffset).toEpochDays() + dayOrder - 1) +} diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt new file mode 100644 index 0000000..b4e5eca --- /dev/null +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt @@ -0,0 +1,57 @@ +package hu.petrik.filcapp.data + +import kotlinx.datetime.LocalDate + +internal enum class LessonWeekType { A, B, ALL } + +internal fun lessonWeekType(definition: WeekDefinitionDto?): LessonWeekType { + if (definition == null) return LessonWeekType.ALL + when (definition.short.trim().uppercase()) { + "A" -> return LessonWeekType.A + "B" -> return LessonWeekType.B + } + val name = definition.name.trim().lowercase().replace('é', 'e') + when (name) { + "het a", "a het", "week a" -> return LessonWeekType.A + "het b", "b het", "week b" -> return LessonWeekType.B + } + return when (definition.weeks.map { it.trim() }.toSet()) { + setOf("10") -> LessonWeekType.A + setOf("01") -> LessonWeekType.B + else -> LessonWeekType.ALL + } +} + +internal fun filterLessonsForSchoolWeek( + lessons: List, + week: LessonWeekType, +): List = + lessons.filter { item -> + val lessonType = lessonWeekType(item.weekDefinition) + week == LessonWeekType.ALL || lessonType == LessonWeekType.ALL || lessonType == week + } + +/** The first school week containing September 1 is A by convention. + * The timetable header allows manually inverting this convention when the + * school's actual A/B ordering is different. */ +internal fun schoolWeekTypeFor( + monday: LocalDate, + reversed: Boolean = false, +): LessonWeekType { + val friday = LocalDate.fromEpochDays(monday.toEpochDays() + 4) + val academicYear = if (friday.monthNumber >= 9) friday.year else friday.year - 1 + val septemberFirst = LocalDate(academicYear, 9, 1) + val daysSinceMonday = when (septemberFirst.dayOfWeek) { + kotlinx.datetime.DayOfWeek.MONDAY -> 0 + kotlinx.datetime.DayOfWeek.TUESDAY -> 1 + kotlinx.datetime.DayOfWeek.WEDNESDAY -> 2 + kotlinx.datetime.DayOfWeek.THURSDAY -> 3 + kotlinx.datetime.DayOfWeek.FRIDAY -> 4 + kotlinx.datetime.DayOfWeek.SATURDAY -> 5 + kotlinx.datetime.DayOfWeek.SUNDAY -> 6 + } + val startMonday = LocalDate.fromEpochDays(septemberFirst.toEpochDays() - daysSinceMonday) + val weekIndex = (monday.toEpochDays() - startMonday.toEpochDays()) / 7 + val parity = weekIndex + (if (reversed) 1 else 0) + return if (parity % 2 == 0) LessonWeekType.A else LessonWeekType.B +} diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt index 47ea0ad..7a5ee86 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt @@ -1,5 +1,6 @@ package hu.petrik.filcapp.screens import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -14,12 +15,15 @@ import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.KeyboardArrowLeft +import androidx.compose.material.icons.filled.KeyboardArrowRight import androidx.compose.material.icons.filled.SwapCalls import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.FilterChip import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -32,14 +36,20 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import cafe.adriel.voyager.navigator.tab.Tab import cafe.adriel.voyager.navigator.tab.TabOptions import hu.petrik.filcapp.auth.AuthState +import hu.petrik.filcapp.components.SchoolWeekDaySelector import hu.petrik.filcapp.components.SearchableSelection import hu.petrik.filcapp.components.TimetableFilterChips +import hu.petrik.filcapp.components.schoolDateFor +import hu.petrik.filcapp.components.schoolDefaultDay +import hu.petrik.filcapp.components.schoolWeekMonday import hu.petrik.filcapp.data.ChronosApi import hu.petrik.filcapp.data.CohortDto import hu.petrik.filcapp.data.MovedLessonItemDto @@ -54,11 +64,11 @@ import hu.petrik.filcapp.settings.tr import hu.petrik.filcapp.widgets.WidgetDestination import hu.petrik.filcapp.widgets.WidgetNavigation import hu.petrik.filcapp.widgets.WidgetSelectionType +import kotlin.time.Clock +import kotlin.time.ExperimentalTime import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.todayIn -import kotlin.time.Clock -import kotlin.time.ExperimentalTime private object SubstitutionSessionCache { var substitutions: List = emptyList() @@ -70,6 +80,7 @@ private object SubstitutionSessionCache { var error: String? = null } +@OptIn(ExperimentalTime::class) @Composable fun SubstitutionScreen() { var substitutions by remember { mutableStateOf(SubstitutionSessionCache.substitutions) } @@ -85,6 +96,17 @@ fun SubstitutionScreen() { var personalizedUserId by remember { mutableStateOf(null) } var appliedWidgetRequest by remember { mutableStateOf(0) } + val today = Clock.System.todayIn(TimeZone.currentSystemDefault()) + var weekOffset by remember { mutableStateOf(0) } + var selectedDayOrder by remember { mutableStateOf(schoolDefaultDay(today.dayOfWeek)) } + val selectedDate = schoolDateFor(today, weekOffset, selectedDayOrder) + val selectedDateKey = selectedDate.toString() + + fun moveWeek(delta: Int) { + weekOffset += delta + selectedDayOrder = if (weekOffset == 0) schoolDefaultDay(today.dayOfWeek) else 1 + } + LaunchedEffect(reloadKey) { if (reloadKey == 0 && SubstitutionSessionCache.loaded) { loading = false @@ -97,8 +119,8 @@ fun SubstitutionScreen() { cohorts = ChronosApi.getCohorts(latest.id).sortedBy { it.name } teachers = ChronosApi.getTeachers().sortedBy { it.displayName } classrooms = ChronosApi.getClassrooms().sortedBy { it.name } - substitutions = ChronosApi.getSubstitutions().filter { isTodayOrFuture(it.substitution.date) } - movedLessons = ChronosApi.getMovedLessons().filter { isTodayOrFuture(it.movedLesson.date) } + substitutions = ChronosApi.getSubstitutions() + movedLessons = ChronosApi.getMovedLessons() SubstitutionSessionCache.cohorts = cohorts SubstitutionSessionCache.teachers = teachers SubstitutionSessionCache.classrooms = classrooms @@ -175,8 +197,12 @@ fun SubstitutionScreen() { TimetableFilter.CLASSROOM -> classrooms.map { it.id to displayName(it) } } - val filteredSubstitutions = filterSubstitutions(substitutions, filter, selectedId, cohorts) - val filteredMovedLessons = filterMovedLessons(movedLessons, filter, selectedId, cohorts) + val filteredSubstitutions = + filterSubstitutions(substitutions, filter, selectedId, cohorts) + .filter { normalizeDate(it.substitution.date) == selectedDateKey } + val filteredMovedLessons = + filterMovedLessons(movedLessons, filter, selectedId, cohorts) + .filter { normalizeDate(it.movedLesson.date) == selectedDateKey } PullToRefreshBox( isRefreshing = loading, @@ -191,7 +217,20 @@ fun SubstitutionScreen() { .padding(horizontal = 12.dp, vertical = 12.dp), verticalArrangement = Arrangement.spacedBy(12.dp), ) { + SubstitutionWeekSwitcher( + today = today, + weekOffset = weekOffset, + onPreviousWeek = { moveWeek(-1) }, + onNextWeek = { moveWeek(1) }, + ) + SchoolWeekDaySelector( + today = today, + weekOffset = weekOffset, + selectedDayOrder = selectedDayOrder, + onDaySelected = { selectedDayOrder = it }, + ) SubstitutionOverviewHeader( + date = selectedDate, changeCount = filteredSubstitutions.size + filteredMovedLessons.size, ) @@ -264,8 +303,8 @@ fun SubstitutionScreen() { Card(modifier = Modifier.fillMaxWidth()) { Text( tr( - "Nincs aktuális vagy közelgő helyettesítés ehhez a szűréshez.", - "No current or upcoming substitutions for this filter.", + "Ezen a napon nincs helyettesítés vagy áthelyezett óra ehhez a szűréshez.", + "No substitutions or moved lessons on this day for this filter.", ), modifier = Modifier.padding(18.dp), color = MaterialTheme.colorScheme.onSurfaceVariant, @@ -273,48 +312,118 @@ fun SubstitutionScreen() { } } - val dates = - ( - filteredSubstitutions.map { normalizeDate(it.substitution.date) } + - filteredMovedLessons.map { normalizeDate(it.movedLesson.date) } - ).distinct() - .sorted() - - dates.forEach { date -> - Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { - Text(formatDate(date), style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.SemiBold) + if (error == null) { + filteredSubstitutions.forEach { substitution -> SubstitutionCard(substitution) } + filteredMovedLessons.forEach { movedLesson -> MovedLessonCard(movedLesson) } + } + } + } +} - filteredSubstitutions - .filter { normalizeDate(it.substitution.date) == date } - .forEach { substitution -> SubstitutionCard(substitution) } +@Composable +private fun SubstitutionWeekSwitcher( + today: LocalDate, + weekOffset: Int, + onPreviousWeek: () -> Unit, + onNextWeek: () -> Unit, +) { + val monday = schoolWeekMonday(today, weekOffset) + val friday = LocalDate.fromEpochDays(monday.toEpochDays() + 4) + val range = + if (monday.year == friday.year) { + "${monday.year}. ${monday.monthNumber}. ${monday.day}. – ${friday.monthNumber}. ${friday.day}." + } else { + "${monday.year}. ${monday.monthNumber}. ${monday.day}. – " + + "${friday.year}. ${friday.monthNumber}. ${friday.day}." + } - filteredMovedLessons - .filter { normalizeDate(it.movedLesson.date) == date } - .forEach { movedLesson -> MovedLessonCard(movedLesson) } - } + Surface( + modifier = Modifier.fillMaxWidth(), + shape = RoundedCornerShape(12.dp), + color = MaterialTheme.colorScheme.surface, + shadowElevation = 1.dp, + ) { + Row( + modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp), + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, + ) { + SubstitutionWeekArrow( + icon = Icons.Default.KeyboardArrowLeft, + contentDescription = tr("Előző hét", "Previous week"), + onClick = onPreviousWeek, + ) + Column( + modifier = Modifier.weight(1f), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(2.dp), + ) { + Text( + text = range, + style = MaterialTheme.typography.titleMedium, + fontWeight = FontWeight.SemiBold, + color = MaterialTheme.colorScheme.onSurface, + textAlign = TextAlign.Center, + ) + Text( + text = tr("Hétfő – péntek", "Monday – Friday"), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) } + SubstitutionWeekArrow( + icon = Icons.Default.KeyboardArrowRight, + contentDescription = tr("Következő hét", "Next week"), + onClick = onNextWeek, + ) } } } -@OptIn(ExperimentalTime::class) @Composable -private fun SubstitutionOverviewHeader(changeCount: Int) { - val today = Clock.System.todayIn(TimeZone.currentSystemDefault()) +private fun SubstitutionWeekArrow( + icon: ImageVector, + contentDescription: String, + onClick: () -> Unit, +) { + Surface( + modifier = Modifier.size(32.dp).clickable(onClick = onClick), + shape = CircleShape, + color = MaterialTheme.colorScheme.surfaceVariant, + ) { + Box(contentAlignment = Alignment.Center) { + Icon( + imageVector = icon, + contentDescription = contentDescription, + modifier = Modifier.size(18.dp), + tint = MaterialTheme.colorScheme.onSurface, + ) + } + } +} + +@Composable +private fun SubstitutionOverviewHeader( + date: LocalDate, + changeCount: Int, +) { Row( modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, + horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.Top, ) { - Column(verticalArrangement = Arrangement.spacedBy(2.dp)) { + Column( + modifier = Modifier.weight(1f), + verticalArrangement = Arrangement.spacedBy(2.dp), + ) { Text( text = tr("HIVATALOS NAPLÓ", "OFFICIAL LOG"), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, ) Text( - text = formatHungarianDate(today), + text = formatHungarianDate(date), style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold, color = MaterialTheme.colorScheme.onBackground, @@ -339,9 +448,9 @@ private fun SubstitutionOverviewHeader(changeCount: Int) { Text( text = if (changeCount == 1) { - tr("1 változás ma", "1 change today") + tr("1 változás", "1 change") } else { - tr("$changeCount változás ma", "$changeCount changes today") + tr("$changeCount változás", "$changeCount changes") }, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary, @@ -749,18 +858,7 @@ private fun formatHungarianDate(date: LocalDate): String { private fun normalizeDate(value: String): String = value.take(10) -private fun formatDate(value: String): String { - val parts = normalizeDate(value).split("-") - return if (parts.size == 3) "${parts[0]}. ${parts[1]}. ${parts[2]}." else value -} -@OptIn(ExperimentalTime::class) -private fun isTodayOrFuture(value: String): Boolean = - runCatching { - val date = LocalDate.parse(normalizeDate(value)) - val today = Clock.System.todayIn(TimeZone.currentSystemDefault()) - date >= today - }.getOrDefault(true) private fun formatTime(value: String): String = value.take(5) diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt index bb7e7d3..a8e518a 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt @@ -46,32 +46,39 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp import cafe.adriel.voyager.navigator.tab.Tab import cafe.adriel.voyager.navigator.tab.TabOptions import hu.petrik.filcapp.auth.AuthState +import hu.petrik.filcapp.components.SchoolWeekDaySelector import hu.petrik.filcapp.components.SearchableSelection import hu.petrik.filcapp.components.TimetableFilterChips +import hu.petrik.filcapp.components.schoolDefaultDay +import hu.petrik.filcapp.components.schoolWeekMonday import hu.petrik.filcapp.data.ChronosApi import hu.petrik.filcapp.data.CohortDto import hu.petrik.filcapp.data.LessonDto +import hu.petrik.filcapp.data.LessonWeekType import hu.petrik.filcapp.data.NamedRefDto import hu.petrik.filcapp.data.TeacherDto import hu.petrik.filcapp.data.TimetableDto import hu.petrik.filcapp.data.TimetableFilter import hu.petrik.filcapp.data.WeekDefinitionDto import hu.petrik.filcapp.data.cohortLabels +import hu.petrik.filcapp.data.filterLessonsForSchoolWeek +import hu.petrik.filcapp.data.lessonWeekType +import hu.petrik.filcapp.data.schoolWeekTypeFor import hu.petrik.filcapp.settings.tr import hu.petrik.filcapp.widgets.WidgetDestination import hu.petrik.filcapp.widgets.WidgetNavigation import hu.petrik.filcapp.widgets.WidgetSelectionType -import kotlinx.datetime.DayOfWeek +import kotlin.time.Clock +import kotlin.time.ExperimentalTime import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.todayIn -import kotlin.time.Clock -import kotlin.time.ExperimentalTime private object TimetableSessionCache { var timetables: List = emptyList() @@ -108,11 +115,11 @@ fun TimetableScreen() { var filter by remember { mutableStateOf(TimetableFilter.COHORT) } var selectedId by remember { mutableStateOf(null) } var lessons by remember { mutableStateOf>(emptyList()) } - var selectedWeekId by remember { mutableStateOf(null) } + var reverseABWeeks by remember { mutableStateOf(false) } val today = Clock.System.todayIn(TimeZone.currentSystemDefault()) var weekOffset by remember { mutableStateOf(0) } - var selectedDayOrder by remember { mutableStateOf(defaultSchoolDay(today.dayOfWeek)) } + var selectedDayOrder by remember { mutableStateOf(schoolDefaultDay(today.dayOfWeek)) } var showTimetableSelector by remember { mutableStateOf(false) } var loadingReferenceData by remember { mutableStateOf(!TimetableSessionCache.referenceLoaded) } @@ -318,24 +325,18 @@ fun TimetableScreen() { .distinctBy { it.id } .sortedBy { it.name } - LaunchedEffect(weekDefinitions) { - if (weekDefinitions.isEmpty()) { - selectedWeekId = null - } else if (selectedWeekId !in weekDefinitions.map { it.id }) { - selectedWeekId = weekDefinitions.first().id - } - } - + // Do not treat the "both weeks" definition as a third week. + val hasABWeeks = weekDefinitions.any { lessonWeekType(it) != LessonWeekType.ALL } + val selectedWeekType = schoolWeekTypeFor(schoolWeekMonday(today, weekOffset), reverseABWeeks) val selectedWeek = - weekDefinitions.firstOrNull { it.id == selectedWeekId } - ?: weekDefinitions.firstOrNull() - - val visibleLessons = - if (selectedWeek == null) { - lessons + if (hasABWeeks) { + weekDefinitions.firstOrNull { lessonWeekType(it) == selectedWeekType } + ?: WeekDefinitionDto(short = selectedWeekType.name) } else { - lessons.filter { it.weekDefinition?.id == selectedWeek.id } + null } + val visibleLessons = + if (hasABWeeks) filterLessonsForSchoolWeek(lessons, selectedWeekType) else lessons val selectedDayLessons = visibleLessons @@ -391,27 +392,7 @@ fun TimetableScreen() { fun moveWeek(delta: Int) { weekOffset += delta - - if (weekDefinitions.size > 1) { - val currentIndex = - weekDefinitions - .indexOfFirst { it.id == selectedWeekId } - .takeIf { it >= 0 } - ?: 0 - - val nextIndex = - (currentIndex + delta) - .mod(weekDefinitions.size) - - selectedWeekId = weekDefinitions[nextIndex].id - } - - selectedDayOrder = - if (weekOffset == 0) { - defaultSchoolDay(today.dayOfWeek) - } else { - 1 - } + selectedDayOrder = if (weekOffset == 0) schoolDefaultDay(today.dayOfWeek) else 1 } PullToRefreshBox( @@ -431,11 +412,13 @@ fun TimetableScreen() { today = today, weekOffset = weekOffset, selectedWeek = selectedWeek, + canToggleWeek = hasABWeeks, + onToggleWeek = { reverseABWeeks = !reverseABWeeks }, onPreviousWeek = { moveWeek(-1) }, onNextWeek = { moveWeek(1) }, ) - TimetableDaySelector( + SchoolWeekDaySelector( today = today, weekOffset = weekOffset, selectedDayOrder = selectedDayOrder, @@ -515,10 +498,12 @@ private fun TimetableWeekSwitcher( today: LocalDate, weekOffset: Int, selectedWeek: WeekDefinitionDto?, + canToggleWeek: Boolean, + onToggleWeek: () -> Unit, onPreviousWeek: () -> Unit, onNextWeek: () -> Unit, ) { - val monday = mondayOfWeek(today, weekOffset) + val monday = schoolWeekMonday(today, weekOffset) val friday = LocalDate.fromEpochDays(monday.toEpochDays() + 4) Surface( @@ -527,72 +512,75 @@ private fun TimetableWeekSwitcher( color = MaterialTheme.colorScheme.surface, shadowElevation = 1.dp, ) { - Row( - modifier = - Modifier - .fillMaxWidth() - .padding(horizontal = 12.dp, vertical = 8.dp), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, + Column( + modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp), + verticalArrangement = Arrangement.spacedBy(5.dp), ) { Row( - horizontalArrangement = Arrangement.spacedBy(4.dp), + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.spacedBy(6.dp), verticalAlignment = Alignment.CenterVertically, ) { WeekArrowButton( icon = Icons.Default.KeyboardArrowLeft, onClick = onPreviousWeek, ) - Column( - verticalArrangement = Arrangement.spacedBy(1.dp), + modifier = Modifier.weight(1f), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(2.dp), ) { Text( text = formatWeekRange(monday, friday), style = MaterialTheme.typography.titleMedium, color = MaterialTheme.colorScheme.onSurface, fontWeight = FontWeight.SemiBold, + textAlign = TextAlign.Center, ) - Text( - text = - tr( - "${approximateTeachingWeek(monday)}. tanítási hét", - "School week ${approximateTeachingWeek(monday)}", - ), + text = tr( + "${approximateTeachingWeek(monday)}. tanítási hét", + "School week ${approximateTeachingWeek(monday)}", + ), style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurface, + color = MaterialTheme.colorScheme.onSurfaceVariant, ) } - WeekArrowButton( icon = Icons.Default.KeyboardArrowRight, onClick = onNextWeek, ) } - - Surface( - shape = RoundedCornerShape(999.dp), - color = MaterialTheme.colorScheme.primary.copy(alpha = 0.12f), - ) { - Row( - modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp), - horizontalArrangement = Arrangement.spacedBy(6.dp), - verticalAlignment = Alignment.CenterVertically, + Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { + Surface( + modifier = Modifier.clickable(enabled = canToggleWeek, onClick = onToggleWeek), + shape = RoundedCornerShape(999.dp), + color = MaterialTheme.colorScheme.primary.copy(alpha = 0.12f), ) { - Box( - modifier = - Modifier - .size(6.dp) + Row( + modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp), + horizontalArrangement = Arrangement.spacedBy(6.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Box( + modifier = Modifier.size(6.dp) .background(MaterialTheme.colorScheme.primary, CircleShape), - ) - - Text( - text = weekBadgeLabel(selectedWeek), - style = MaterialTheme.typography.labelMedium, - color = MaterialTheme.colorScheme.primary, - fontWeight = FontWeight.Bold, - ) + ) + Text( + text = weekBadgeLabel(selectedWeek), + style = MaterialTheme.typography.labelMedium, + color = MaterialTheme.colorScheme.primary, + fontWeight = FontWeight.Bold, + ) + if (canToggleWeek) { + Icon( + imageVector = Icons.Default.KeyboardArrowDown, + contentDescription = tr("A/B hét felcserélése", "Swap A/B week"), + modifier = Modifier.size(16.dp), + tint = MaterialTheme.colorScheme.primary, + ) + } + } } } } @@ -623,73 +611,6 @@ private fun WeekArrowButton( } } -@Composable -private fun TimetableDaySelector( - today: LocalDate, - weekOffset: Int, - selectedDayOrder: Int, - onDaySelected: (Int) -> Unit, -) { - val monday = mondayOfWeek(today, weekOffset) - - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.spacedBy(4.dp), - ) { - (1..5).forEach { dayIndex -> - val date = LocalDate.fromEpochDays(monday.toEpochDays() + dayIndex - 1) - val selected = selectedDayOrder == dayIndex - - Surface( - modifier = - Modifier - .weight(1f) - .height(53.dp) - .clickable { - onDaySelected(dayIndex) - }, - shape = RoundedCornerShape(12.dp), - color = - if (selected) { - MaterialTheme.colorScheme.primary - } else { - MaterialTheme.colorScheme.surface - }, - shadowElevation = if (selected) 3.dp else 0.dp, - ) { - Column( - horizontalAlignment = Alignment.CenterHorizontally, - verticalArrangement = Arrangement.Center, - ) { - Text( - text = shortDayName(dayIndex), - style = MaterialTheme.typography.bodySmall, - color = - if (selected) { - Color.White - } else { - MaterialTheme.colorScheme.onSurface.copy(alpha = 0.75f) - }, - fontWeight = if (selected) FontWeight.Bold else FontWeight.Medium, - ) - - Text( - text = date.day.toString(), - style = MaterialTheme.typography.titleSmall, - color = - if (selected) { - Color.White - } else { - MaterialTheme.colorScheme.onSurface - }, - fontWeight = if (selected) FontWeight.ExtraBold else FontWeight.Bold, - ) - } - } - } - } -} - @Composable private fun FigmaLessonCard( lesson: LessonDto, @@ -1101,57 +1022,18 @@ private fun ErrorBlock( } } -private fun mondayOfWeek( - date: LocalDate, - weekOffset: Int, -): LocalDate { - val daysSinceMonday = - when (date.dayOfWeek) { - DayOfWeek.MONDAY -> 0 - DayOfWeek.TUESDAY -> 1 - DayOfWeek.WEDNESDAY -> 2 - DayOfWeek.THURSDAY -> 3 - DayOfWeek.FRIDAY -> 4 - DayOfWeek.SATURDAY -> 5 - DayOfWeek.SUNDAY -> 6 - } - - return LocalDate.fromEpochDays( - date.toEpochDays() - daysSinceMonday + weekOffset * 7, - ) -} - -private fun defaultSchoolDay(day: DayOfWeek): Int = - when (day) { - DayOfWeek.MONDAY -> 1 - DayOfWeek.TUESDAY -> 2 - DayOfWeek.WEDNESDAY -> 3 - DayOfWeek.THURSDAY -> 4 - DayOfWeek.FRIDAY -> 5 - DayOfWeek.SATURDAY, DayOfWeek.SUNDAY -> 1 - } - -private fun shortDayName(dayOrder: Int): String = - when (dayOrder) { - 1 -> tr("Hét", "Mon") - 2 -> tr("Ked", "Tue") - 3 -> tr("Sze", "Wed") - 4 -> tr("Csü", "Thu") - 5 -> tr("Pén", "Fri") - else -> "" - } - private fun formatWeekRange( monday: LocalDate, friday: LocalDate, ): String { val startMonth = monthName(monday.monthNumber) val endMonth = monthName(friday.monthNumber) - - return if (monday.monthNumber == friday.monthNumber) { - "${monday.year}. $startMonth ${monday.day} – ${friday.day}." - } else { - "${monday.year}. $startMonth ${monday.day} – $endMonth ${friday.day}." + return when { + monday.year != friday.year -> + "${monday.year}. $startMonth ${monday.day}. – ${friday.year}. $endMonth ${friday.day}." + monday.monthNumber != friday.monthNumber -> + "${monday.year}. $startMonth ${monday.day}. – $endMonth ${friday.day}." + else -> "${monday.year}. $startMonth ${monday.day}–${friday.day}." } } @@ -1173,17 +1055,10 @@ private fun monthName(month: Int): String = } private fun approximateTeachingWeek(monday: LocalDate): Int { - val schoolYear = - if (monday.monthNumber >= 9) { - monday.year - } else { - monday.year - 1 - } - - val schoolStart = LocalDate(schoolYear, 9, 1) - val elapsedDays = monday.toEpochDays() - schoolStart.toEpochDays() - - return (((elapsedDays.coerceAtLeast(0L)) / 7L) + 1L).toInt() + val friday = LocalDate.fromEpochDays(monday.toEpochDays() + 4) + val schoolYear = if (friday.monthNumber >= 9) friday.year else friday.year - 1 + val startMonday = schoolWeekMonday(LocalDate(schoolYear, 9, 1), 0) + return ((monday.toEpochDays() - startMonday.toEpochDays()) / 7L + 1L).toInt() } private fun weekBadgeLabel(week: WeekDefinitionDto?): String { @@ -1198,10 +1073,10 @@ private fun weekBadgeLabel(week: WeekDefinitionDto?): String { return tr("AKTUÁLIS", "CURRENT") } - return if (raw.contains("hét", ignoreCase = true)) { + return if (raw.contains("hét", ignoreCase = true) || raw.contains("week", ignoreCase = true)) { raw.uppercase() } else { - "${raw.uppercase()} HÉT" + tr("${raw.uppercase()} HÉT", "WEEK ${raw.uppercase()}") } } diff --git a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt new file mode 100644 index 0000000..e5cde2c --- /dev/null +++ b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt @@ -0,0 +1,50 @@ +package hu.petrik.filcapp.components + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate + +class SchoolWeekDaySelectorTest { + private val thursday = LocalDate(2026, 11, 19) + + @Test + fun selectedDayResolvesToExactCalendarDate() { + assertEquals(LocalDate(2026, 11, 16), schoolDateFor(thursday, 0, 1)) + assertEquals(thursday, schoolDateFor(thursday, 0, 4)) + assertEquals(LocalDate(2026, 11, 20), schoolDateFor(thursday, 0, 5)) + } + + @Test + fun weekNavigationAdjustsTheSelectedDate() { + assertEquals(LocalDate(2026, 11, 9), schoolDateFor(thursday, -1, 1)) + assertEquals(LocalDate(2026, 11, 27), schoolDateFor(thursday, 1, 5)) + } + + @Test + fun shortMonthsAndLeapYearsHaveValidDates() { + assertEquals(LocalDate(2027, 2, 22), schoolDateFor(LocalDate(2027, 2, 28), 0, 1)) + assertEquals(LocalDate(2028, 2, 28), schoolDateFor(LocalDate(2028, 2, 29), 0, 1)) + assertEquals(LocalDate(2028, 3, 3), schoolDateFor(LocalDate(2028, 2, 29), 0, 5)) + } + + @Test + fun weekCalculationCrossesYearsCorrectly() { + assertEquals(LocalDate(2026, 12, 28), schoolWeekMonday(LocalDate(2027, 1, 1), 0)) + assertEquals(LocalDate(2027, 1, 1), schoolDateFor(LocalDate(2027, 1, 1), 0, 5)) + } + + @Test + fun weekendsDefaultToMondayAsInTimetable() { + assertEquals(1, schoolDefaultDay(DayOfWeek.SATURDAY)) + assertEquals(1, schoolDefaultDay(DayOfWeek.SUNDAY)) + assertEquals(4, schoolDefaultDay(DayOfWeek.THURSDAY)) + } + + @Test + fun onlySchoolDaysCanBeSelected() { + assertFailsWith { schoolDateFor(thursday, 0, 0) } + assertFailsWith { schoolDateFor(thursday, 0, 6) } + } +} diff --git a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt new file mode 100644 index 0000000..af9bda0 --- /dev/null +++ b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt @@ -0,0 +1,46 @@ +package hu.petrik.filcapp.data + +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlinx.datetime.LocalDate + +class LessonWeekFilterTest { + private val both = WeekDefinitionDto(id = "all", short = "Mind", name = "Mind hét", weeks = listOf("11")) + private val a = WeekDefinitionDto(id = "a", short = "A", weeks = listOf("10")) + private val b = WeekDefinitionDto(id = "b", short = "B", weeks = listOf("01")) + private val entries = listOf( + LessonDto(id = "a", weekDefinition = a), + LessonDto(id = "b", weekDefinition = b), + LessonDto(id = "both", weekDefinition = both), + LessonDto(id = "null", weekDefinition = null), + ) + + @Test + fun aWeekIncludesBothWeekLessons() { + assertEquals(listOf("a", "both", "null"), filterLessonsForSchoolWeek(entries, LessonWeekType.A).map { it.id }) + } + + @Test + fun bWeekIncludesBothWeekLessons() { + assertEquals(listOf("b", "both", "null"), filterLessonsForSchoolWeek(entries, LessonWeekType.B).map { it.id }) + } + + @Test + fun fallbackClassificationMatchesFilcWebClient() { + assertEquals(LessonWeekType.A, lessonWeekType(WeekDefinitionDto(weeks = listOf("10")))) + assertEquals(LessonWeekType.B, lessonWeekType(WeekDefinitionDto(weeks = listOf("01")))) + assertEquals(LessonWeekType.A, lessonWeekType(WeekDefinitionDto(name = "A hét"))) + assertEquals(LessonWeekType.B, lessonWeekType(WeekDefinitionDto(name = "week b"))) + assertEquals(LessonWeekType.ALL, lessonWeekType(WeekDefinitionDto(weeks = listOf("11")))) + assertEquals(LessonWeekType.ALL, lessonWeekType(null)) + } + + @Test + fun alternatingWeeksAndYearBoundaries() { + assertEquals(LessonWeekType.A, schoolWeekTypeFor(LocalDate(2026, 8, 31))) + assertEquals(LessonWeekType.B, schoolWeekTypeFor(LocalDate(2026, 9, 7))) + assertEquals(LessonWeekType.A, schoolWeekTypeFor(LocalDate(2026, 9, 7), reversed = true)) + assertEquals(LessonWeekType.B, schoolWeekTypeFor(LocalDate(2026, 12, 28))) + assertEquals(LessonWeekType.A, schoolWeekTypeFor(LocalDate(2027, 1, 4))) + } +} From 99fefdc5d7b00fc709fc577d2e3dcaf547fabd09 Mon Sep 17 00:00:00 2001 From: merenyimiklos Date: Thu, 19 Nov 2026 23:37:18 +0100 Subject: [PATCH 2/4] fix: Kotlin compile and ktlint errors in school-week screens (#46 #47 #54) --- .../components/SchoolWeekDaySelector.kt | 1 + .../petrik/filcapp/data/LessonWeekFilter.kt | 21 ++++++++++--------- .../filcapp/screens/SubstitutionScreen.kt | 7 +++---- .../petrik/filcapp/screens/TimetableScreen.kt | 19 ++++++++++------- .../components/SchoolWeekDaySelectorTest.kt | 4 ++-- .../filcapp/data/LessonWeekFilterTest.kt | 15 ++++++------- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt index e9ca638..84abc63 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelector.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt index b4e5eca..56475b9 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/data/LessonWeekFilter.kt @@ -41,17 +41,18 @@ internal fun schoolWeekTypeFor( val friday = LocalDate.fromEpochDays(monday.toEpochDays() + 4) val academicYear = if (friday.monthNumber >= 9) friday.year else friday.year - 1 val septemberFirst = LocalDate(academicYear, 9, 1) - val daysSinceMonday = when (septemberFirst.dayOfWeek) { - kotlinx.datetime.DayOfWeek.MONDAY -> 0 - kotlinx.datetime.DayOfWeek.TUESDAY -> 1 - kotlinx.datetime.DayOfWeek.WEDNESDAY -> 2 - kotlinx.datetime.DayOfWeek.THURSDAY -> 3 - kotlinx.datetime.DayOfWeek.FRIDAY -> 4 - kotlinx.datetime.DayOfWeek.SATURDAY -> 5 - kotlinx.datetime.DayOfWeek.SUNDAY -> 6 - } + val daysSinceMonday = + when (septemberFirst.dayOfWeek) { + kotlinx.datetime.DayOfWeek.MONDAY -> 0 + kotlinx.datetime.DayOfWeek.TUESDAY -> 1 + kotlinx.datetime.DayOfWeek.WEDNESDAY -> 2 + kotlinx.datetime.DayOfWeek.THURSDAY -> 3 + kotlinx.datetime.DayOfWeek.FRIDAY -> 4 + kotlinx.datetime.DayOfWeek.SATURDAY -> 5 + kotlinx.datetime.DayOfWeek.SUNDAY -> 6 + } val startMonday = LocalDate.fromEpochDays(septemberFirst.toEpochDays() - daysSinceMonday) val weekIndex = (monday.toEpochDays() - startMonday.toEpochDays()) / 7 val parity = weekIndex + (if (reversed) 1 else 0) - return if (parity % 2 == 0) LessonWeekType.A else LessonWeekType.B + return if (parity % 2L == 0L) LessonWeekType.A else LessonWeekType.B } diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt index 7a5ee86..07ec3a2 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt @@ -1,4 +1,5 @@ package hu.petrik.filcapp.screens + import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.horizontalScroll @@ -64,11 +65,11 @@ import hu.petrik.filcapp.settings.tr import hu.petrik.filcapp.widgets.WidgetDestination import hu.petrik.filcapp.widgets.WidgetNavigation import hu.petrik.filcapp.widgets.WidgetSelectionType -import kotlin.time.Clock -import kotlin.time.ExperimentalTime import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.todayIn +import kotlin.time.Clock +import kotlin.time.ExperimentalTime private object SubstitutionSessionCache { var substitutions: List = emptyList() @@ -407,7 +408,6 @@ private fun SubstitutionOverviewHeader( date: LocalDate, changeCount: Int, ) { - Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp), @@ -859,7 +859,6 @@ private fun formatHungarianDate(date: LocalDate): String { private fun normalizeDate(value: String): String = value.take(10) - private fun formatTime(value: String): String = value.take(5) private fun displayName(item: NamedRefDto): String = item.short.ifBlank { item.name } diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt index a8e518a..a722804 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/TimetableScreen.kt @@ -74,11 +74,11 @@ import hu.petrik.filcapp.settings.tr import hu.petrik.filcapp.widgets.WidgetDestination import hu.petrik.filcapp.widgets.WidgetNavigation import hu.petrik.filcapp.widgets.WidgetSelectionType -import kotlin.time.Clock -import kotlin.time.ExperimentalTime import kotlinx.datetime.LocalDate import kotlinx.datetime.TimeZone import kotlinx.datetime.todayIn +import kotlin.time.Clock +import kotlin.time.ExperimentalTime private object TimetableSessionCache { var timetables: List = emptyList() @@ -538,10 +538,11 @@ private fun TimetableWeekSwitcher( textAlign = TextAlign.Center, ) Text( - text = tr( - "${approximateTeachingWeek(monday)}. tanítási hét", - "School week ${approximateTeachingWeek(monday)}", - ), + text = + tr( + "${approximateTeachingWeek(monday)}. tanítási hét", + "School week ${approximateTeachingWeek(monday)}", + ), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, ) @@ -563,8 +564,10 @@ private fun TimetableWeekSwitcher( verticalAlignment = Alignment.CenterVertically, ) { Box( - modifier = Modifier.size(6.dp) - .background(MaterialTheme.colorScheme.primary, CircleShape), + modifier = + Modifier + .size(6.dp) + .background(MaterialTheme.colorScheme.primary, CircleShape), ) Text( text = weekBadgeLabel(selectedWeek), diff --git a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt index e5cde2c..5b075e6 100644 --- a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt +++ b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/components/SchoolWeekDaySelectorTest.kt @@ -1,10 +1,10 @@ package hu.petrik.filcapp.components +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -import kotlinx.datetime.DayOfWeek -import kotlinx.datetime.LocalDate class SchoolWeekDaySelectorTest { private val thursday = LocalDate(2026, 11, 19) diff --git a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt index af9bda0..05d4f55 100644 --- a/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt +++ b/composeApp/src/commonTest/kotlin/hu/petrik/filcapp/data/LessonWeekFilterTest.kt @@ -1,19 +1,20 @@ package hu.petrik.filcapp.data +import kotlinx.datetime.LocalDate import kotlin.test.Test import kotlin.test.assertEquals -import kotlinx.datetime.LocalDate class LessonWeekFilterTest { private val both = WeekDefinitionDto(id = "all", short = "Mind", name = "Mind hét", weeks = listOf("11")) private val a = WeekDefinitionDto(id = "a", short = "A", weeks = listOf("10")) private val b = WeekDefinitionDto(id = "b", short = "B", weeks = listOf("01")) - private val entries = listOf( - LessonDto(id = "a", weekDefinition = a), - LessonDto(id = "b", weekDefinition = b), - LessonDto(id = "both", weekDefinition = both), - LessonDto(id = "null", weekDefinition = null), - ) + private val entries = + listOf( + LessonDto(id = "a", weekDefinition = a), + LessonDto(id = "b", weekDefinition = b), + LessonDto(id = "both", weekDefinition = both), + LessonDto(id = "null", weekDefinition = null), + ) @Test fun aWeekIncludesBothWeekLessons() { From bc7b6c5d3cdcdf2c1f0f73fced7da883f4bee351 Mon Sep 17 00:00:00 2001 From: merenyimiklos Date: Thu, 19 Nov 2026 23:44:41 +0100 Subject: [PATCH 3/4] style: reformat multiline function calls and cleanup formatting in SubstitutionScreen --- .../filcapp/screens/SubstitutionScreen.kt | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt index 07ec3a2..15187cb 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt @@ -129,7 +129,10 @@ fun SubstitutionScreen() { SubstitutionSessionCache.movedLessons = movedLessons SubstitutionSessionCache.error = null } catch (throwable: Throwable) { - error = throwable.message ?: tr("Nem sikerült betölteni a helyettesítéseket.", "Could not load substitutions.") + error = throwable.message ?: tr( + "Nem sikerült betölteni a helyettesítéseket.", + "Could not load substitutions." + ) SubstitutionSessionCache.error = error } finally { SubstitutionSessionCache.loaded = true @@ -251,7 +254,10 @@ fun SubstitutionScreen() { modifier = Modifier.fillMaxWidth().padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp), ) { - Text(tr("Hiba történt", "Something went wrong"), style = MaterialTheme.typography.titleMedium) + Text( + tr("Hiba történt", "Something went wrong"), + style = MaterialTheme.typography.titleMedium + ) Text(message) Button(onClick = { reloadKey++ }) { Text(tr("Újrapróbálás", "Retry")) @@ -280,7 +286,10 @@ fun SubstitutionScreen() { options = filterOptions, selectedId = selectedId, label = filterLabel(filter), - placeholder = tr("Szűrés nélkül minden látszik", "Without a filter everything is shown"), + placeholder = tr( + "Szűrés nélkül minden látszik", + "Without a filter everything is shown" + ), onSelected = { selectedId = it }, allowClear = true, ) @@ -639,7 +648,10 @@ private fun StatusPill( @Composable private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { - val subject = lesson.subject?.name ?: lesson.subject?.short ?: tr("Ismeretlen tantárgy", "Unknown subject") + val subject = lesson.subject?.name ?: lesson.subject?.short ?: tr( + "Ismeretlen tantárgy", + "Unknown subject" + ) val originalTeachers = lesson.teachers.joinToString(", ") { displayName(it) } val classrooms = lesson.classrooms.joinToString(", ") { displayName(it) } val cohorts = lesson.cohorts.cohortLabels() @@ -650,7 +662,11 @@ private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, ) { - Text(subject, style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold) + Text( + subject, + style = MaterialTheme.typography.titleSmall, + fontWeight = FontWeight.SemiBold + ) period?.let { Text("${it.period}.", style = MaterialTheme.typography.labelLarge) } } period?.let { @@ -662,7 +678,10 @@ private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { } DetailLine(tr("Osztály", "Class"), cohorts.ifBlank { "–" }) if (classrooms.isNotBlank()) DetailLine(tr("Terem", "Classroom"), classrooms) - if (originalTeachers.isNotBlank()) DetailLine(tr("Eredeti tanár", "Original teacher"), originalTeachers) + if (originalTeachers.isNotBlank()) DetailLine( + tr("Eredeti tanár", "Original teacher"), + originalTeachers + ) } } @@ -790,6 +809,7 @@ private fun filterSubstitutions( TimetableFilter.COHORT -> selectedCohort != null && lesson.cohorts.any { it.matchesCohortSelection(selectedCohort) } + TimetableFilter.TEACHER -> lesson.teachers.any { it.id == selectionId } TimetableFilter.CLASSROOM -> lesson.classrooms.any { it.id == selectionId } } @@ -858,7 +878,6 @@ private fun formatHungarianDate(date: LocalDate): String { private fun normalizeDate(value: String): String = value.take(10) - private fun formatTime(value: String): String = value.take(5) private fun displayName(item: NamedRefDto): String = item.short.ifBlank { item.name } From c5166898f25601cd728901ebb7adfb41c2fd9f78 Mon Sep 17 00:00:00 2001 From: merenyimiklos Date: Thu, 19 Nov 2026 23:46:28 +0100 Subject: [PATCH 4/4] style: reformat multiline function calls and cleanup formatting in SubstitutionScreen --- .../filcapp/screens/SubstitutionScreen.kt | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt index 15187cb..61b038c 100644 --- a/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt +++ b/composeApp/src/commonMain/kotlin/hu/petrik/filcapp/screens/SubstitutionScreen.kt @@ -129,10 +129,7 @@ fun SubstitutionScreen() { SubstitutionSessionCache.movedLessons = movedLessons SubstitutionSessionCache.error = null } catch (throwable: Throwable) { - error = throwable.message ?: tr( - "Nem sikerült betölteni a helyettesítéseket.", - "Could not load substitutions." - ) + error = throwable.message ?: tr("Nem sikerült betölteni a helyettesítéseket.", "Could not load substitutions.") SubstitutionSessionCache.error = error } finally { SubstitutionSessionCache.loaded = true @@ -254,10 +251,7 @@ fun SubstitutionScreen() { modifier = Modifier.fillMaxWidth().padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp), ) { - Text( - tr("Hiba történt", "Something went wrong"), - style = MaterialTheme.typography.titleMedium - ) + Text(tr("Hiba történt", "Something went wrong"), style = MaterialTheme.typography.titleMedium) Text(message) Button(onClick = { reloadKey++ }) { Text(tr("Újrapróbálás", "Retry")) @@ -286,10 +280,7 @@ fun SubstitutionScreen() { options = filterOptions, selectedId = selectedId, label = filterLabel(filter), - placeholder = tr( - "Szűrés nélkül minden látszik", - "Without a filter everything is shown" - ), + placeholder = tr("Szűrés nélkül minden látszik", "Without a filter everything is shown"), onSelected = { selectedId = it }, allowClear = true, ) @@ -648,10 +639,7 @@ private fun StatusPill( @Composable private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { - val subject = lesson.subject?.name ?: lesson.subject?.short ?: tr( - "Ismeretlen tantárgy", - "Unknown subject" - ) + val subject = lesson.subject?.name ?: lesson.subject?.short ?: tr("Ismeretlen tantárgy", "Unknown subject") val originalTeachers = lesson.teachers.joinToString(", ") { displayName(it) } val classrooms = lesson.classrooms.joinToString(", ") { displayName(it) } val cohorts = lesson.cohorts.cohortLabels() @@ -662,11 +650,7 @@ private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, ) { - Text( - subject, - style = MaterialTheme.typography.titleSmall, - fontWeight = FontWeight.SemiBold - ) + Text(subject, style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold) period?.let { Text("${it.period}.", style = MaterialTheme.typography.labelLarge) } } period?.let { @@ -678,10 +662,7 @@ private fun SubstitutionLessonDetails(lesson: SubstitutionLessonDto) { } DetailLine(tr("Osztály", "Class"), cohorts.ifBlank { "–" }) if (classrooms.isNotBlank()) DetailLine(tr("Terem", "Classroom"), classrooms) - if (originalTeachers.isNotBlank()) DetailLine( - tr("Eredeti tanár", "Original teacher"), - originalTeachers - ) + if (originalTeachers.isNotBlank()) DetailLine(tr("Eredeti tanár", "Original teacher"), originalTeachers) } } @@ -809,7 +790,6 @@ private fun filterSubstitutions( TimetableFilter.COHORT -> selectedCohort != null && lesson.cohorts.any { it.matchesCohortSelection(selectedCohort) } - TimetableFilter.TEACHER -> lesson.teachers.any { it.id == selectionId } TimetableFilter.CLASSROOM -> lesson.classrooms.any { it.id == selectionId } }