Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ fun RecordingListItem(
color = MaterialTheme.colorScheme.onSurface
)
Text(
text = "$dateStr • $durationStr • $sizeStr (${record.format.uppercase()})",
text = "$dateStr • $durationStr • $sizeStr (${record.format.uppercase(Locale.ROOT)})",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 1
Expand Down Expand Up @@ -510,7 +510,7 @@ fun RecordingOptionsDialog(
overflow = TextOverflow.Ellipsis
)
Text(
text = "$dateStr • $durationStr • $sizeStr (${record.format.uppercase()})",
text = "$dateStr • $durationStr • $sizeStr (${record.format.uppercase(Locale.ROOT)})",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant
)
Expand Down Expand Up @@ -639,7 +639,7 @@ private fun shareRecordingFile(context: Context, record: RecordEntity) {
type = "audio/*"
putExtra(Intent.EXTRA_STREAM, uri)
putExtra(Intent.EXTRA_SUBJECT, record.Name)
putExtra(Intent.EXTRA_TEXT, "${record.Name}\nRecording: ${record.format.uppercase()}")
putExtra(Intent.EXTRA_TEXT, "${record.Name}\nRecording: ${record.format.uppercase(Locale.ROOT)}")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
val chooser = Intent.createChooser(shareIntent, context.getString(R.string.action_station_share))
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/ounben/amaradio/ui/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.ounben.amaradio.AMARadioApp
import com.ounben.amaradio.R
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.util.Locale

@Serializable
private data class CountryJson(
Expand Down Expand Up @@ -254,7 +255,7 @@ fun SettingsScreen(
val json = Json { ignoreUnknownKeys = true }
val countries = json.decodeFromString<List<CountryJson>>(jsonContent)
val categories = countries.mapNotNull { item ->
val code = item.code?.uppercase() ?: return@mapNotNull null
val code = item.code?.uppercase(Locale.ROOT) ?: return@mapNotNull null
val rawName = item.name ?: code
val label = com.ounben.amaradio.CountryCodeDictionary.instance.getCountryByCode(code) ?: rawName
val emoji = com.ounben.amaradio.utils.EmojiUtils.getFlagEmoji(code) ?: ""
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/kotlin/com/ounben/amaradio/ui/TabsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.ounben.amaradio.R
import com.ounben.amaradio.Utils
import com.ounben.amaradio.station.DataRadioStation
import kotlinx.coroutines.launch
import java.util.Locale

private sealed class MainTab {
object Local : MainTab()
Expand Down Expand Up @@ -122,8 +123,8 @@ fun TabsScreen(
val title = when (tab) {
is MainTab.Local -> {
if (manualCountry.isNotEmpty() && manualCountry != "SYSTEM") {
val flag = com.ounben.amaradio.utils.EmojiUtils.getFlagEmoji(manualCountry.uppercase()) ?: ""
if (flag.isNotEmpty()) "$flag ${manualCountry.uppercase()}" else manualCountry.uppercase()
val flag = com.ounben.amaradio.utils.EmojiUtils.getFlagEmoji(manualCountry.uppercase(Locale.ROOT)) ?: ""
if (flag.isNotEmpty()) "$flag ${manualCountry.uppercase(Locale.ROOT)}" else manualCountry.uppercase(Locale.ROOT)
} else {
stringResource(R.string.action_local)
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/kotlin/com/ounben/amaradio/utils/EmojiUtils.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.ounben.amaradio.utils

import java.util.Locale

object EmojiUtils {
/**
* Converts a 2-letter country code to a flag emoji.
* Example: "US" -> 🇺🇸
*/
fun getFlagEmoji(countryCode: String?): String? {
if (countryCode == null || countryCode.length != 2) return null

val firstChar = Character.codePointAt(countryCode.uppercase(), 0) - 0x41 + 0x1F1E6
val secondChar = Character.codePointAt(countryCode.uppercase(), 1) - 0x41 + 0x1F1E6
// Country codes are ASCII identifiers: never let the device locale turn 'i' into 'İ'.
val code = countryCode.uppercase(Locale.ROOT)

val firstChar = Character.codePointAt(code, 0) - 0x41 + 0x1F1E6
val secondChar = Character.codePointAt(code, 1) - 0x41 + 0x1F1E6

return String(Character.toChars(firstChar)) + String(Character.toChars(secondChar))
}
Expand Down
Loading