Skip to content

Commit

Permalink
locale: now 100% of the app is translated to Russian, also some minor…
Browse files Browse the repository at this point in the history
… fixes to UI
  • Loading branch information
bulkabuka committed May 15, 2024
1 parent f2dcc2d commit c207892
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fun WelcomeScreen(navController: NavController) {
UnorderedList(stringResource(R.string.create_edit_remove_task_lists))
UnorderedList(stringResource(R.string.add_delete_edit_tasks_from_your_lists))
UnorderedList(stringResource(R.string.add_tags_and_due_dates))
UnorderedList(stringResource(R.string.create_reminders))
}
}
}
Expand Down
57 changes: 23 additions & 34 deletions app/src/main/java/org/leftbrained/uptaskapp/StatsActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.leftbrained.uptaskapp

import android.app.Activity
import android.content.Context
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand All @@ -13,11 +12,9 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.KeyboardArrowLeft
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowLeft
import androidx.compose.material3.Button
import androidx.compose.material3.DateRangePicker
import androidx.compose.material3.DateRangePickerState
import androidx.compose.material3.DisplayMode
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -33,23 +30,15 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime
import org.jetbrains.exposed.sql.and
import org.jetbrains.exposed.sql.transactions.transaction
import org.leftbrained.uptaskapp.classes.Stats
import org.leftbrained.uptaskapp.db.UptaskDb
import org.leftbrained.uptaskapp.db.UserTask

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand All @@ -59,14 +48,14 @@ fun StatsActivity(navController: NavController, userId: Int) {
var currentStats by remember { mutableStateOf(Stats()) }
Scaffold(
topBar = {
TopAppBar(title = { Text("Stats") }, navigationIcon = {
TopAppBar(title = { Text(stringResource(R.string.stats)) }, navigationIcon = {
IconButton(
onClick = {
navController.navigate("taskList/$userId")
}
) {
Icon(
imageVector = Icons.Rounded.KeyboardArrowLeft,
imageVector = Icons.AutoMirrored.Rounded.KeyboardArrowLeft,
contentDescription = "Back icon"
)
}
Expand Down Expand Up @@ -111,26 +100,26 @@ fun StatsActivity(navController: NavController, userId: Int) {
},
modifier = Modifier.padding(8.dp)
) {
Text("Apply")
Text(stringResource(R.string.apply))
}
Column(Modifier.padding(16.dp)) {
Text(
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth(),
text = stringResource(R.string.stats_period),
style = MaterialTheme.typography.titleLarge
)
Text(
stringResource(R.string.total_tasks_added, currentStats.totalTasks)
)
Text(
stringResource(R.string.total_tasks_completed, currentStats.completedTasks)
)
Text(
stringResource(R.string.total_tasks_undone, currentStats.undoneTasks)
)
}

Text(
textAlign = TextAlign.Center,
modifier = Modifier
.padding(8.dp)
.fillMaxWidth(),
text = "Stats for the period",
style = MaterialTheme.typography.titleLarge
)
Text(
"Total tasks added: ${currentStats.totalTasks}"
)
Text(
"Total tasks completed: ${currentStats.completedTasks}"
)
Text(
"Total tasks undone: ${currentStats.undoneTasks}"
)
}
}
}
119 changes: 61 additions & 58 deletions app/src/main/java/org/leftbrained/uptaskapp/UserActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import android.content.Context
import android.widget.Toast
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.KeyboardArrowLeft
import androidx.compose.material.icons.automirrored.rounded.KeyboardArrowLeft
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
Expand All @@ -27,11 +28,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import org.jetbrains.exposed.sql.deleteAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.leftbrained.uptaskapp.db.UptaskDb
Expand All @@ -44,9 +44,10 @@ fun UserActivity(navController: NavController, userId: Int) {
connectToDb()
val activity = LocalContext.current as Activity
val sharedPref = activity.getPreferences(Context.MODE_PRIVATE)
val context = LocalContext.current
val userName = transaction {
val user = User.findById(userId)
user?.login ?: "No Login"
user?.login ?: context.getString(R.string.no_login)
}
var userNameEdit by remember { mutableStateOf(userName) }
var password by remember { mutableStateOf("") }
Expand All @@ -56,8 +57,14 @@ fun UserActivity(navController: NavController, userId: Int) {
TopAppBar(
title = {
Column {
Text("Uptask", style = MaterialTheme.typography.titleLarge)
Text(text = "Profile", style = MaterialTheme.typography.labelMedium)
Text(
text = stringResource(R.string.app_name),
style = MaterialTheme.typography.titleLarge
)
Text(
text = stringResource(R.string.profile),
style = MaterialTheme.typography.labelMedium
)
}
},
navigationIcon = {
Expand All @@ -67,7 +74,7 @@ fun UserActivity(navController: NavController, userId: Int) {
}
) {
Icon(
imageVector = Icons.Rounded.KeyboardArrowLeft,
imageVector = Icons.AutoMirrored.Rounded.KeyboardArrowLeft,
contentDescription = "Back icon"
)
}
Expand All @@ -86,85 +93,81 @@ fun UserActivity(navController: NavController, userId: Int) {
modifier = Modifier.padding(24.dp)
) {
Text(
"Here you can change your profile information",
stringResource(R.string.change_profile_info),
textAlign = TextAlign.Center,
modifier = Modifier.fillMaxWidth()
)
OutlinedTextField(
value = userNameEdit,
onValueChange = { userNameEdit = it },
label = { Text("Login") }
label = { Text(stringResource(R.string.login)) }
)
OutlinedTextField(
value = currentPass,
onValueChange = { currentPass = it },
label = { Text("Current Password") }
label = { Text(stringResource(R.string.current_password)) }
)
OutlinedTextField(
value = password,
onValueChange = { password = it },
label = { Text("New Password") }
label = { Text(stringResource(R.string.new_password)) }
)
Button(
onClick = {
transaction {
val user = User.findById(userId)
println(
"User: ${user?.login}, ${user?.password}, $currentPass, $password"
)
if (user?.password == currentPass) {
if (password.isNotEmpty() && password != currentPass && userName.isNotEmpty()) {
user.login = userNameEdit
user.password = password
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
Button(
onClick = {
transaction {
val user = User.findById(userId)
println(
"User: ${user?.login}, ${user?.password}, $currentPass, $password"
)
if (user?.password == currentPass) {
if (password.isNotEmpty() && password != currentPass && userName.isNotEmpty()) {
user.login = userNameEdit
user.password = password
} else {
Toast.makeText(
navController.context,
context.getString(R.string.fill_all_fields_correctly),
Toast.LENGTH_SHORT
).show()
}
} else {
Toast.makeText(
navController.context,
"Please fill all fields correctly",
context.getString(R.string.current_password_is_incorrect),
Toast.LENGTH_SHORT
).show()
}
} else {
Toast.makeText(
navController.context,
"Current password is incorrect",
Toast.LENGTH_SHORT
).show()
}
}
) {
Text(stringResource(R.string.save))
}
) {
Text("Save")
}
Button(
onClick = {
transaction {
UptaskDb.Users.deleteAll()
UptaskDb.UserTasks.deleteAll()
UptaskDb.TaskLists.deleteAll()
UptaskDb.TaskTags.deleteAll()
UptaskDb.Logs.deleteAll()
}
Toast.makeText(
navController.context,
"Database cleared. You will be logged out.",
Toast.LENGTH_SHORT
).show()
with(sharedPref.edit()) {
putString("user", "0")
apply()
Button(
onClick = {
transaction {
UptaskDb.Users.deleteAll()
UptaskDb.UserTasks.deleteAll()
UptaskDb.TaskLists.deleteAll()
UptaskDb.TaskTags.deleteAll()
UptaskDb.Logs.deleteAll()
}
Toast.makeText(
navController.context,
context.getString(R.string.database_cleared_output),
Toast.LENGTH_SHORT
).show()
with(sharedPref.edit()) {
putString("user", "0")
apply()
}
navController.navigate("auth")
}
navController.navigate("auth")
) {
Text(stringResource(R.string.clear_database))
}
) {
Text("Clear database")
}
}
}
}
}

@Preview(device = "id:pixel_8_pro", showSystemUi = true, showBackground = true)
@Composable
fun UserActivityPreview() {
UserActivity(rememberNavController(), 1)
}
10 changes: 5 additions & 5 deletions app/src/main/java/org/leftbrained/uptaskapp/classes/Checks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Checks {
if (name == "") {
Toast.makeText(
context,
"Empty values not allowed",
context.getString(R.string.empty_not_allowed),
Toast.LENGTH_SHORT
).show()
return false
Expand All @@ -28,7 +28,7 @@ object Checks {
if (!priority.toString().matches(Regex("[0-5]"))) {
Toast.makeText(
context,
"Priority must be between 0 and 5",
context.getString(R.string.priority_between),
Toast.LENGTH_SHORT
).show()
return false
Expand All @@ -40,7 +40,7 @@ object Checks {
if (tag == "") {
Toast.makeText(
context,
"Tag can't be empty",
context.getString(R.string.tag_empty),
Toast.LENGTH_SHORT
).show()
return false
Expand All @@ -56,7 +56,7 @@ object Checks {
}) {
Toast.makeText(
context,
"Tag already exists",
context.getString(R.string.tag_already_exists),
Toast.LENGTH_SHORT
).show()
return false
Expand All @@ -68,7 +68,7 @@ object Checks {
if (tags.contains(tag)) {
Toast.makeText(
context,
"Tag already added",
context.getString(R.string.tag_already_added),
Toast.LENGTH_SHORT
).show()
return false
Expand Down
Loading

0 comments on commit c207892

Please sign in to comment.