forked from agzam/vyatsu-schedule
refactor: database multi-period schedule storage
This commit is contained in:
@@ -94,6 +94,17 @@ fun ScheduleScreen(viewModel: ScheduleViewModel, onSwitchGroup: () -> Unit) {
|
||||
"$dayLabel ${dayName(day.date.dayOfWeek)} · ${day.date.format(FULL_DATE)}",
|
||||
style = MaterialTheme.typography.titleMedium
|
||||
)
|
||||
Row(
|
||||
Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
TextButton(onClick = { viewModel.clearSelectedPeriod() }) {
|
||||
Text("Очистить неделю")
|
||||
}
|
||||
TextButton(onClick = { viewModel.clearAll() }) {
|
||||
Text("Очистить всё")
|
||||
}
|
||||
}
|
||||
HorizontalDivider(Modifier.padding(vertical = 8.dp))
|
||||
|
||||
DayChips(
|
||||
|
||||
@@ -93,6 +93,23 @@ class ScheduleViewModel(
|
||||
_uiState.value = _uiState.value.copy(selectedIndex = index)
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
val groupId = currentGroupId ?: return
|
||||
viewModelScope.launch {
|
||||
scheduleRepository.clearAll(groupId)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearSelectedPeriod() {
|
||||
val state = _uiState.value
|
||||
val schedule = state.schedule ?: return
|
||||
val day = schedule.days.getOrNull(state.selectedIndex) ?: return
|
||||
val period = schedule.periodOf(day.date) ?: return
|
||||
viewModelScope.launch {
|
||||
scheduleRepository.clearPeriod(schedule.groupId, period)
|
||||
}
|
||||
}
|
||||
|
||||
private fun todayIndex(days: List<Day>): Int {
|
||||
if (days.isEmpty()) return 0
|
||||
val today = ScheduleDates.moscowToday()
|
||||
|
||||
Reference in New Issue
Block a user