-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ui enhancement(LanguagesScreen): add emojis for languages and redesig…
…n language item
- Loading branch information
Showing
3 changed files
with
874 additions
and
23 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/kaajjo/libresudoku/ui/components/locale_emoji/LocaleEmoji.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.kaajjo.libresudoku.ui.components.locale_emoji | ||
|
||
import android.util.Log | ||
|
||
object LocaleEmoji { | ||
/** | ||
* Get a country flag from language code | ||
* @return country flag (emoji) | ||
*/ | ||
fun getFlagEmoji( | ||
languageCode: String | ||
): String? { | ||
val countryCode = countryFromLanguage(languageCode) | ||
if (countryCode.isNullOrBlank()) return null | ||
|
||
return countryCodeToEmoji(countryCode) | ||
} | ||
|
||
private fun countryFromLanguage(languageCode: String?): String? { | ||
if (languageCode == null) return null | ||
|
||
return languageCodeToCountryCode[languageCode.lowercase()] | ||
} | ||
|
||
private fun countryCodeToEmoji(countryCode: String): String? { | ||
val uppercaseCode = countryCode.uppercase() | ||
|
||
try { | ||
val firstChar = uppercaseCode[0] - 'A' + 0x1F1E6 | ||
val secondChar = uppercaseCode[1] - 'A' + 0x1F1E6 | ||
val emoji = String(Character.toChars(firstChar)) + String(Character.toChars(secondChar)) | ||
return emoji | ||
} catch (e: IllegalArgumentException) { | ||
Log.e("LocaleEmoji", "Cannot find flag for: $countryCode") | ||
return null | ||
} | ||
} | ||
} |
Oops, something went wrong.