Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,91 @@
package com.google.android.horologist.ai.sample.wear.gemini.activity

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.items
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.ListHeader
import androidx.wear.compose.material3.MaterialTheme
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import coil.compose.AsyncImage
import com.google.android.horologist.compose.layout.ColumnItemType
import com.google.android.horologist.compose.layout.rememberResponsiveColumnPadding

@Composable
fun DeviceStatusScreen(
modifier: Modifier = Modifier,
viewModel: DeviceStatusViewModel = hiltViewModel(),
) {
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
ScreenScaffold(modifier = modifier) {
Column(
val columnState = rememberTransformingLazyColumnState()
val transformationSpec = rememberTransformationSpec()

val data = uiState.value
val paragraphs = remember((data as? Loaded)?.description) {
(data as? Loaded)?.description?.split("[\n,]+".toRegex()).orEmpty()
}

ScreenScaffold(
modifier = modifier,
contentPadding = rememberResponsiveColumnPadding(
first = ColumnItemType.IconButton,
last = ColumnItemType.BodyText,
),
scrollState = columnState,
) { contentPadding ->
TransformingLazyColumn(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
contentPadding = contentPadding,
state = columnState,
) {
val uiState = uiState.value
if (uiState is Loaded) {
AsyncImage(
model = uiState.image,
contentDescription = null,
modifier = Modifier.width(100.dp),
contentScale = ContentScale.FillWidth,
)
Text(uiState.description ?: "None", style = MaterialTheme.typography.bodyExtraSmall)
item {
ListHeader(modifier = Modifier.fillMaxWidth()) {
Text("Gemini")
}
}
if (data is Loaded) {
items(paragraphs.take(3)) {
Text(
it,
style = MaterialTheme.typography.bodyExtraSmall,
modifier = Modifier.padding(bottom = 6.dp),
)
}
item {
AsyncImage(
model = data.image,
contentDescription = null,
modifier = Modifier.width(100.dp),
contentScale = ContentScale.FillWidth,
)
}
items(paragraphs.drop(3)) {
Text(
it,
style = MaterialTheme.typography.bodyExtraSmall,
modifier = Modifier.padding(bottom = 6.dp),
)
}
} else {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious why not using Placeholder API, just for simplicity?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should. It's just not there yet.

Text("Loading...")
item {
Text("Loading...")
}
}
}
}
Expand Down
Loading