commit c227dff7348337356d1d479d8df07d9963a258bf
parent cd4f3c29c4a5a39a3e52de61307fe863a6f098c7
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Sat, 5 Aug 2023 09:58:47 +0200
feat: navbar localization
Diffstat:
8 files changed, 67 insertions(+), 21 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/MainActivity.kt
@@ -39,7 +39,7 @@ class MainActivity : ComponentActivity() {
setContent {
val navController = rememberNavController()
- val navigation = remember { Navigation(sections, navController) }
+ val navigation = remember { Navigation(managerContext, sections, navController) }
AppMaterialTheme {
Scaffold(
containerColor = MaterialTheme.colorScheme.background,
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Navigation.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Navigation.kt
@@ -5,7 +5,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
-import androidx.compose.foundation.layout.requiredWidth
+import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.ExperimentalMaterial3Api
@@ -18,16 +18,20 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.currentBackStackEntryAsState
+import me.rhunk.snapenhance.RemoteSideContext
class Navigation(
+ private val context: RemoteSideContext,
private val sections: Map<EnumSection, Section>,
private val navHostController: NavHostController
){
@@ -80,7 +84,6 @@ class Navigation(
NavigationBarItem(
modifier = Modifier
- .requiredWidth(75.dp)
.fillMaxHeight(),
icon = {
val iconOffset by animateDpAsState(
@@ -99,7 +102,13 @@ class Navigation(
if (selected()) 0.dp else (-5).dp,
label = ""
)
- Text(text = if (selected()) section.title else "", modifier = Modifier.offset(y = labelOffset))
+ Text(
+ textAlign = TextAlign.Center,
+ softWrap = false,
+ fontSize = 12.sp,
+ modifier = Modifier.wrapContentWidth(unbounded = true).offset(y = labelOffset),
+ text = if (selected()) context.translation["manager.routes.${section.route}"] else "",
+ )
},
selected = selected(),
onClick = {
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Section.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/Section.kt
@@ -20,36 +20,30 @@ import kotlin.reflect.KClass
enum class EnumSection(
val route: String,
- val title: String,
val icon: ImageVector,
val section: KClass<out Section> = NotImplemented::class
) {
DOWNLOADS(
route = "downloads",
- title = "Downloads",
icon = Icons.Filled.Download,
section = DownloadSection::class
),
FEATURES(
route = "features",
- title = "Features",
icon = Icons.Filled.Stars,
section = FeaturesSection::class
),
HOME(
route = "home",
- title = "Home",
icon = Icons.Filled.Home,
section = HomeSection::class
),
FRIENDS(
route = "friends",
- title = "Friends",
icon = Icons.Filled.Group
),
DEBUG(
route = "debug",
- title = "Debug",
icon = Icons.Filled.BugReport
);
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/HomeSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/HomeSection.kt
@@ -3,15 +3,16 @@ package me.rhunk.snapenhance.ui.manager.sections
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
-import androidx.compose.foundation.layout.ExperimentalLayoutApi
-import androidx.compose.foundation.layout.FlowRow
+import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.Language
import androidx.compose.material.icons.filled.Map
+import androidx.compose.material.icons.filled.OpenInNew
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
@@ -26,14 +27,15 @@ import androidx.compose.ui.unit.dp
import me.rhunk.snapenhance.ui.manager.Section
import me.rhunk.snapenhance.ui.manager.data.InstallationSummary
import me.rhunk.snapenhance.ui.setup.Requirements
+import java.util.Locale
class HomeSection : Section() {
companion object {
val cardMargin = 10.dp
}
private val installationSummary = mutableStateOf(null as InstallationSummary?)
+ private val userLocale = mutableStateOf(null as String?)
- @OptIn(ExperimentalLayoutApi::class)
@Composable
private fun SummaryCards(installationSummary: InstallationSummary) {
//installation summary
@@ -57,7 +59,7 @@ class HomeSection : Section() {
.padding(all = cardMargin)
.fillMaxWidth()
) {
- FlowRow(
+ Row(
modifier = Modifier.padding(all = 16.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
@@ -86,6 +88,34 @@ class HomeSection : Section() {
}
}
}
+ OutlinedCard(
+ modifier = Modifier
+ .padding(all = cardMargin)
+ .fillMaxWidth()
+ ) {
+ Row(
+ modifier = Modifier.padding(all = 16.dp),
+ ) {
+ Icon(
+ Icons.Filled.Language,
+ contentDescription = "Language",
+ modifier = Modifier
+ .padding(end = 10.dp)
+ .align(Alignment.CenterVertically)
+ )
+ Text(text = userLocale.value ?: "Unknown", modifier = Modifier
+ .weight(1f)
+ .align(Alignment.CenterVertically)
+ )
+
+ //inline button
+ Button(onClick = {
+ context.checkForRequirements(Requirements.LANGUAGE)
+ }, modifier = Modifier.height(40.dp)) {
+ Icon(Icons.Filled.OpenInNew, contentDescription = null)
+ }
+ }
+ }
}
override fun onResumed() {
@@ -93,6 +123,7 @@ class HomeSection : Section() {
context.mappings.init()
}
installationSummary.value = context.getInstallationSummary()
+ userLocale.value = context.translation.loadedLocale.getDisplayName(Locale.getDefault())
}
override fun sectionTopBarName() = "SnapEnhance"
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/features/FeaturesSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/features/FeaturesSection.kt
@@ -115,7 +115,7 @@ class FeaturesSection : Section() {
}
override fun build(navGraphBuilder: NavGraphBuilder) {
- navGraphBuilder.navigation(route = "features", startDestination = MAIN_ROUTE) {
+ navGraphBuilder.navigation(route = enumSection.route, startDestination = MAIN_ROUTE) {
composable(MAIN_ROUTE) {
Container(context.config.root)
}
@@ -141,8 +141,7 @@ class FeaturesSection : Section() {
if (showDialog.value) {
Dialog(
- onDismissRequest = { showDialog.value = false },
- properties = DialogProperties()
+ onDismissRequest = { showDialog.value = false }
) {
dialogComposable.value()
}
@@ -329,7 +328,7 @@ class FeaturesSection : Section() {
scaffoldState.snackbarHostState.showSnackbar("Saved")
}
},
- modifier = Modifier.padding(25.dp),
+ modifier = Modifier.padding(10.dp),
containerColor = MaterialTheme.colors.primary,
contentColor = MaterialTheme.colors.onPrimary,
shape = RoundedCornerShape(16.dp),
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/screens/impl/MappingsScreen.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/setup/screens/impl/MappingsScreen.kt
@@ -35,7 +35,6 @@ class MappingsScreen : SetupScreen() {
}) {
Surface(
modifier = Modifier.padding(16.dp).fillMaxWidth(),
- color = MaterialTheme.colors.surface,
shape = RoundedCornerShape(16.dp),
) {
Column(
@@ -86,8 +85,8 @@ class MappingsScreen : SetupScreen() {
}) {
if (isGenerating.value) {
CircularProgressIndicator(
- modifier = Modifier.padding(end = 5.dp).size(25.dp),
- strokeWidth = 2.dp,
+ modifier = Modifier.padding().size(30.dp),
+ strokeWidth = 3.dp,
color = MaterialTheme.colors.onPrimary
)
} else {
diff --git a/core/src/main/assets/lang/en_US.json b/core/src/main/assets/lang/en_US.json
@@ -20,6 +20,7 @@
"routes": {
"downloads": "Downloads",
"features": "Features",
+ "home": "Home",
"friends": "Friends",
"debug": "Debug"
},
diff --git a/core/src/main/assets/lang/fr_FR.json b/core/src/main/assets/lang/fr_FR.json
@@ -7,6 +7,19 @@
}
},
+ "manager": {
+ "routes": {
+ "downloads": "Téléchargements",
+ "features": "Fonctionnalités",
+ "home": "Accueil",
+ "friends": "Amis",
+ "debug": "Débogage"
+ },
+ "features": {
+ "disabled": "Désactivé"
+ }
+ },
+
"category": {
"spying_privacy": "Espionnage et vie privée",
"media_manager": "Gestionnaire de média",