Saving unit groups order in onDragEnd

This commit is contained in:
Sad Ellie 2022-08-14 11:46:10 +03:00
parent 3f4b21af4d
commit c965a68198
2 changed files with 11 additions and 3 deletions

View File

@ -134,12 +134,19 @@ class SettingsViewModel @Inject constructor(
}
/**
* See [UnitGroupsRepository.moveShownUnitGroups] and
* [UserPreferencesRepository.updateShownUnitGroups]
* See [UnitGroupsRepository.moveShownUnitGroups]
*/
fun onMove(from: ItemPosition, to: ItemPosition) {
viewModelScope.launch {
unitGroupsRepository.moveShownUnitGroups(from, to)
}
}
/**
* See [UserPreferencesRepository.updateShownUnitGroups]
*/
fun onDragEnd() {
viewModelScope.launch {
userPrefsRepository.updateShownUnitGroups(unitGroupsRepository.shownUnitGroups.value)
}
}

View File

@ -66,7 +66,8 @@ fun UnitGroupsScreen(
val state = rememberReorderableLazyListState(
onMove = viewModel::onMove,
canDragOver = viewModel::canDragOver
canDragOver = viewModel::canDragOver,
onDragEnd = { _, _ -> viewModel.onDragEnd() }
)
LazyColumn(