hide time card if no instances

This commit is contained in:
Minecon724 2024-08-08 13:19:32 +02:00
parent bf240c4203
commit 2ead3c054a
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -72,85 +72,101 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
) { ) {
// balance card // balance card
Card( BalanceCard(balance = user.credit, balanceWarning = user.balanceThreshold)
modifier = Modifier
.padding(16.dp),
colors = CardDefaults.cardColors(
containerColor = balanceCardColor(user.credit)
)
) {
Row(
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 = stringResource(id = R.string.balance)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = "$%.2f".format(user.credit),
fontSize = 22.sp,
color = balanceColor(user.credit, user.balanceThreshold)
)
}
}
// time card // time card
Card( if (rentedInstances.isNotEmpty())
modifier = Modifier RemainingTimeCard(remainingTime = remainingTime)
.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.baseline_access_time_filled_24),
contentDescription = stringResource(id = R.string.time_left)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = formatTime(remainingTime),
fontSize = 22.sp
)
}
}
// instances // instances
Card( InstancesCard(rentedInstancesCount = rentedInstances.size)
modifier = Modifier
.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 = stringResource(id = R.string.rented_instances)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = rentedInstances.size.toString(),
fontSize = 22.sp
)
}
}
} }
} }
} }
} }
@Composable
fun RemainingTimeCard(remainingTime: Int) {
Card(
modifier = Modifier
.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.baseline_access_time_filled_24),
contentDescription = stringResource(id = R.string.time_left)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = formatTime(remainingTime),
fontSize = 22.sp
)
}
}
}
@Composable
fun BalanceCard(balance: Double, balanceWarning: Double) {
Card(
modifier = Modifier
.padding(16.dp),
colors = CardDefaults.cardColors(
containerColor = balanceCardColor(balance)
)
) {
Row(
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 = stringResource(id = R.string.balance)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = "$%.2f".format(balance),
fontSize = 22.sp,
color = balanceColor(balance, balanceWarning)
)
}
}
}
@Composable
fun InstancesCard(rentedInstancesCount: Int) {
Card(
modifier = Modifier
.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 = stringResource(id = R.string.rented_instances)
)
Spacer(
modifier = Modifier.width(12.dp)
)
Text(
text = rentedInstancesCount.toString(),
fontSize = 22.sp
)
}
}
}
@Composable @Composable
fun balanceCardColor(balance: Double): Color { fun balanceCardColor(balance: Double): Color {
return if (balance > 0) Color.Unspecified else MaterialTheme.colorScheme.errorContainer return if (balance > 0) Color.Unspecified else MaterialTheme.colorScheme.errorContainer