Move code into coroutines

This commit is contained in:
Damontecres 2026-01-30 10:30:39 -05:00
parent 8437ddb51d
commit bec833b0e8
No known key found for this signature in database

View file

@ -176,13 +176,15 @@ class HomeSettingsViewModel
} }
fun deleteRow(index: Int) { fun deleteRow(index: Int) {
updateState { viewModelScope.launchIO {
val rows = it.rows.toMutableList().apply { removeAt(index) } updateState {
val rowData = it.rowData.toMutableList().apply { removeAt(index) } val rows = it.rows.toMutableList().apply { removeAt(index) }
it.copy( val rowData = it.rowData.toMutableList().apply { removeAt(index) }
rows = rows, it.copy(
rowData = rowData, rows = rows,
) rowData = rowData,
)
}
} }
} }
@ -341,17 +343,19 @@ class HomeSettingsViewModel
} }
fun updateViewOptionsForAll(viewOptions: HomeRowViewOptions) { fun updateViewOptionsForAll(viewOptions: HomeRowViewOptions) {
updateState { viewModelScope.launchIO {
it.copy( updateState {
rowData = it.copy(
it.rowData.toMutableList().map { row -> rowData =
if (row is HomeRowLoadingState.Success) { it.rowData.toMutableList().map { row ->
row.copy(viewOptions = viewOptions) if (row is HomeRowLoadingState.Success) {
} else { row.copy(viewOptions = viewOptions)
row } else {
} row
}, }
) },
)
}
} }
} }
@ -456,24 +460,26 @@ class HomeSettingsViewModel
} }
fun resizeCards(relative: Int) { fun resizeCards(relative: Int) {
updateState { viewModelScope.launchIO {
val newRows = updateState {
it.rows.toMutableList().map { row -> val newRows =
val vo = row.config.viewOptions it.rows.toMutableList().map { row ->
val newVo = vo.copy(heightDp = vo.heightDp + (4 * relative)) val vo = row.config.viewOptions
row.copy(config = row.config.updateViewOptions(newVo)) val newVo = vo.copy(heightDp = vo.heightDp + (4 * relative))
} row.copy(config = row.config.updateViewOptions(newVo))
it.copy( }
rows = newRows, it.copy(
rowData = rows = newRows,
it.rowData.toMutableList().mapIndexed { index, row -> rowData =
if (row is HomeRowLoadingState.Success) { it.rowData.toMutableList().mapIndexed { index, row ->
row.copy(viewOptions = newRows[index].config.viewOptions) if (row is HomeRowLoadingState.Success) {
} else { row.copy(viewOptions = newRows[index].config.viewOptions)
row } else {
} row
}, }
) },
)
}
} }
} }
} }