diff --git a/app/src/main/java/com/lukeneedham/videodiary/ui/feature/common/datepicker/DiaryDatePicker.kt b/app/src/main/java/com/lukeneedham/videodiary/ui/feature/common/datepicker/DiaryDatePicker.kt index 828cc41..f4de406 100644 --- a/app/src/main/java/com/lukeneedham/videodiary/ui/feature/common/datepicker/DiaryDatePicker.kt +++ b/app/src/main/java/com/lukeneedham/videodiary/ui/feature/common/datepicker/DiaryDatePicker.kt @@ -5,11 +5,17 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.semantics.semantics import androidx.compose.ui.tooling.preview.Preview +import com.lukeneedham.videodiary.R import com.lukeneedham.videodiary.domain.model.Day import java.time.DayOfWeek import java.time.LocalDate @@ -34,9 +40,27 @@ fun DiaryDatePicker( placeholderDaysStart + week.map { Weekday.Value(it) } + placeholderDaysEnd } + val today = LocalDate.now() + val rows = buildList { + var previousWasCollapsed = false + weekDays.forEach { week -> + val isCurrentWeek = week.any { it is Weekday.Value && it.day.date == today } + val isEmpty = week.none { it is Weekday.Value && it.day.video != null } + if (!isCurrentWeek && isEmpty) { + if (!previousWasCollapsed) { + add(WeekRow.Collapsed) + previousWasCollapsed = true + } + } else { + add(WeekRow.Normal(week)) + previousWasCollapsed = false + } + } + } + val firstVisibleWeekIndex = remember { - val res = weekDays.indexOfFirst { week -> - week.any { it is Weekday.Value && it.day.date == initialFocusedDate } + val res = rows.indexOfFirst { row -> + row is WeekRow.Normal && row.week.any { it is Weekday.Value && it.day.date == initialFocusedDate } } if (res == -1) 0 else res } @@ -53,30 +77,46 @@ fun DiaryDatePicker( state = state, modifier = modifier ) { - items(weekDays) { week -> - Row(modifier = Modifier.fillParentMaxWidth()) { - week.forEach { weekday -> - Box( - modifier = Modifier - .weight(1f) - ) { - when (weekday) { - is Weekday.Empty -> { - // Nothing - } + items(rows) { row -> + when (row) { + is WeekRow.Normal -> { + Row(modifier = Modifier.fillParentMaxWidth()) { + row.week.forEach { weekday -> + Box( + modifier = Modifier + .weight(1f) + ) { + when (weekday) { + is Weekday.Empty -> { + // Nothing + } - is Weekday.Value -> { - val day = weekday.day - DiaryDatePickerDay( - day = day, - onClick = { - onDateSelected(day.date) + is Weekday.Value -> { + val day = weekday.day + DiaryDatePickerDay( + day = day, + onClick = { + onDateSelected(day.date) + } + ) } - ) + } } } } } + + is WeekRow.Collapsed -> { + val collapsedDescription = stringResource(R.string.date_picker_collapsed_weeks_description) + Box( + contentAlignment = Alignment.Center, + modifier = Modifier + .fillParentMaxWidth() + .semantics { contentDescription = collapsedDescription } + ) { + Text(text = stringResource(R.string.date_picker_collapsed_weeks)) + } + } } } } @@ -87,6 +127,11 @@ private sealed interface Weekday { data object Empty : Weekday } +private sealed interface WeekRow { + data class Normal(val week: List) : WeekRow + data object Collapsed : WeekRow +} + @Preview @Composable private fun Preview() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 94e6925..9aed094 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,5 @@ Video Diary + + Empty weeks collapsed \ No newline at end of file