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

View file

@ -32,7 +32,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import eu.m724.vastapp.R import eu.m724.vastapp.R
@ -44,7 +43,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
val uiState by dashboardViewModel.uiState.collectAsState() val uiState by dashboardViewModel.uiState.collectAsState()
val user by remember(uiState) { derivedStateOf { uiState.user } } val user by remember(uiState) { derivedStateOf { uiState.user } }
val remainingTime by rememberSaveable { mutableIntStateOf(6000000) } val remainingTime by rememberSaveable { mutableIntStateOf(0) }
val scrollState = rememberScrollState() val scrollState = rememberScrollState()
@ -63,18 +62,14 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
.height(100.dp), .height(100.dp),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center) { verticalArrangement = Arrangement.Center) {
Text( Text("Hello ${user.username}!", fontSize = 28.sp)
text = stringResource(id = R.string.greeting, user.username),
fontSize = 28.sp
)
} }
FlowRow( FlowRow {
horizontalArrangement = Arrangement.Center
) {
// balance card // balance card
Card( Card(
modifier = Modifier modifier = Modifier
.width(160.dp)
.padding(16.dp), .padding(16.dp),
colors = CardDefaults.cardColors( colors = CardDefaults.cardColors(
containerColor = balanceCardColor(user.credit) containerColor = balanceCardColor(user.credit)
@ -87,10 +82,12 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon( Icon(
modifier = Modifier.size(24.dp), modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_monetization_on_24), painter = painterResource(id = R.drawable.baseline_monetization_on_24),
contentDescription = stringResource(id = R.string.balance) contentDescription = "Balance"
) )
Spacer( Spacer(
modifier = Modifier.width(12.dp) modifier = Modifier
.fillMaxWidth()
.weight(1f)
) )
Text( Text(
text = "$%.2f".format(user.credit), text = "$%.2f".format(user.credit),
@ -103,6 +100,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
// time card // time card
Card( Card(
modifier = Modifier modifier = Modifier
.width(160.dp)
.padding(16.dp) .padding(16.dp)
) { ) {
Row( Row(
@ -112,10 +110,12 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon( Icon(
modifier = Modifier.size(24.dp), modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_access_time_filled_24), painter = painterResource(id = R.drawable.baseline_access_time_filled_24),
contentDescription = stringResource(id = R.string.time_left) contentDescription = "Remaining time"
) )
Spacer( Spacer(
modifier = Modifier.width(12.dp) modifier = Modifier
.fillMaxWidth()
.weight(1f)
) )
Text( Text(
text = formatTime(remainingTime), text = formatTime(remainingTime),
@ -127,6 +127,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
// instances // instances
Card( Card(
modifier = Modifier modifier = Modifier
.width(160.dp)
.padding(16.dp) .padding(16.dp)
) { ) {
Row( Row(
@ -136,10 +137,11 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon( Icon(
modifier = Modifier.size(24.dp), modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.server_solid), painter = painterResource(id = R.drawable.server_solid),
contentDescription = stringResource(id = R.string.rented_instances) contentDescription = "Rented"
) )
Spacer( Spacer(modifier = Modifier
modifier = Modifier.width(12.dp) .fillMaxWidth()
.weight(1f)
) )
Text( Text(
text = "4", text = "4",
@ -162,19 +164,19 @@ fun balanceColor(balance: Double, warningThreshold: Double): Color {
return if (balance > warningThreshold) MaterialTheme.colorScheme.secondary else MaterialTheme.colorScheme.error return if (balance > warningThreshold) MaterialTheme.colorScheme.secondary else MaterialTheme.colorScheme.error
} }
@Composable
fun formatTime(seconds: Int): String { fun formatTime(seconds: Int): String {
if (seconds <= 0) if (seconds <= 0) return "0.00m"
return stringResource(id = R.string.time_minutes_short, 0.0)
val minutes: Double = seconds / 60.0 val minutes: Double = seconds / 60.0
if (minutes < 60) if (minutes < 60) {
return stringResource(id = R.string.time_minutes_short, minutes) return "%.2fm".format(minutes)
}
val hours: Double = minutes / 60 val hours: Double = minutes / 60
if (hours < 24) if (hours < 24) {
return stringResource(id = R.string.time_hours_short, hours) return "%.2fh".format(hours)
}
val days: Double = hours / 24 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.draw.rotate
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import eu.m724.vastapp.BuildConfig import eu.m724.vastapp.BuildConfig
import eu.m724.vastapp.R
import eu.m724.vastapp.activity.dashboard.DashboardActivity import eu.m724.vastapp.activity.dashboard.DashboardActivity
import eu.m724.vastapp.ui.theme.VastappTheme import eu.m724.vastapp.ui.theme.VastappTheme
import eu.m724.vastapp.vastai.data.User import eu.m724.vastapp.vastai.data.User
@ -149,9 +147,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
Column( Column(
modifier = Modifier modifier = Modifier.width(300.dp).animateContentSize(spring(stiffness = Spring.StiffnessMedium)), // TODO double animation
.width(300.dp)
.animateContentSize(spring(stiffness = Spring.StiffnessMedium)), // TODO double animation
verticalArrangement = Arrangement.Center, verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
@ -160,7 +156,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
enabled = isIdle, enabled = isIdle,
value = apiKey, value = apiKey,
onValueChange = { apiKey = it }, onValueChange = { apiKey = it },
label = { Text(text = stringResource(id = R.string.api_key)) }, label = { Text(text = "API key") },
visualTransformation = PasswordVisualTransformation(), visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password), keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
textStyle = if (uiState is LoginUiState.Success) rainbowTextStyle() else LocalTextStyle.current, textStyle = if (uiState is LoginUiState.Success) rainbowTextStyle() else LocalTextStyle.current,
@ -175,7 +171,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
advancedOpen = !advancedOpen advancedOpen = !advancedOpen
} }
) { ) {
Text(text = stringResource(id = R.string.advanced_options)) Text("Advanced options")
Icon( Icon(
imageVector = Icons.Filled.KeyboardArrowDown, imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = null, contentDescription = null,
@ -192,7 +188,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
if (uiState is LoginUiState.Loading) { if (uiState is LoginUiState.Loading) {
CircularProgressIndicator() CircularProgressIndicator()
} else { } else {
Text(text = stringResource(id = R.string.btn_login)) Text("Log in")
} }
} }
} }
@ -217,14 +213,13 @@ fun rainbowTextStyle(): TextStyle {
@Composable @Composable
fun AdvancedOptions() { // TODO put this in viewmodel fun AdvancedOptions() { // TODO put this in viewmodel
var checked by rememberSaveable { mutableStateOf(true) } var checked by rememberSaveable { mutableStateOf(true) }
var clicks by rememberSaveable { mutableIntStateOf(0) } 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) } var mathPassing by rememberSaveable { mutableStateOf(true) }
val clickMessages = mapOf( val clickMessages = mapOf(
20 to R.string.login_checkbox_20 20 to "having fun?"
) )
Column( Column(
@ -232,7 +227,7 @@ fun AdvancedOptions() { // TODO put this in viewmodel
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = 12.dp) .padding(horizontal = 12.dp)
) { ) {
Text(text = stringResource(id = R.string.no_options)) Text("none yet sorry")
Row( Row(
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
@ -245,17 +240,17 @@ fun AdvancedOptions() { // TODO put this in viewmodel
clicks++ clicks++
if (clicks in clickMessages) { if (clicks in clickMessages) {
checkboxLabel = clickMessages[clicks]!! checkboxLabel = clickMessages[clicks].toString()
} }
} }
) )
Text(text = stringResource(id = checkboxLabel)) Text(checkboxLabel)
} }
AnimatedVisibility(visible = mathPassing) { AnimatedVisibility(visible = mathPassing) {
MathProblem(onFail = { MathProblem(onFail = {
mathPassing = false mathPassing = false
checkboxLabel = R.string.login_checkbox_angry checkboxLabel = "checkbox is angry"
}, onPass = { }, onPass = {
checked = !checked checked = !checked
}) })

View file

@ -1,23 +1,10 @@
<resources> <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_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_dashboard">Dashboard</string>
<string name="nav_billing">Billing</string> <string name="nav_billing">Billing</string>
<string name="nav_instances">Instances</string> <string name="nav_instances">Instances</string>
<string name="nav_help">Help</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> </resources>