make things translatable
This commit is contained in:
parent
8bdd22f783
commit
eeb4125336
4 changed files with 52 additions and 24 deletions
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -6,4 +6,17 @@
|
|||
<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>
|
||||
</resources>
|
Loading…
Reference in a new issue