diff --git a/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/component/ProviderSettingsHeader.kt b/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/component/ProviderSettingsHeader.kt index 98ff03539..3a41181d7 100644 --- a/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/component/ProviderSettingsHeader.kt +++ b/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/component/ProviderSettingsHeader.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding @@ -33,6 +32,7 @@ import com.flixclusive.core.theme.FlixclusiveTheme import com.flixclusive.core.ui.common.util.getProviderStatusColor import com.flixclusive.core.ui.common.util.onMediumEmphasis import com.flixclusive.core.ui.mobile.component.ImageWithSmallPlaceholder +import com.flixclusive.feature.mobile.provider.settings.util.getFlagFromLanguageCode import com.flixclusive.gradle.entities.Author import com.flixclusive.gradle.entities.Language import com.flixclusive.gradle.entities.ProviderData @@ -62,66 +62,6 @@ internal fun ProviderSettingsHeader( } } -@Composable -private fun ProvidersOtherInfo( - providerData: ProviderData -) { - Row( - horizontalArrangement = Arrangement.SpaceEvenly, - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - ) { - OtherInfoText( - title = stringResource(id = UtilR.string.version), - subtitle = "v${providerData.versionName}" - ) - - OtherInfoText( - title = stringResource(id = UtilR.string.content), - subtitle = providerData.providerType.toString() - ) - - OtherInfoText( - title = stringResource(id = UtilR.string.status), - subtitle = providerData.status.toString() - ) - } -} - -@Composable -private fun OtherInfoText( - modifier: Modifier = Modifier, - title: String, - subtitle: String -) { - Column( - verticalArrangement = Arrangement.spacedBy(10.dp, Alignment.CenterVertically), - horizontalAlignment = Alignment.CenterHorizontally, - modifier = modifier, - ) { - Text( - text = title, - style = MaterialTheme.typography.labelLarge.copy( - fontWeight = FontWeight.Black, - color = LocalContentColor.current.onMediumEmphasis(0.8F), - fontSize = 15.sp - ) - ) - - Text( - text = subtitle, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - style = MaterialTheme.typography.titleMedium.copy( - fontWeight = FontWeight.Medium, - color = LocalContentColor.current.onMediumEmphasis(0.4F), - fontSize = 14.sp - ) - ) - } -} - @Composable private fun AuthorsList( authors: List @@ -222,6 +162,8 @@ private fun HeaderIcon( withStyle(commonStyle.toSpanStyle()) { append("v${providerData.versionName}") append(" - ") + append(getFlagFromLanguageCode(providerData.language.languageCode)) + append(" - ") } withStyle( diff --git a/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/util/LanguageEmojiHelper.kt b/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/util/LanguageEmojiHelper.kt new file mode 100644 index 000000000..c360199c4 --- /dev/null +++ b/feature/mobile/provider-settings/src/main/kotlin/com/flixclusive/feature/mobile/provider/settings/util/LanguageEmojiHelper.kt @@ -0,0 +1,206 @@ +/** + * + * From CS3 + */ +package com.flixclusive.feature.mobile.provider.settings.util + +import com.flixclusive.core.util.exception.safeCall + +private val flagEmojiRegex = Regex("[\uD83C\uDDE6-\uD83C\uDDFF]{2}") +internal fun getFlagFromLanguageCode(code: String?): String? { + if (code?.equals("multiple", true) == true) + return "\uD83C\uDF10" + + if (code.isNullOrBlank() || code.length < 2) + return "❓" + + return safeCall { + val flagEmoji = countryCodeToEmojiFlag(flags[code]) + ?: countryCodeToEmojiFlag(code.uppercase()) + ?: return "❓" + + return if (flagEmojiRegex.matches(flagEmoji)) flagEmoji else "❓" + } +} + +private fun countryCodeToEmojiFlag(flagAscii: String?): String? { + if (flagAscii.isNullOrBlank() || flagAscii.length < 2) return null + + return safeCall { + val offset = 0x1F1E6 - 0x41 + val firstChar: Int = Character.codePointAt(flagAscii, 0) + offset + val secondChar: Int = Character.codePointAt(flagAscii, 1) + offset + + (String(Character.toChars(firstChar)) + String(Character.toChars(secondChar))) + } +} + +private val flags = mapOf( + "af" to "ZA", + "agq" to "CM", + "ajp" to "SY", + "ak" to "GH", + "am" to "ET", + "ar" to "AE", + "ars" to "SA", + "as" to "IN", + "asa" to "TZ", + "az" to "AZ", + "bas" to "CM", + "be" to "BY", + "bem" to "ZM", + "bez" to "IT", + "bg" to "BG", + "bm" to "ML", + "bn" to "BD", + "bo" to "CN", + "br" to "FR", + "brx" to "IN", + "bs" to "BA", + "ca" to "ES", + "cgg" to "UG", + "chr" to "US", + "cs" to "CZ", + "cy" to "GB", + "da" to "DK", + "dav" to "KE", + "de" to "DE", + "dje" to "NE", + "dua" to "CM", + "dyo" to "SN", + "ebu" to "KE", + "ee" to "GH", + "en" to "GB", + "el" to "GR", + "es" to "ES", + "et" to "EE", + "eu" to "ES", + "ewo" to "CM", + "fa" to "IR", + "fil" to "PH", + "fr" to "FR", + "ga" to "IE", + "gl" to "ES", + "gsw" to "CH", + "gu" to "IN", + "guz" to "KE", + "gv" to "GB", + "ha" to "NG", + "haw" to "US", + "he" to "IL", + "hi" to "IN", + "ff" to "CN", + "fi" to "FI", + "fo" to "FO", + "hr" to "HR", + "hu" to "HU", + "hy" to "AM", + "id" to "ID", + "ig" to "NG", + "ii" to "CN", + "is" to "IS", + "it" to "IT", + "ita" to "IT", + "ja" to "JP", + "jmc" to "TZ", + "ka" to "GE", + "kab" to "DZ", + "ki" to "KE", + "kam" to "KE", + "mer" to "KE", + "kde" to "TZ", + "kea" to "CV", + "khq" to "ML", + "kk" to "KZ", + "kl" to "GL", + "kln" to "KE", + "km" to "KH", + "kn" to "IN", + "ko" to "KR", + "kok" to "IN", + "ksb" to "TZ", + "ksf" to "CM", + "kw" to "GB", + "lag" to "TZ", + "lg" to "UG", + "ln" to "CG", + "lt" to "LT", + "lu" to "CD", + "lv" to "LV", + "lat" to "LV", + "luo" to "KE", + "luy" to "KE", + "mas" to "TZ", + "mfe" to "MU", + "mg" to "MG", + "mgh" to "MZ", + "ml" to "IN", + "mk" to "MK", + "mr" to "IN", + "ms" to "MY", + "mt" to "MT", + "mua" to "CM", + "my" to "MM", + "naq" to "NA", + "nb" to "NO", + "no" to "NO", + "nn" to "NO", + "nd" to "ZW", + "ne" to "NP", + "nl" to "NL", + "nmg" to "CM", + "nus" to "SD", + "nyn" to "UG", + "om" to "ET", + "or" to "IN", + "pa" to "PK", + "pl" to "PL", + "ps" to "AF", + "pt" to "PT", + "pt-pt" to "PT", + "pt-br" to "BR", + "rm" to "CH", + "rn" to "BI", + "ro" to "RO", + "ru" to "RU", + "rw" to "RW", + "rof" to "TZ", + "rwk" to "TZ", + "saq" to "KE", + "sbp" to "TZ", + "seh" to "MZ", + "ses" to "ML", + "sg" to "CF", + "shi" to "MA", + "si" to "LK", + "sk" to "SK", + "sl" to "SI", + "sn" to "ZW", + "so" to "SO", + "sq" to "AL", + "sr" to "RS", + "sv" to "SE", + "sw" to "TZ", + "swc" to "CD", + "ta" to "IN", + "te" to "IN", + "teo" to "UG", + "th" to "TH", + "ti" to "ET", + "to" to "TO", + "tr" to "TR", + "twq" to "NE", + "tzm" to "MA", + "uk" to "UA", + "ur" to "PK", + "uz" to "UZ", + "vai" to "LR", + "vi" to "VN", + "vun" to "TZ", + "xog" to "UG", + "yav" to "CM", + "yo" to "NG", + "zh" to "CN", + "zu" to "ZA", + "tl" to "PH", +) \ No newline at end of file