Skip to content

Commit

Permalink
[WEAR] Add GPU screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kamgurgul committed Jan 2, 2025
1 parent 736fb18 commit 9a055c8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ 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
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
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,15 +51,15 @@ fun WearCpuChip(
label = {
Text(
text = label,
maxLines = 3,
maxLines = labelMaxLines,
overflow = TextOverflow.Ellipsis
)
},
secondaryLabel = if (secondaryLabel != null) {
{
Text(
text = secondaryLabel,
maxLines = 3,
maxLines = secondaryLabelMaxLines,
overflow = TextOverflow.Ellipsis
)
}
Expand Down

0 comments on commit 9a055c8

Please sign in to comment.