diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Billing.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Billing.kt
index 1b15344..d800216 100644
--- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Billing.kt
+++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Billing.kt
@@ -22,6 +22,7 @@ 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
@@ -45,12 +46,16 @@ 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 = "Balance"
+ contentDescription = stringResource(id = R.string.balance)
)
Spacer(modifier = Modifier
.fillMaxWidth()
diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt
index 750923c..0593842 100644
--- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt
+++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Dashboard.kt
@@ -32,10 +32,12 @@ 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
import eu.m724.vastapp.activity.dashboard.DashboardViewModel
+import kotlin.math.min
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) // for pullRefresh
@Composable
@@ -62,7 +64,10 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
.height(100.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center) {
- Text("Hello ${user.username}!", fontSize = 28.sp)
+ Text(
+ text = stringResource(id = R.string.greeting, user.username),
+ fontSize = 28.sp
+ )
}
FlowRow {
@@ -82,7 +87,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_monetization_on_24),
- contentDescription = "Balance"
+ contentDescription = stringResource(id = R.string.balance)
)
Spacer(
modifier = Modifier
@@ -110,7 +115,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.baseline_access_time_filled_24),
- contentDescription = "Remaining time"
+ contentDescription = stringResource(id = R.string.time_left)
)
Spacer(
modifier = Modifier
@@ -137,7 +142,7 @@ fun DashboardScreen(dashboardViewModel: DashboardViewModel) {
Icon(
modifier = Modifier.size(24.dp),
painter = painterResource(id = R.drawable.server_solid),
- contentDescription = "Rented"
+ contentDescription = stringResource(id = R.string.rented_instances)
)
Spacer(modifier = Modifier
.fillMaxWidth()
@@ -164,19 +169,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 "0.00m"
+ if (seconds <= 0)
+ return stringResource(id = R.string.time_minutes_short, 0)
val minutes: Double = seconds / 60.0
- if (minutes < 60) {
- return "%.2fm".format(minutes)
- }
+ if (minutes < 60)
+ return stringResource(id = R.string.time_minutes_short, minutes)
val hours: Double = minutes / 60
- if (hours < 24) {
- return "%.2fh".format(hours)
- }
+ if (hours < 24)
+ return stringResource(id = R.string.time_hours_short, hours)
val days: Double = hours / 24
- return "%.2fd".format(days)
+ return stringResource(id = R.string.time_days_short, days)
}
\ No newline at end of file
diff --git a/app/src/main/java/eu/m724/vastapp/activity/login/LoginActivity.kt b/app/src/main/java/eu/m724/vastapp/activity/login/LoginActivity.kt
index 8374045..39eb214 100644
--- a/app/src/main/java/eu/m724/vastapp/activity/login/LoginActivity.kt
+++ b/app/src/main/java/eu/m724/vastapp/activity/login/LoginActivity.kt
@@ -57,12 +57,14 @@ 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
@@ -147,7 +149,9 @@ 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
) {
@@ -156,7 +160,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
enabled = isIdle,
value = apiKey,
onValueChange = { apiKey = it },
- label = { Text(text = "API key") },
+ label = { Text(text = stringResource(id = R.string.api_key)) },
visualTransformation = PasswordVisualTransformation(),
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Password),
textStyle = if (uiState is LoginUiState.Success) rainbowTextStyle() else LocalTextStyle.current,
@@ -171,7 +175,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
advancedOpen = !advancedOpen
}
) {
- Text("Advanced options")
+ Text(text = stringResource(id = R.string.advanced_options))
Icon(
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = null,
@@ -188,7 +192,7 @@ fun LoginApp(loginViewModel: LoginViewModel) {
if (uiState is LoginUiState.Loading) {
CircularProgressIndicator()
} else {
- Text("Log in")
+ Text(text = stringResource(id = R.string.btn_login))
}
}
}
@@ -213,13 +217,14 @@ 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 { mutableStateOf("here's a checkbox for you") }
+ var checkboxLabel by rememberSaveable { mutableIntStateOf(R.string.login_checkbox) }
var mathPassing by rememberSaveable { mutableStateOf(true) }
val clickMessages = mapOf(
- 20 to "having fun?"
+ 20 to R.string.login_checkbox_20
)
Column(
@@ -240,17 +245,17 @@ fun AdvancedOptions() { // TODO put this in viewmodel
clicks++
if (clicks in clickMessages) {
- checkboxLabel = clickMessages[clicks].toString()
+ checkboxLabel = clickMessages[clicks]!!
}
}
)
- Text(checkboxLabel)
+ Text(text = stringResource(id = checkboxLabel))
}
AnimatedVisibility(visible = mathPassing) {
MathProblem(onFail = {
mathPassing = false
- checkboxLabel = "checkbox is angry"
+ checkboxLabel = R.string.login_checkbox_angry
}, onPass = {
checked = !checked
})
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b1049e8..f5a746d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -6,4 +6,17 @@
Billing
Instances
Help
+ Balance
+ Hello %1$s!
+ Time left
+ Rented
+ %1$.2fm
+ %1$.2fh
+ %1$.2fd
+ API Key
+ Advanced options
+ Log in
+ here\'s a checkbox for you
+ having fun?
+ checkbox is angry
\ No newline at end of file