Add a "Views" settings section that lets users pick which views the top-bar quick-switch button cycles through and drag to reorder them, plus an independent drag-to-reorder for the navigation drawer's view list. Two separate configs: a view turned off in the quick-switch cycle is still reachable from the drawer, which always lists every view. - QuickSwitchConfig (order + enabled set) and a drawer order persisted in SettingsPrefs (comma-joined enum names; "!" marks a disabled view). Missing views append enabled and unknown names drop, so a future view defaults into both lists. - The pill cycles through the configured enabled views in order; the drawer renders CalendarDrawer from the drawer order. Both threaded from CalendarHost via CalendarHostViewModel. - New ReorderableColumn: dependency-free, measurement-driven drag reordering for the short grouped-card settings lists (no LazyColumn, since settings are a single verticalScroll column). Commits one write per gesture. - The switch needs two targets, so the last two enabled views can't be turned off. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
49 lines
1.8 KiB
Kotlin
49 lines
1.8 KiB
Kotlin
package de.jeanlucmakiola.calendula.ui
|
|
|
|
import androidx.lifecycle.ViewModel
|
|
import androidx.lifecycle.viewModelScope
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
import de.jeanlucmakiola.calendula.data.prefs.SettingsPrefs
|
|
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
|
import de.jeanlucmakiola.calendula.ui.common.IMPLEMENTED_VIEWS
|
|
import kotlinx.coroutines.flow.SharingStarted
|
|
import kotlinx.coroutines.flow.StateFlow
|
|
import kotlinx.coroutines.flow.map
|
|
import kotlinx.coroutines.flow.stateIn
|
|
import javax.inject.Inject
|
|
|
|
/**
|
|
* Supplies [CalendarHost] with the user's default startup view (M1). Held as a
|
|
* nullable [StateFlow] so the host can wait for DataStore's first emission before
|
|
* seeding its view back stack — rendering nothing for that first frame rather
|
|
* than flashing the old hard-coded Week view and then correcting it.
|
|
*/
|
|
@HiltViewModel
|
|
class CalendarHostViewModel @Inject constructor(
|
|
prefs: SettingsPrefs,
|
|
) : ViewModel() {
|
|
|
|
val defaultView: StateFlow<CalendarView?> = prefs.defaultView.stateIn(
|
|
scope = viewModelScope,
|
|
started = SharingStarted.WhileSubscribed(5_000L),
|
|
initialValue = null,
|
|
)
|
|
|
|
/** Views the top-bar quick-switch pill cycles through, in the user's order (#24). */
|
|
val quickSwitchViews: StateFlow<List<CalendarView>> = prefs.quickSwitchConfig
|
|
.map { it.cycle }
|
|
.stateIn(
|
|
scope = viewModelScope,
|
|
started = SharingStarted.WhileSubscribed(5_000L),
|
|
initialValue = IMPLEMENTED_VIEWS,
|
|
)
|
|
|
|
/** Order of the views in the navigation drawer (#24); every view always shown. */
|
|
val drawerViewOrder: StateFlow<List<CalendarView>> = prefs.drawerViewOrder
|
|
.stateIn(
|
|
scope = viewModelScope,
|
|
started = SharingStarted.WhileSubscribed(5_000L),
|
|
initialValue = IMPLEMENTED_VIEWS,
|
|
)
|
|
}
|