diff --git a/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/modals/LanguageBottomSheet.kt b/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/modals/LanguageBottomSheet.kt index 707a888a1..6e97ddfc0 100644 --- a/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/modals/LanguageBottomSheet.kt +++ b/core-commonui/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/commonui/modals/LanguageBottomSheet.kt @@ -13,6 +13,7 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.text.buildAnnotatedString import cafe.adriel.voyager.core.screen.Screen import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle @@ -21,6 +22,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.notifications.NotificationC import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotificationCenter import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback +import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLanguageFlag import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLanguageName import com.github.diegoberaldin.raccoonforlemmy.resources.MR import dev.icerock.moko.resources.compose.stringResource @@ -100,7 +102,13 @@ class LanguageBottomSheet : Screen { ), ) { Text( - text = value.toLanguageName(), + text = buildAnnotatedString { + with(value) { + append(toLanguageFlag()) + append(" ") + append(toLanguageName()) + } + }, style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onBackground, ) diff --git a/core-utils/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/utils/Extensions.kt b/core-utils/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/utils/Extensions.kt index 0fe6f388f..a400fcf19 100644 --- a/core-utils/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/utils/Extensions.kt +++ b/core-utils/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/core/utils/Extensions.kt @@ -2,8 +2,11 @@ package com.github.diegoberaldin.raccoonforlemmy.core.utils import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.unit.Dp import com.github.diegoberaldin.raccoonforlemmy.resources.MR +import dev.icerock.moko.resources.compose.fontFamilyResource import dev.icerock.moko.resources.compose.stringResource import kotlin.math.round @@ -37,6 +40,42 @@ fun String.toLanguageName() = when (this) { else -> stringResource(MR.strings.language_en) } +@Composable +fun String.toLanguageFlag(): AnnotatedString = when (this) { + "bg" -> "🇧🇬" + "cs" -> "🇨🇿" + "da" -> "🇩🇰" + "de" -> "🇩🇪" + "el" -> "🇬🇷" + "en" -> "🇬🇧" + "eo" -> "🍀" + "es" -> "🇪🇸" + "et" -> "🇪🇪" + "ga" -> "🇮🇪" + "fi" -> "🇫🇮" + "fr" -> "🇫🇷" + "hu" -> "🇭🇺" + "hr" -> "🇭🇷" + "it" -> "🇮🇹" + "lt" -> "🇱🇹" + "lv" -> "🇱🇻" + "mt" -> "🇲🇹" + "no" -> "🇳🇴" + "nl" -> "🇳🇱" + "pl" -> "🇵🇱" + "pt" -> "🇵🇹" + "ro" -> "🇷🇴" + "se" -> "🇸🇪" + "sk" -> "🇸🇰" + "sl" -> "🇸🇮" + else -> "" +}.let { + AnnotatedString( + text = it, + spanStyle = SpanStyle(fontFamily = fontFamilyResource(MR.fonts.TitilliumWeb.regular)) + ) +} + @Composable fun Dp.toLocalPixel(): Float = with(LocalDensity.current) { value * density diff --git a/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/main/SettingsScreen.kt b/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/main/SettingsScreen.kt index f29f5384d..73f20ad45 100644 --- a/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/main/SettingsScreen.kt +++ b/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/main/SettingsScreen.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.layout.onGloballyPositioned +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.unit.toSize import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.core.screen.Screen @@ -64,6 +65,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallbackArgs import com.github.diegoberaldin.raccoonforlemmy.core.utils.datetime.getPrettyDuration +import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLanguageFlag import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLanguageName import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.SortType @@ -254,7 +256,13 @@ class SettingsScreen : Screen { // language SettingsRow( title = stringResource(MR.strings.settings_language), - value = uiState.lang.toLanguageName(), + annotatedValue = buildAnnotatedString { + with(uiState.lang) { + append(toLanguageFlag()) + append(" ") + append(toLanguageName()) + } + }, onTap = rememberCallback { val sheet = LanguageBottomSheet() navigationCoordinator.showBottomSheet(sheet) diff --git a/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/ui/components/SettingsRow.kt b/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/ui/components/SettingsRow.kt index 88cdfb527..26daae8c0 100644 --- a/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/ui/components/SettingsRow.kt +++ b/feature-settings/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/feature/settings/ui/components/SettingsRow.kt @@ -8,6 +8,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.style.TextOverflow import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick @@ -16,7 +17,8 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallb @Composable internal fun SettingsRow( title: String, - value: String, + value: String = "", + annotatedValue: AnnotatedString = AnnotatedString(""), modifier: Modifier = Modifier, subtitle: String? = null, onTap: (() -> Unit)? = null, @@ -47,13 +49,24 @@ internal fun SettingsRow( ) } } - Text( - modifier = Modifier.padding(start = Spacing.xs), - text = value, - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onBackground, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) + if (annotatedValue.isNotEmpty()) { + Text( + modifier = Modifier.padding(start = Spacing.xs), + text = annotatedValue, + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onBackground, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } else { + Text( + modifier = Modifier.padding(start = Spacing.xs), + text = value, + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.onBackground, + maxLines = 1, + overflow = TextOverflow.Ellipsis, + ) + } } }