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,34 +72,21 @@ 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
if (rentedInstances.isNotEmpty())
RemainingTimeCard(remainingTime = remainingTime)
// instances
InstancesCard(rentedInstancesCount = rentedInstances.size)
}
}
}
}
@Composable
fun RemainingTimeCard(remainingTime: Int) {
Card( Card(
modifier = Modifier modifier = Modifier
.padding(16.dp) .padding(16.dp)
@ -122,8 +109,40 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
) )
} }
} }
}
// instances @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( Card(
modifier = Modifier modifier = Modifier
.padding(16.dp) .padding(16.dp)
@ -141,14 +160,11 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
modifier = Modifier.width(12.dp) modifier = Modifier.width(12.dp)
) )
Text( Text(
text = rentedInstances.size.toString(), text = rentedInstancesCount.toString(),
fontSize = 22.sp fontSize = 22.sp
) )
} }
} }
}
}
}
} }
@Composable @Composable