From 8d7268f194a3d32a56b0d2de475e1ec52db3b381 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Fri, 26 Jul 2024 18:52:47 +0200 Subject: [PATCH] prepare instances page --- .../activity/dashboard/screen/Dashboard.kt | 3 +- .../activity/dashboard/screen/Instances.kt | 42 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt index 1622c3d..f04eb90 100644 --- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt +++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt @@ -130,6 +130,8 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) { } } + // TODO maybe reuse that from Instances? + val instance = JSONObject() instance.put("id", 234523) instance.put("machine_id", 1121323) @@ -140,7 +142,6 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) { instance.put("gpu_ram", 24564) instance.put("vmem_usage", 0.339843) - Column( modifier = Modifier.width(340.dp) ) { diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt index 9c4d2b4..e0505a8 100644 --- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt +++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt @@ -3,16 +3,26 @@ package eu.m724.vastapp.activity.dashboard.screen import android.widget.ProgressBar import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ContextualFlowRow +import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.IntrinsicSize +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Card import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview @@ -24,13 +34,35 @@ import org.json.JSONObject class Instances { } +@OptIn(ExperimentalLayoutApi::class) @Composable fun InstancesScreen(dashboardViewModel: DashboardViewModel) { - Column { + val uiState by dashboardViewModel.uiState.collectAsState() + // TODO actually get instances + + ContextualFlowRow( + modifier = Modifier + .fillMaxWidth() + .verticalScroll(rememberScrollState()), + itemCount = 10, + horizontalArrangement = Arrangement.Center + ) { + val instance = JSONObject() + instance.put("id", 234523) + instance.put("machine_id", 1121323) + instance.put("host_id", 5924) + instance.put("gpu_name", "RTX 4090") + instance.put("num_gpus", 2) + instance.put("gpu_util", 70) + instance.put("gpu_ram", 24564) + instance.put("vmem_usage", 0.339843) + + InstanceCard(instance = instance, modifier = Modifier.width(340.dp).padding(8.dp)) } } +// TODO maybe move this? @Composable fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) { val gpuUsage = instance.getInt("gpu_util") @@ -68,7 +100,9 @@ fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) { modifier = Modifier.fillMaxWidth(0.5f) ) { Column( - modifier = Modifier.fillMaxWidth().weight(1f) + modifier = Modifier + .fillMaxWidth() + .weight(1f) ) { Text(text = "GPU: $gpuUsage%", fontSize = 12.sp) LinearProgressIndicator( @@ -77,7 +111,9 @@ fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) { } Column( - modifier = Modifier.fillMaxWidth().weight(1f) + modifier = Modifier + .fillMaxWidth() + .weight(1f) ) { Text(text = "%.1f / %.1f G".format(vramGbUsed, vramGb), fontSize = 12.sp) LinearProgressIndicator(