prepare instances page

This commit is contained in:
Minecon724 2024-07-26 18:52:47 +02:00
parent fbde1a502b
commit 8d7268f194
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
2 changed files with 41 additions and 4 deletions

View file

@ -130,6 +130,8 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
} }
} }
// TODO maybe reuse that from Instances?
val instance = JSONObject() val instance = JSONObject()
instance.put("id", 234523) instance.put("id", 234523)
instance.put("machine_id", 1121323) instance.put("machine_id", 1121323)
@ -140,7 +142,6 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
instance.put("gpu_ram", 24564) instance.put("gpu_ram", 24564)
instance.put("vmem_usage", 0.339843) instance.put("vmem_usage", 0.339843)
Column( Column(
modifier = Modifier.width(340.dp) modifier = Modifier.width(340.dp)
) { ) {

View file

@ -3,16 +3,26 @@ package eu.m724.vastapp.activity.dashboard.screen
import android.widget.ProgressBar import android.widget.ProgressBar
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column 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.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width 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.Card
import androidx.compose.material3.LinearProgressIndicator import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
@ -24,13 +34,35 @@ import org.json.JSONObject
class Instances { class Instances {
} }
@OptIn(ExperimentalLayoutApi::class)
@Composable @Composable
fun InstancesScreen(dashboardViewModel: DashboardViewModel) { 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 @Composable
fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) { fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) {
val gpuUsage = instance.getInt("gpu_util") val gpuUsage = instance.getInt("gpu_util")
@ -68,7 +100,9 @@ fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) {
modifier = Modifier.fillMaxWidth(0.5f) modifier = Modifier.fillMaxWidth(0.5f)
) { ) {
Column( Column(
modifier = Modifier.fillMaxWidth().weight(1f) modifier = Modifier
.fillMaxWidth()
.weight(1f)
) { ) {
Text(text = "GPU: $gpuUsage%", fontSize = 12.sp) Text(text = "GPU: $gpuUsage%", fontSize = 12.sp)
LinearProgressIndicator( LinearProgressIndicator(
@ -77,7 +111,9 @@ fun InstanceCard(instance: JSONObject, modifier: Modifier = Modifier) {
} }
Column( Column(
modifier = Modifier.fillMaxWidth().weight(1f) modifier = Modifier
.fillMaxWidth()
.weight(1f)
) { ) {
Text(text = "%.1f / %.1f G".format(vramGbUsed, vramGb), fontSize = 12.sp) Text(text = "%.1f / %.1f G".format(vramGbUsed, vramGb), fontSize = 12.sp)
LinearProgressIndicator( LinearProgressIndicator(