hide time card if no instances
This commit is contained in:
parent
bf240c4203
commit
2ead3c054a
1 changed files with 86 additions and 70 deletions
|
@ -72,34 +72,21 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
|
|||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
// balance card
|
||||
Card(
|
||||
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)
|
||||
)
|
||||
BalanceCard(balance = user.credit, balanceWarning = user.balanceThreshold)
|
||||
|
||||
// time card
|
||||
if (rentedInstances.isNotEmpty())
|
||||
RemainingTimeCard(remainingTime = remainingTime)
|
||||
|
||||
// instances
|
||||
InstancesCard(rentedInstancesCount = rentedInstances.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// time card
|
||||
@Composable
|
||||
fun RemainingTimeCard(remainingTime: Int) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.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(
|
||||
modifier = Modifier
|
||||
.padding(16.dp)
|
||||
|
@ -141,15 +160,12 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
|
|||
modifier = Modifier.width(12.dp)
|
||||
)
|
||||
Text(
|
||||
text = rentedInstances.size.toString(),
|
||||
text = rentedInstancesCount.toString(),
|
||||
fontSize = 22.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun balanceCardColor(balance: Double): Color {
|
||||
|
|
Loading…
Reference in a new issue