ui: header group display
This commit is contained in:
@@ -41,5 +41,5 @@ private class SimpleFactory<T : ViewModel>(private val create: () -> T) : ViewMo
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T = create() as T
|
||||
}
|
||||
|
||||
private fun scheduleFactory(c: AppContainer): ViewModelProvider.Factory = SimpleFactory { ScheduleViewModel(c.scheduleRepository, c.preferencesRepository) }
|
||||
private fun scheduleFactory(c: AppContainer): ViewModelProvider.Factory = SimpleFactory { ScheduleViewModel(c.scheduleRepository, c.preferencesRepository, c.groupRepository) }
|
||||
private fun groupPickerFactory(c: AppContainer): ViewModelProvider.Factory = SimpleFactory { GroupPickerViewModel(c.groupRepository) }
|
||||
|
||||
@@ -57,7 +57,7 @@ fun ScheduleScreen(viewModel: ScheduleViewModel, onSwitchGroup: () -> Unit) {
|
||||
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
TopAppBar(
|
||||
title = { Text("Расписание") },
|
||||
title = { Text(state.groupName ?: "Расписание", style = MaterialTheme.typography.titleMedium) },
|
||||
actions = {
|
||||
TextButton(onClick = { onSwitchGroup() }) {
|
||||
Text("Сменить группу")
|
||||
|
||||
@@ -2,6 +2,7 @@ package agzam.vyatsu.ui.schedule
|
||||
|
||||
import agzam.vyatsu.domain.ScheduleDates
|
||||
import agzam.vyatsu.domain.model.Schedule
|
||||
import agzam.vyatsu.domain.repository.GroupRepository
|
||||
import agzam.vyatsu.domain.repository.PreferencesRepository
|
||||
import agzam.vyatsu.domain.repository.ScheduleRepository
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -14,7 +15,8 @@ import java.time.LocalDate
|
||||
|
||||
class ScheduleViewModel(
|
||||
private val scheduleRepository: ScheduleRepository,
|
||||
private val preferencesRepository: PreferencesRepository
|
||||
private val preferencesRepository: PreferencesRepository,
|
||||
private val groupRepository: GroupRepository
|
||||
) : ViewModel() {
|
||||
|
||||
private val _uiState = MutableStateFlow(ScheduleUiState())
|
||||
@@ -28,7 +30,7 @@ class ScheduleViewModel(
|
||||
if (groupId != null) {
|
||||
selectGroup(groupId)
|
||||
} else {
|
||||
_uiState.value = _uiState.value.copy(noGroup = true)
|
||||
_uiState.value = _uiState.value.copy(noGroup = true, groupName = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,6 +39,7 @@ class ScheduleViewModel(
|
||||
currentGroupId = groupId
|
||||
viewModelScope.launch {
|
||||
preferencesRepository.setSelectedGroup(groupId)
|
||||
val groupName = groupRepository.getGroups().firstOrNull { it.id == groupId }?.name
|
||||
|
||||
val savedWeekStart = runCatching {
|
||||
preferencesRepository.selectedWeekStart()?.let(LocalDate::parse)
|
||||
@@ -46,6 +49,7 @@ class ScheduleViewModel(
|
||||
}.getOrNull()
|
||||
_uiState.value = _uiState.value.copy(
|
||||
noGroup = false,
|
||||
groupName = groupName,
|
||||
weekStart = savedWeekStart,
|
||||
dayDate = savedDayDate
|
||||
)
|
||||
@@ -174,6 +178,7 @@ data class ScheduleUiState(
|
||||
val isRefreshing: Boolean = false,
|
||||
val isSyncing: Boolean = false,
|
||||
val schedule: Schedule? = null,
|
||||
val groupName: String? = null,
|
||||
val weekStart: LocalDate? = null,
|
||||
val dayDate: LocalDate? = null,
|
||||
val todayDate: LocalDate? = null
|
||||
|
||||
Reference in New Issue
Block a user