From 2ba20d415f8d21bb1dacf6144b5df7deebbb47ac Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sat, 27 Jul 2024 15:55:06 +0200 Subject: [PATCH] add instances to dashboard and change arrangement --- .../activity/dashboard/screen/Dashboard.kt | 78 +++++++++++-------- 1 file changed, 47 insertions(+), 31 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 101a1e9..465e487 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 @@ -2,11 +2,17 @@ package eu.m724.vastapp.activity.dashboard.screen import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowRow +import androidx.compose.foundation.layout.IntrinsicSize import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxHeight 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.rememberScrollState import androidx.compose.foundation.verticalScroll @@ -35,7 +41,7 @@ import eu.m724.vastapp.R import eu.m724.vastapp.activity.dashboard.DashboardViewModel import org.json.JSONObject -@OptIn(ExperimentalMaterial3Api::class) // for pullRefresh +@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) // for pullRefresh @Composable fun DashboardScreen(dashboardViewModel: DashboardViewModel) { val uiState by dashboardViewModel.uiState.collectAsState() @@ -63,29 +69,29 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) { Text("Hello ${user.username}!", fontSize = 28.sp) } - Row( - modifier = Modifier.width(340.dp) - ) { + FlowRow { + // balance card Card( modifier = Modifier - .fillMaxWidth() - .padding(16.dp) - .weight(1f), + .width(160.dp) + .padding(16.dp), colors = CardDefaults.cardColors( containerColor = balanceCardColor(user.credit) ) ) { Row( - modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), + modifier = Modifier.padding(16.dp, 8.dp), verticalAlignment = Alignment.CenterVertically ) { Icon( + modifier = Modifier.size(24.dp), painter = painterResource(id = R.drawable.baseline_monetization_on_24), contentDescription = "Balance" ) - Spacer(modifier = Modifier - .fillMaxWidth() - .weight(1f) + Spacer( + modifier = Modifier + .fillMaxWidth() + .weight(1f) ) Text( text = "$%.2f".format(user.credit), @@ -94,17 +100,19 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) { ) } } + + // time card Card( modifier = Modifier - .fillMaxWidth() + .width(160.dp) .padding(16.dp) - .weight(1f), ) { Row( - modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp), + modifier = Modifier.padding(16.dp, 8.dp), verticalAlignment = Alignment.CenterVertically ) { Icon( + modifier = Modifier.size(24.dp), painter = painterResource(id = R.drawable.baseline_access_time_filled_24), contentDescription = "Remaining time" ) @@ -119,24 +127,32 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) { ) } } - } - // TODO maybe reuse that from Instances? - - 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) - - Column( - modifier = Modifier.width(340.dp) - ) { - InstanceCard(instance = instance, modifier = Modifier.padding(16.dp)) + // instances + Card( + modifier = Modifier + .width(160.dp) + .padding(16.dp) + ) { + Row( + modifier = Modifier.padding(16.dp, 8.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + modifier = Modifier.size(24.dp), + painter = painterResource(id = R.drawable.server_solid), + contentDescription = "Rented" + ) + Spacer(modifier = Modifier + .fillMaxWidth() + .weight(1f) + ) + Text( + text = "4", + fontSize = 22.sp + ) + } + } } } }