11package io.github.openflocon.flocondesktop.device
22
3- import androidx.compose.foundation.clickable
43import androidx.compose.foundation.layout.Arrangement
54import androidx.compose.foundation.layout.Column
65import androidx.compose.foundation.layout.PaddingValues
76import androidx.compose.foundation.layout.Row
87import androidx.compose.foundation.layout.fillMaxSize
98import androidx.compose.foundation.layout.fillMaxWidth
109import androidx.compose.foundation.layout.padding
11- import androidx.compose.foundation.lazy.LazyColumn
12- import androidx.compose.foundation.lazy.items
1310import androidx.compose.foundation.pager.HorizontalPager
1411import androidx.compose.foundation.pager.rememberPagerState
12+ import androidx.compose.foundation.text.selection.SelectionContainer
1513import androidx.compose.material.icons.Icons
1614import androidx.compose.material.icons.outlined.Refresh
1715import androidx.compose.material3.Text
@@ -20,17 +18,17 @@ import androidx.compose.runtime.LaunchedEffect
2018import androidx.compose.runtime.getValue
2119import androidx.compose.ui.Alignment
2220import androidx.compose.ui.Modifier
23- import androidx.compose.ui.draw.clip
2421import androidx.compose.ui.unit.dp
2522import androidx.lifecycle.compose.collectAsStateWithLifecycle
2623import io.github.openflocon.domain.device.models.DeviceId
2724import io.github.openflocon.flocondesktop.common.ui.window.FloconWindow
2825import io.github.openflocon.flocondesktop.common.ui.window.createFloconWindowState
29- import io.github.openflocon.flocondesktop.device.models.CpuItem
3026import io.github.openflocon.flocondesktop.device.models.DeviceUiState
3127import io.github.openflocon.flocondesktop.device.models.previewDeviceUiState
28+ import io.github.openflocon.flocondesktop.device.pages.CpuPage
29+ import io.github.openflocon.flocondesktop.device.pages.InfoPage
30+ import io.github.openflocon.flocondesktop.device.pages.PermissionPage
3231import io.github.openflocon.library.designsystem.FloconTheme
33- import io.github.openflocon.library.designsystem.components.FloconCheckbox
3432import io.github.openflocon.library.designsystem.components.FloconHorizontalDivider
3533import io.github.openflocon.library.designsystem.components.FloconIconButton
3634import io.github.openflocon.library.designsystem.components.FloconScaffold
@@ -129,14 +127,14 @@ private fun Content(
129127 .padding(it)
130128 ) { index ->
131129 when (index) {
132- 0 -> InfoPage (uiState)
130+ 0 -> InfoPage (uiState.infoState )
133131 1 -> CpuPage (
134- uiState = uiState,
132+ state = uiState.cpuState ,
135133 onAction = onAction
136134 )
137135
138136 2 -> PermissionPage (
139- uiState = uiState,
137+ state = uiState.permissionState ,
140138 onAction = onAction
141139 )
142140
@@ -156,143 +154,27 @@ private fun Header(
156154 Row (
157155 verticalAlignment = Alignment .CenterVertically
158156 ) {
159- Text (
160- text = " ${uiState.infoState.model} (${uiState.infoState.serialNumber} )" ,
161- style = FloconTheme .typography.headlineSmall,
157+ Column (
162158 modifier = Modifier
163- .weight( 1f )
159+ .fillMaxWidth( )
164160 .padding(16 .dp)
165- )
166- FloconIconButton (
167- imageVector = Icons .Outlined .Refresh ,
168- onClick = { onAction(DeviceAction .Refresh ) }
169- )
170- }
171- }
172-
173- @Composable
174- private fun InfoPage (
175- uiState : DeviceUiState
176- ) {
177- Column (
178- verticalArrangement = Arrangement .spacedBy(4 .dp),
179- modifier = Modifier .fillMaxSize()
180- ) {
181- FloconTextValue (" Brand" , uiState.infoState.brand)
182- // FloconTextValue("CPU", uiState.cpu)
183- // FloconTextValue("Memory", uiState.mem)
184- FloconTextValue (" Battery" , uiState.infoState.battery)
185- FloconTextValue (" Serial number" , uiState.infoState.serialNumber)
186- FloconTextValue (" Version - Release" , uiState.infoState.versionRelease)
187- FloconTextValue (" Version - Sdk" , uiState.infoState.versionSdk)
188- }
189- }
190-
191- @Composable
192- private fun CpuPage (
193- uiState : DeviceUiState ,
194- onAction : (DeviceAction ) -> Unit
195- ) {
196- LazyColumn (
197- modifier = Modifier .fillMaxSize()
198- ) {
199- items(
200- items = uiState.cpuState.list,
201- key = CpuItem ::packageName
202- ) {
203- Row (
204- horizontalArrangement = Arrangement .spacedBy(4 .dp),
205- verticalAlignment = Alignment .CenterVertically ,
206- modifier = Modifier
207- .fillMaxWidth()
208- .clip(FloconTheme .shapes.medium)
209- .padding(4 .dp)
210- ) {
211- Text (
212- text = it.cpuUsage.toString(),
213- style = FloconTheme .typography.labelSmall,
214- modifier = Modifier .weight(.1f )
215- )
216- Text (
217- text = it.userPercentage.toString(),
218- style = FloconTheme .typography.labelSmall,
219- modifier = Modifier .weight(.1f )
220- )
221- Text (
222- text = it.kernelPercentage.toString(),
223- style = FloconTheme .typography.labelSmall,
224- modifier = Modifier .weight(.1f )
225- )
226- Text (
227- text = it.pId.toString(),
228- style = FloconTheme .typography.labelSmall,
229- modifier = Modifier .weight(.1f )
230- )
231- Text (
232- text = it.packageName,
233- style = FloconTheme .typography.labelSmall,
234- modifier = Modifier .weight(1f )
235- )
236- Text (
237- text = it.userPercentage.toString(),
238- style = FloconTheme .typography.labelSmall,
239- modifier = Modifier .weight(.1f )
240- )
241- Text (
242- text = it.majorFaults.toString(),
243- style = FloconTheme .typography.labelSmall,
244- modifier = Modifier .weight(.1f )
245- )
246- Text (
247- text = it.minorFaults.toString(),
248- style = FloconTheme .typography.labelSmall,
249- modifier = Modifier .weight(.1f )
250- )
251- }
252- }
253- }
254- }
255-
256- @Composable
257- private fun PermissionPage (
258- uiState : DeviceUiState ,
259- onAction : (DeviceAction ) -> Unit
260- ) {
261- LazyColumn (
262- modifier = Modifier .fillMaxSize()
263- ) {
264- items(
265- items = uiState.permissionState.list,
266- key = { it.name }
161+ .weight(1f )
267162 ) {
268- Row (
269- horizontalArrangement = Arrangement .spacedBy(4 .dp),
270- verticalAlignment = Alignment .CenterVertically ,
271- modifier = Modifier
272- .fillMaxWidth()
273- .clip(FloconTheme .shapes.medium)
274- .clickable(onClick = {
275- // onAction(
276- // DeviceAction.ChangePermission(
277- // permissions = it.permissions,
278- // granted = it.granted
279- // )
280- // )
281- })
282- .padding(4 .dp)
283- ) {
163+ Text (
164+ text = uiState.infoState.model,
165+ style = FloconTheme .typography.headlineSmall
166+ )
167+ SelectionContainer {
284168 Text (
285- text = it.name,
286- style = FloconTheme .typography.labelSmall,
287- modifier = Modifier .weight(1f )
288- )
289- FloconCheckbox (
290- checked = it.granted,
291- onCheckedChange = null ,
292- uncheckedColor = FloconTheme .colorPalette.primary,
169+ text = uiState.infoState.serialNumber,
170+ style = FloconTheme .typography.labelSmall
293171 )
294172 }
295173 }
174+ FloconIconButton (
175+ imageVector = Icons .Outlined .Refresh ,
176+ onClick = { onAction(DeviceAction .Refresh ) }
177+ )
296178 }
297179}
298180
0 commit comments