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