diff --git a/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/WearInfoContainerScreen.kt b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/WearInfoContainerScreen.kt index 2d84bca2..e13b4be3 100644 --- a/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/WearInfoContainerScreen.kt +++ b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/WearInfoContainerScreen.kt @@ -12,7 +12,6 @@ import com.kgurgul.cpuinfo.features.information.InfoContainerViewModel.Companion import com.kgurgul.cpuinfo.features.information.InfoContainerViewModel.Companion.SCREEN_POS import com.kgurgul.cpuinfo.features.information.InfoContainerViewModel.Companion.SENSORS_POS import com.kgurgul.cpuinfo.features.information.InfoContainerViewModel.Companion.STORAGE_POS -import com.kgurgul.cpuinfo.features.information.gpu.GpuInfoScreen import com.kgurgul.cpuinfo.features.information.hardware.HardwareInfoScreen import com.kgurgul.cpuinfo.features.information.os.OsInfoScreen import com.kgurgul.cpuinfo.features.information.ram.RamInfoScreen @@ -20,6 +19,7 @@ import com.kgurgul.cpuinfo.features.information.screen.ScreenInfoScreen import com.kgurgul.cpuinfo.features.information.sensors.SensorsInfoScreen import com.kgurgul.cpuinfo.features.information.storage.StorageInfoScreen import com.kgurgul.cpuinfo.wear.features.information.cpu.WearCpuInfoScreen +import com.kgurgul.cpuinfo.wear.features.information.gpu.WearGpuInfoScreen @Composable @@ -30,7 +30,7 @@ fun WearInfoContainerScreen() { ) { when (it) { CPU_POS -> WearCpuInfoScreen() - GPU_POS -> GpuInfoScreen() + GPU_POS -> WearGpuInfoScreen() RAM_POS -> RamInfoScreen() STORAGE_POS -> StorageInfoScreen() SCREEN_POS -> ScreenInfoScreen() diff --git a/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/gpu/WearGpuInfoScreen.kt b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/gpu/WearGpuInfoScreen.kt new file mode 100644 index 00000000..6f3100b2 --- /dev/null +++ b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/features/information/gpu/WearGpuInfoScreen.kt @@ -0,0 +1,82 @@ +@file:OptIn(ExperimentalHorologistApi::class) + +package com.kgurgul.cpuinfo.wear.features.information.gpu + +import androidx.compose.foundation.layout.Box +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.wear.compose.foundation.lazy.items +import androidx.wear.compose.material.MaterialTheme +import androidx.wear.compose.material.Text +import com.google.android.horologist.annotations.ExperimentalHorologistApi +import com.google.android.horologist.compose.layout.ScalingLazyColumn +import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults +import com.google.android.horologist.compose.layout.ScreenScaffold +import com.google.android.horologist.compose.layout.rememberResponsiveColumnState +import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding +import com.google.android.horologist.compose.material.ResponsiveListHeader +import com.kgurgul.cpuinfo.domain.model.getKey +import com.kgurgul.cpuinfo.domain.model.getName +import com.kgurgul.cpuinfo.domain.model.getValue +import com.kgurgul.cpuinfo.features.information.gpu.GpuInfoViewModel +import com.kgurgul.cpuinfo.features.information.gpu.InternalGLSurfaceView +import com.kgurgul.cpuinfo.shared.Res +import com.kgurgul.cpuinfo.shared.gpu +import com.kgurgul.cpuinfo.wear.ui.components.WearCpuChip +import org.jetbrains.compose.resources.stringResource +import org.koin.compose.viewmodel.koinViewModel + +@Composable +fun WearGpuInfoScreen( + viewModel: GpuInfoViewModel = koinViewModel(), +) { + val uiState by viewModel.uiStateFlow.collectAsStateWithLifecycle() + + Box { + InternalGLSurfaceView( + onGlInfoReceived = { vendor, renderer, extensions -> + viewModel.onGlInfoReceived(vendor, renderer, extensions) + }, + ) + WearGpuInfoScreen( + uiState = uiState, + ) + } +} + +@Composable +fun WearGpuInfoScreen( + uiState: GpuInfoViewModel.UiState, +) { + val columnState = rememberResponsiveColumnState( + contentPadding = ScalingLazyColumnDefaults.padding( + first = ScalingLazyColumnDefaults.ItemType.Text, + last = ScalingLazyColumnDefaults.ItemType.Chip, + ), + ) + ScreenScaffold(scrollState = columnState) { + ScalingLazyColumn( + columnState = columnState + ) { + item(key = "__header") { + ResponsiveListHeader(contentPadding = firstItemPadding()) { + Text( + text = stringResource(Res.string.gpu), + color = MaterialTheme.colors.onBackground, + ) + } + } + items( + uiState.gpuData, + key = { itemValue -> itemValue.getKey() }, + ) { itemValue -> + WearCpuChip( + label = itemValue.getName(), + secondaryLabel = itemValue.getValue(), + secondaryLabelMaxLines = 100, + ) + } + } + } +} diff --git a/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/ui/components/WearCpuChip.kt b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/ui/components/WearCpuChip.kt index 5c81cfce..7ee79c18 100644 --- a/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/ui/components/WearCpuChip.kt +++ b/wearOsApp/src/androidMain/kotlin/com/kgurgul/cpuinfo/wear/ui/components/WearCpuChip.kt @@ -38,6 +38,8 @@ fun WearCpuChip( secondaryLabel: String? = null, colors: ChipColors = ChipDefaults.primaryChipColors(), border: ChipBorder = ChipDefaults.chipBorder(), + labelMaxLines: Int = 3, + secondaryLabelMaxLines: Int = 3, ) { Chip( modifier = Modifier @@ -49,7 +51,7 @@ fun WearCpuChip( label = { Text( text = label, - maxLines = 3, + maxLines = labelMaxLines, overflow = TextOverflow.Ellipsis ) }, @@ -57,7 +59,7 @@ fun WearCpuChip( { Text( text = secondaryLabel, - maxLines = 3, + maxLines = secondaryLabelMaxLines, overflow = TextOverflow.Ellipsis ) }