Compare commits

..

No commits in common. "37475c83d5048603492082701a5197aeb93c0b08" and "8d95c3271cd62213171c29e4085787f2093c2234" have entirely different histories.

4 changed files with 42 additions and 63 deletions

View file

@ -22,7 +22,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import eu.m724.vastapp.R
@ -46,16 +45,12 @@ fun BillingScreen(dashboardViewModel: DashboardViewModel) {
modifier = Modifier.width(160.dp)
) {
Row(
modifier = Modifier
.padding(16.dp, 8.dp)
.height(IntrinsicSize.Min)
modifier = Modifier.padding(16.dp, 8.dp).height(IntrinsicSize.Min)
) {
Icon(
modifier = Modifier
.fillMaxHeight()
.aspectRatio(1f),
modifier = Modifier.fillMaxHeight().aspectRatio(1f),
painter = painterResource(id = R.drawable.baseline_monetization_on_24),
contentDescription = stringResource(id = R.string.balance)
contentDescription = "Balance"
)
Spacer(modifier = Modifier
.fillMaxWidth()

View file

@ -32,7 +32,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import eu.m724.vastapp.R
@ -44,7 +43,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
val uiState by dashboardViewModel.uiState.collectAsState()
val user by remember(uiState) { derivedStateOf { uiState.user } }
val remainingTime by rememberSaveable { mutableIntStateOf(6000000) }
val remainingTime by rememberSaveable { mutableIntStateOf(0) }
val scrollState = rememberScrollState()
@ -63,18 +62,14 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
.height(100.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center) {
Text(
text = stringResource(id = R.string.greeting, user.username),
fontSize = 28.sp
)
Text("Hello ${user.username}!", fontSize = 28.sp)
}
FlowRow(
horizontalArrangement = Arrangement.Center
) {
FlowRow {
// balance card
Card(
modifier = Modifier
.width(160.dp)
.padding(16.dp),
colors = CardDefaults.cardColors(
containerColor = balanceCardColor(user.credit)
@ -87,10 +82,12 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_monetization_on_24),
contentDescription = stringResource(id = R.string.balance)
contentDescription = "Balance"
)
Spacer(
modifier = Modifier.width(12.dp)
modifier = Modifier
.fillMaxWidth()
.weight(1f)
)
Text(
text = "$%.2f".format(user.credit),
@ -103,6 +100,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
// time card
Card(
modifier = Modifier
.width(160.dp)
.padding(16.dp)
) {
Row(
@ -112,10 +110,12 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_access_time_filled_24),
contentDescription = stringResource(id = R.string.time_left)
contentDescription = "Remaining time"
)
Spacer(
modifier = Modifier.width(12.dp)
modifier = Modifier
.fillMaxWidth()
.weight(1f)
)
Text(
text = formatTime(remainingTime),
@ -127,6 +127,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
// instances
Card(
modifier = Modifier
.width(160.dp)
.padding(16.dp)
) {
Row(
@ -136,10 +137,11 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.server_solid),
contentDescription = stringResource(id = R.string.rented_instances)
contentDescription = "Rented"
)
Spacer(
modifier = Modifier.width(12.dp)
Spacer(modifier = Modifier
.fillMaxWidth()
.weight(1f)
)
Text(
text = "4",
@ -162,19 +164,19 @@ fun balanceColor(balance: Double, warningThreshold: Double): Color {
return if (balance > warningThreshold) MaterialTheme.colorScheme.secondary else MaterialTheme.colorScheme.error
}
@Composable
fun formatTime(seconds: Int): String {
if (seconds <= 0)
return stringResource(id = R.string.time_minutes_short, 0.0)
if (seconds <= 0) return "0.00m"
val minutes: Double = seconds / 60.0
if (minutes < 60)
return stringResource(id = R.string.time_minutes_short, minutes)
if (minutes < 60) {
return "%.2fm".format(minutes)
}
val hours: Double = minutes / 60
if (hours < 24)
return stringResource(id = R.string.time_hours_short, hours)
if (hours < 24) {
return "%.2fh".format(hours)
}
val days: Double = hours / 24
return stringResource(id = R.string.time_days_short, days)
return "%.2fd".format(days)
}

View file

@ -57,14 +57,12 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.lifecycle.lifecycleScope
import eu.m724.vastapp.BuildConfig
import eu.m724.vastapp.R
import eu.m724.vastapp.activity.dashboard.DashboardActivity
import eu.m724.vastapp.ui.theme.VastappTheme
import eu.m724.vastapp.vastai.data.User
@ -149,9 +147,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
Column(
modifier = Modifier
.width(300.dp)
.animateContentSize(spring(stiffness = Spring.StiffnessMedium)), // TODO double animation
modifier = Modifier.width(300.dp).animateContentSize(spring(stiffness = Spring.StiffnessMedium)), // TODO double animation
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
@ -160,7 +156,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
enabled = isIdle,
value = apiKey,
onValueChange = { apiKey = it },
label = { Text(text = stringResource(id = R.string.api_key)) },
label = { Text(text = "API key") },
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
textStyle = if (uiState is LoginUiState.Success) rainbowTextStyle() else LocalTextStyle.current,
@ -175,7 +171,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
advancedOpen = !advancedOpen
}
) {
Text(text = stringResource(id = R.string.advanced_options))
Text("Advanced options")
Icon(
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = null,
@ -192,7 +188,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
if (uiState is LoginUiState.Loading) {
CircularProgressIndicator()
} else {
Text(text = stringResource(id = R.string.btn_login))
Text("Log in")
}
}
}
@ -217,14 +213,13 @@ fun rainbowTextStyle(): TextStyle {
@Composable
fun AdvancedOptions() { // TODO put this in viewmodel
var checked by rememberSaveable { mutableStateOf(true) }
var clicks by rememberSaveable { mutableIntStateOf(0) }
var checkboxLabel by rememberSaveable { mutableIntStateOf(R.string.login_checkbox) }
var checkboxLabel by rememberSaveable { mutableStateOf("here's a checkbox for you") }
var mathPassing by rememberSaveable { mutableStateOf(true) }
val clickMessages = mapOf(
20 to R.string.login_checkbox_20
20 to "having fun?"
)
Column(
@ -232,7 +227,7 @@ fun AdvancedOptions() { // TODO put this in viewmodel
.fillMaxWidth()
.padding(horizontal = 12.dp)
) {
Text(text = stringResource(id = R.string.no_options))
Text("none yet sorry")
Row(
verticalAlignment = Alignment.CenterVertically
@ -245,17 +240,17 @@ fun AdvancedOptions() { // TODO put this in viewmodel
clicks++
if (clicks in clickMessages) {
checkboxLabel = clickMessages[clicks]!!
checkboxLabel = clickMessages[clicks].toString()
}
}
)
Text(text = stringResource(id = checkboxLabel))
Text(checkboxLabel)
}
AnimatedVisibility(visible = mathPassing) {
MathProblem(onFail = {
mathPassing = false
checkboxLabel = R.string.login_checkbox_angry
checkboxLabel = "checkbox is angry"
}, onPass = {
checked = !checked
})

View file

@ -1,23 +1,10 @@
<resources>
<string name="app_name" translatable="false">vast.app</string>
<string name="app_name">vast.app</string>
<string name="title_activity_dashboard">Dashboard</string>
<string name="title_activity_login" translatable="false">vast.app</string>
<string name="title_activity_login">Login</string>
<string name="dashboard">Dashboard</string>
<string name="nav_dashboard">Dashboard</string>
<string name="nav_billing">Billing</string>
<string name="nav_instances">Instances</string>
<string name="nav_help">Help</string>
<string name="balance">Balance</string>
<string name="greeting">Hello %1$s!</string>
<string name="time_left">Time left</string>
<string name="rented_instances">Rented</string>
<string name="time_minutes_short">%1$.2fm</string>
<string name="time_hours_short">%1$.2fh</string>
<string name="time_days_short">%1$.2fd</string>
<string name="api_key">API Key</string>
<string name="advanced_options">Advanced options</string>
<string name="btn_login">Log in</string>
<string name="login_checkbox">here\'s a checkbox for you</string>
<string name="login_checkbox_20">having fun?</string>
<string name="login_checkbox_angry">checkbox is angry</string>
<string name="no_options">none yet sorry</string>
</resources>