private fun downloadStateReducer( state: DownloadFragmentState, action: DownloadFragmentAction, ): DownloadFragmentState { return when (action) { is DownloadFragmentAction.AddItemForRemoval -> state.copy(mode = DownloadFragmentState.Mode.Editing(state.mode.selectedItems + action.item)) is DownloadFragmentAction.RemoveItemForRemoval -> { val selected = state.mode.selectedItems - action.item state.copy( mode = if (selected.isEmpty()) { DownloadFragmentState.Mode.Normal } else { DownloadFragmentState.Mode.Editing(selected) }, ) } is DownloadFragmentAction.ExitEditMode -> state.copy(mode = DownloadFragmentState.Mode.Normal) is DownloadFragmentAction.EnterDeletionMode -> state.copy(isDeletingItems = true) is DownloadFragmentAction.ExitDeletionMode -> state.copy(isDeletingItems = false) is DownloadFragmentAction.AddPendingDeletionSet -> state.copy( pendingDeletionIds = state.pendingDeletionIds + action.itemIds, ) is DownloadFragmentAction.UndoPendingDeletionSet -> state.copy( pendingDeletionIds = state.pendingDeletionIds - action.itemIds, ) } }
The DownloadState Reducer.