diff options
| author | Albin <albin@mullvad.net> | 2022-07-28 15:45:10 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2022-07-29 13:01:20 +0200 |
| commit | aab63a0ce2f94f00f893df86789699b32c53e7b7 (patch) | |
| tree | cb910337fdd1cf21b63cb7b745b89ef8ff0a4aa6 /android/app | |
| parent | 32e57e938ec3a336a1cbfa7a6c5cbbc6fbc5d6dd (diff) | |
| download | mullvadvpn-aab63a0ce2f94f00f893df86789699b32c53e7b7.tar.xz mullvadvpn-aab63a0ce2f94f00f893df86789699b32c53e7b7.zip | |
Add device list item ui model
Diffstat (limited to 'android/app')
3 files changed, 14 insertions, 8 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt index 970c9812c5..99218a8837 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceListScreen.kt @@ -141,13 +141,13 @@ fun DeviceListScreen( } ) { Column { - state.devices.forEach { device -> + state.deviceUiItems.forEach { deviceUiState -> ListItem( - text = device.name.capitalizeFirstCharOfEachWord(), - isLoading = false, + text = deviceUiState.device.name.capitalizeFirstCharOfEachWord(), + isLoading = deviceUiState.isLoading, iconResourceId = R.drawable.icon_close ) { - viewModel.stageDeviceForRemoval(device.id) + viewModel.stageDeviceForRemoval(deviceUiState.device.id) } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt index d9edae81da..e989960301 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/DeviceListUiState.kt @@ -3,17 +3,22 @@ package net.mullvad.mullvadvpn.compose.state import net.mullvad.mullvadvpn.model.Device data class DeviceListUiState( - val devices: List<Device>, + val deviceUiItems: List<DeviceListItemUiState>, val isLoading: Boolean, val stagedDevice: Device? ) { - val hasTooManyDevices = devices.count() >= 5 + val hasTooManyDevices = deviceUiItems.count() >= 5 companion object { val INITIAL = DeviceListUiState( - devices = listOf(), + deviceUiItems = emptyList(), isLoading = true, stagedDevice = null ) } } + +data class DeviceListItemUiState( + val device: Device, + val isLoading: Boolean +) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt index 7aa748ddba..5631f74b73 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceListViewModel.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn +import net.mullvad.mullvadvpn.compose.state.DeviceListItemUiState import net.mullvad.mullvadvpn.compose.state.DeviceListUiState import net.mullvad.mullvadvpn.ui.serviceconnection.DeviceRepository import net.mullvad.mullvadvpn.util.safeLet @@ -30,7 +31,7 @@ class DeviceListViewModel( device.id == stagedDeviceId } DeviceListUiState( - devices = deviceList, + deviceUiItems = deviceList.map { DeviceListItemUiState(it, false) }, isLoading = false, stagedDevice = stagedDevice ) |
