Skip to content

Commit

Permalink
Merge pull request andras-adam#15 from NeoAren/translation
Browse files Browse the repository at this point in the history
Add string resources and translation
  • Loading branch information
tamaskr committed Oct 10, 2022
2 parents a48baef + f2415ad commit 2ae7e27
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 40 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/com/virtualtag/app/ui/components/Buttons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.virtualtag.app.R

@Composable
fun PrimaryButton(text: String, onClick: () -> Unit) {
Button(
onClick = { onClick() },
modifier = Modifier

.padding(top = 8.dp, bottom = 8.dp),
contentPadding = PaddingValues(all = 16.dp),
elevation = ButtonDefaults.elevation(defaultElevation = 2.dp)
Expand Down Expand Up @@ -69,7 +70,8 @@ fun ColorButton(colors: List<Color>, onColorSelected: (Color) -> Unit) {
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "Change card background color", color = MaterialTheme.colors.secondary
text = stringResource(R.string.color_button_text),
color = MaterialTheme.colors.secondary
)
Canvas(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun CardContainer(onClick: () -> Unit, enabled: Boolean, color: Color, children: @Composable () -> Unit) {
fun CardContainer(
onClick: () -> Unit,
enabled: Boolean,
color: Color,
children: @Composable () -> Unit
) {
Card(
elevation = 2.dp,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp


@Composable
fun ColorPickerDialog(
colorList: List<Color>,
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/com/virtualtag/app/ui/screens/AddScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.virtualtag.app.ui.screens

import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
Expand All @@ -11,18 +10,18 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import com.virtualtag.app.R
import com.virtualtag.app.data.ScanningViewModel
import com.virtualtag.app.data.toHex
import com.virtualtag.app.db.Card
import com.virtualtag.app.ui.components.CardContainer
import com.virtualtag.app.ui.components.ColorButton
import com.virtualtag.app.ui.components.PrimaryButton
import com.virtualtag.app.ui.components.SecondaryButton
import com.virtualtag.app.ui.theme.WhiteBG
import com.virtualtag.app.ui.theme.cardBackGroundColors
import com.virtualtag.app.utils.colorToString
import com.virtualtag.app.viewmodels.CardViewModel
Expand All @@ -49,14 +48,15 @@ fun AddScreen(
color = color
)
)
Toast.makeText(context, "Card added successfully!", Toast.LENGTH_SHORT).show()
Toast.makeText(context, context.getString(R.string.card_added_success), Toast.LENGTH_SHORT)
.show()
goHome()
}

Scaffold(
topBar = {
TopAppBar(
title = { Text("Add new card") },
title = { Text(context.getString(R.string.add_new_card)) },
navigationIcon = {
IconButton(onClick = goBack) {
Icon(
Expand Down Expand Up @@ -104,7 +104,7 @@ fun AddScreen(
tint = MaterialTheme.colors.secondary
)
Text(
"NFC tag scanned successfully",
stringResource(R.string.scan_success),
modifier = Modifier,
color = MaterialTheme.colors.secondary
)
Expand All @@ -116,7 +116,7 @@ fun AddScreen(
onValueChange = { newName ->
name = newName
},
label = { Text(text = "Name") },
label = { Text(stringResource(R.string.name)) },
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
Expand All @@ -134,7 +134,7 @@ fun AddScreen(
.weight(1f)
.padding(end = 4.dp)
) {
SecondaryButton(text = "Cancel", onClick = goHome)
SecondaryButton(text = stringResource(R.string.cancel), onClick = goHome)
}
Column(
Modifier
Expand All @@ -145,7 +145,7 @@ fun AddScreen(
if (name.text == "") {
return@PrimaryButton Toast.makeText(
context,
"Please set a name for your card",
context.getString(R.string.empty_name_error),
Toast.LENGTH_SHORT
).show()
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/virtualtag/app/ui/screens/CardScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.*
import androidx.compose.material.MaterialTheme.colors
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
Expand All @@ -22,7 +23,8 @@ fun CardScreen(
goBack: () -> Unit
) {
val card =
model.getCardById(id).observeAsState(Card(id = "0", name = "Unknown card", color = "red"))
model.getCardById(id)
.observeAsState(Card(id = "0", name = "Unknown card", color = "#fff8f8f8"))
Scaffold(
topBar = {
TopAppBar(
Expand All @@ -42,10 +44,10 @@ fun CardScreen(
modifier = Modifier
.padding(it)
.fillMaxSize()
.padding(8.dp), color = MaterialTheme.colors.background
.padding(8.dp), color = colors.background
) {
Column(modifier = Modifier.fillMaxWidth()) {
Text("View card details here")
Text("Card details - placeholder")
}
}
}
Expand Down
41 changes: 26 additions & 15 deletions app/src/main/java/com/virtualtag/app/ui/screens/EditScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,35 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.virtualtag.app.viewmodels.CardViewModel
import com.virtualtag.app.R

@Composable
fun EditScreen(model: CardViewModel, id: String, goBack: () -> Unit) {
Scaffold(
topBar = {
TopAppBar(
title = { Text("Edit $id") },
navigationIcon = { IconButton(onClick = goBack) { Icon(Icons.Filled.ArrowBack, null) } }
)
Scaffold(
topBar = {
TopAppBar(
title = { Text(stringResource(R.string.edit)) },
navigationIcon = {
IconButton(onClick = goBack) {
Icon(
Icons.Filled.ArrowBack,
null
)
}
}
)
}
) {
Surface(
modifier = Modifier
.padding(it)
.fillMaxSize()
) {
Column(modifier = Modifier.fillMaxWidth()) {
Text("Edit card details here - placeholder")
}
}
}
) {
Surface(modifier = Modifier
.padding(it)
.fillMaxSize()) {
Column(modifier = Modifier.fillMaxWidth()) {
Text("Edit card details here")
}
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/com/virtualtag/app/ui/screens/HomeScreen.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.virtualtag.app.ui.screens

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
Expand All @@ -12,13 +11,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.virtualtag.app.ui.components.CardContainer
import com.virtualtag.app.ui.components.Logo
import com.virtualtag.app.ui.components.PrimaryButton
import com.virtualtag.app.ui.theme.BlackBG
import com.virtualtag.app.utils.stringToColor
import com.virtualtag.app.viewmodels.CardViewModel
import com.virtualtag.app.R

@Composable
fun HomeScreen(model: CardViewModel, viewCard: (id: String) -> Unit, scanCard: () -> Unit) {
Expand Down Expand Up @@ -53,7 +54,7 @@ fun HomeScreen(model: CardViewModel, viewCard: (id: String) -> Unit, scanCard: (
}
}
}
PrimaryButton(text = "Scan new card", onClick = scanCard)
PrimaryButton(text = stringResource(R.string.scan_new_card), onClick = scanCard)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/virtualtag/app/ui/screens/ScanScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.virtualtag.app.data.ScanningViewModel
import com.virtualtag.app.ui.components.CardContainer
import com.virtualtag.app.ui.components.PrimaryButton
import com.virtualtag.app.ui.theme.WhiteBG
import com.virtualtag.app.R

@Composable
fun ScanScreen(scanningViewModel: ScanningViewModel, goBack: () -> Unit, addCard: () -> Unit) {
Expand All @@ -43,7 +43,7 @@ fun ScanScreen(scanningViewModel: ScanningViewModel, goBack: () -> Unit, addCard
Scaffold(
topBar = {
TopAppBar(
title = { Text("Scan") },
title = { Text(stringResource(R.string.scan_new_card)) },
navigationIcon = {
IconButton(onClick = goBack) {
Icon(
Expand Down Expand Up @@ -74,7 +74,7 @@ fun ScanScreen(scanningViewModel: ScanningViewModel, goBack: () -> Unit, addCard
) {
Spacer(Modifier.weight(1f))
Text(
"Ready to scan",
stringResource(R.string.ready_to_scan),
color = MaterialTheme.colors.secondary,
style = MaterialTheme.typography.h1,
)
Expand All @@ -86,13 +86,13 @@ fun ScanScreen(scanningViewModel: ScanningViewModel, goBack: () -> Unit, addCard
)
Spacer(Modifier.weight(2f))
Text(
"Hold your device near your NFC tag to scan",
stringResource(R.string.scan_description),
color = MaterialTheme.colors.secondary,
)
Spacer(Modifier.weight(2f))
}
}
PrimaryButton(text = "Cancel", onClick = goBack)
PrimaryButton(text = stringResource(R.string.cancel), onClick = goBack)
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="card_added_success">Kártya sikeresen hozzáadva!</string>
<string name="add_new_card">Új kártya hozzáadása</string>
<string name="scan_success">Kártya sikeresen beolvasva</string>
<string name="name">Név</string>
<string name="cancel">Mégse</string>
<string name="empty_name_error">Töltsd ki a név mezőt</string>
<string name="color_button_text">Háttér módosítása</string>
<string name="edit">Szerkesztés</string>
<string name="scan_new_card">Új kártya</string>
<string name="ready_to_scan">Készen áll a beolvasásra</string>
<string name="scan_description">Tartsd az eszközt az NFC olvasóhoz a beolvasáshoz</string>
</resources>
13 changes: 12 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<resources>
<string name="app_name">VirtualTag</string>
<string name="app_name" translatable="false">VirtualTag</string>
<string name="card_added_success">Card added successfully!</string>
<string name="add_new_card">Add new card</string>
<string name="scan_success">NFC tag scanned successfully</string>
<string name="name">Name</string>
<string name="cancel">Cancel</string>
<string name="empty_name_error">Please set a name for your card</string>
<string name="color_button_text">Change card background color</string>
<string name="edit">Edit card</string>
<string name="scan_new_card">Scan new card</string>
<string name="ready_to_scan">Ready to scan</string>
<string name="scan_description">Hold your device near your NFC tag to scan</string>
</resources>

0 comments on commit 2ae7e27

Please sign in to comment.