From c2514eabdabda65f56b0efcd1524f2b668dd7274 Mon Sep 17 00:00:00 2001 From: Harold Martin Date: Mon, 2 Oct 2023 09:59:06 -0700 Subject: [PATCH] Refactoring Country Data (#32) * Refactoring Country Data * cleanups * upgrade AGP * improved color handling for clear icon, add label to demo * upgrade compose, add missing hints * detekt * upgrade sonar * optimizations * use remember / derivedStateOf to minimize recomposition when searching --- .github/workflows/documentation.yml | 3 +- README.md | 4 +- app/src/main/AndroidManifest.xml | 3 +- .../java/com/togitech/togii/MainActivity.kt | 5 +- build.gradle.kts | 4 +- ccp/build.gradle.kts | 5 +- .../togitech/ccp/component/CountryDialog.kt | 58 ++-- .../{TogiCodePicker.kt => TogiCodeDialog.kt} | 85 +++--- .../ccp/component/TogiCountryCodePicker.kt | 110 ++++---- .../java/com/togitech/ccp/data/CountryData.kt | 257 ++++++++++++++++- .../ccp/data/utils/CountryCodeUtils.kt | 41 +++ .../togitech/ccp/data/utils/CountryNameMap.kt | 249 +++++++++++++++++ .../togitech/ccp/data/utils/GetCountryName.kt | 248 ----------------- .../ccp/data/utils/GetCountryPhoneCode.kt | 262 ------------------ .../togitech/ccp/data/utils/GetNumberHint.kt | 249 ----------------- .../togitech/ccp/data/utils/NumberHintMap.kt | 250 +++++++++++++++++ .../ccp/{ => data}/utils/SearchCountryList.kt | 7 +- .../com/togitech/ccp/data/utils/TogiUtils.kt | 50 ---- ccp/src/main/res/values/strings.xml | 9 + .../com/togitech/ccp/CountryCodePickTest.kt | 1 + detekt.yml | 5 +- gradle/libs.versions.toml | 4 +- 22 files changed, 958 insertions(+), 951 deletions(-) rename ccp/src/main/java/com/togitech/ccp/component/{TogiCodePicker.kt => TogiCodeDialog.kt} (64%) create mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/CountryCodeUtils.kt create mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/CountryNameMap.kt delete mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryName.kt delete mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryPhoneCode.kt delete mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/GetNumberHint.kt create mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/NumberHintMap.kt rename ccp/src/main/java/com/togitech/ccp/{ => data}/utils/SearchCountryList.kt (79%) delete mode 100644 ccp/src/main/java/com/togitech/ccp/data/utils/TogiUtils.kt diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index f8fee85..392d997 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -2,7 +2,8 @@ name: Publish Dokka HTML to GitHub Pages on: push: - branches: [ master ] + tags: + - '*' jobs: build: diff --git a/README.md b/README.md index eb85524..e1c2094 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Android CI](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/actions/workflows/android.yml/badge.svg)](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/actions/workflows/android.yml) [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=jump-sdk_jetpack_compose_country_code_picker_emoji&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=jump-sdk_jetpack_compose_country_code_picker_emoji) [![Jitpack](https://jitpack.io/v/jump-sdk/jetpack_compose_country_code_picker_emoji.svg)](https://jitpack.io/#jump-sdk/jetpack_compose_country_code_picker_emoji) +[![Documentation](https://img.shields.io/badge/Documentation-3d3d41?logo=kotlin)](https://jump-sdk.github.io/jetpack_compose_country_code_picker_emoji/) * 😍 Emoji flag icons - beautiful and minimizes library size * 🤔 Country numbers hints (option to disable) @@ -28,6 +29,7 @@ See [MainActivity in the sample app](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/blob/master/app/src/main/java/com/togitech/togii/MainActivity.kt) for a full example. +Also check out the [ComposeCountryCodePicker documentation](https://jump-sdk.github.io/jetpack_compose_country_code_picker_emoji/) for all available composables and utilities. ```kotlin TogiCountryCodePicker( @@ -87,7 +89,7 @@ Step 2. Add the dependency ```kotlin dependencies { - implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.0.8") + implementation("com.github.jump-sdk:jetpack_compose_country_code_picker_emoji:2.2.0") } ``` diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fbadff..9791d82 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -7,7 +7,8 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.Togii"> + android:theme="@style/Theme.Togii" + android:usesCleartextTraffic="false"> Log.d("CCP", "onValueChange: $code $phone -> $isValid") phoneNumber.value = phone fullPhoneNumber.value = code + phone isNumberValid = isValid }, + label = { Text("Test Label") }, ) Spacer(modifier = Modifier.height(10.dp)) diff --git a/build.gradle.kts b/build.gradle.kts index 396f6cd..312a4ba 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("com.android.library") version libs.versions.android.gradle.plugin apply false id("org.jetbrains.kotlin.android") version libs.versions.kotlin apply false id("org.jetbrains.dokka") version libs.versions.dokka - id("org.sonarqube") version "4.3.1.3277" + id("org.sonarqube") version "4.4.0.3356" alias(libs.plugins.gradleVersions) } @@ -12,7 +12,7 @@ sonarqube { property("sonar.projectKey", "jump-sdk_jetpack_compose_country_code_picker_emoji") property("sonar.organization", "jump-sdk") property("sonar.host.url", "https://sonarcloud.io") - property("sonar.kotlin.source.version", "1.9.10") + property("sonar.kotlin.source.version", libs.versions.kotlin.get()) property("sonar.pullrequest.github.summary_comment", "true") } } diff --git a/ccp/build.gradle.kts b/ccp/build.gradle.kts index f9d7511..6543c97 100644 --- a/ccp/build.gradle.kts +++ b/ccp/build.gradle.kts @@ -7,9 +7,6 @@ plugins { id("app.cash.paparazzi") version libs.versions.paparazzi.get() } -group "com.togitech" -version "2.0.5" - kotlin { jvmToolchain(17) } @@ -81,7 +78,7 @@ afterEvaluate { from(components.getByName("release")) groupId = "com.togisoft" artifactId = "jetpack_country_code_picker" - version = "2.0.5" + version = "2.2.0" } } } diff --git a/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt b/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt index cec4d75..22fb406 100644 --- a/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt +++ b/ccp/src/main/java/com/togitech/ccp/component/CountryDialog.kt @@ -1,6 +1,5 @@ package com.togitech.ccp.component -import android.content.Context import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -26,8 +25,10 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Clear import androidx.compose.material.icons.filled.Search import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -47,31 +48,49 @@ import androidx.compose.ui.unit.sp import androidx.compose.ui.window.Dialog import com.togitech.ccp.R import com.togitech.ccp.data.CountryData -import com.togitech.ccp.data.utils.countryCodeToEmojiFlag import com.togitech.ccp.data.utils.countryNames -import com.togitech.ccp.data.utils.getLibCountries -import com.togitech.ccp.utils.searchCountry +import com.togitech.ccp.data.utils.emojiFlag +import com.togitech.ccp.data.utils.searchCountry import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList -private val DEFAULT_ROUNDING = 10.dp +internal val DEFAULT_ROUNDING = 10.dp private val DEFAULT_ROW_PADDING = 16.dp private const val ROW_PADDING_VERTICAL_SCALING = 1.1f private val DEFAULT_ROW_FONT_SIZE = 16.sp private val SEARCH_ICON_PADDING = 5.dp -@Suppress("ModifierDefaultValue") +/** + * @param onDismissRequest Executes when the user tries to dismiss the dialog. + * @param onSelect Executes when the user selects a country from the list. + * @param countryList The list of countries to display in the dialog. + * @param modifier The modifier to be applied to the dialog surface. + * @param rowPadding The padding to be applied to each row. + * @param rowFontSize The font size to be applied to each row. + */ @Composable -internal fun CountryDialog( +fun CountryDialog( onDismissRequest: () -> Unit, onSelect: (item: CountryData) -> Unit, - filteredCountryList: ImmutableList, - context: Context, - modifier: Modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(DEFAULT_ROUNDING)), + countryList: ImmutableList, + modifier: Modifier = Modifier, rowPadding: Dp = DEFAULT_ROW_PADDING, rowFontSize: TextUnit = DEFAULT_ROW_FONT_SIZE, ) { + val context = LocalContext.current var searchValue by rememberSaveable { mutableStateOf("") } + val filteredCountries by remember(context, searchValue) { + derivedStateOf { + if (searchValue.isEmpty()) { + countryList + } else { + countryList.searchCountry( + searchValue, + context, + ) + } + } + } Dialog( onDismissRequest = onDismissRequest, @@ -101,16 +120,7 @@ internal fun CountryDialog( Spacer(modifier = Modifier.height(DEFAULT_ROW_PADDING)) Divider() LazyColumn { - items( - if (searchValue.isEmpty()) { - filteredCountryList - } else { - filteredCountryList.searchCountry( - searchValue, - context, - ) - }, - ) { countryItem -> + items(filteredCountries, key = { it.countryIso }) { countryItem -> CountryRowItem( rowPadding = rowPadding, onSelect = { onSelect(countryItem) }, @@ -167,10 +177,10 @@ private fun CountryRowItem( verticalAlignment = Alignment.CenterVertically, ) { Text( - text = countryCodeToEmojiFlag(countryItem.countryCode) + " " + + text = countryItem.emojiFlag + " " + stringResource( id = countryNames.getOrDefault( - countryItem.countryCode.lowercase(), + countryItem.countryIso, R.string.unknown, ), ), @@ -231,8 +241,8 @@ private fun SearchTextField( private fun CountryDialogPreview() { CountryDialog( onSelect = {}, - context = LocalContext.current, - filteredCountryList = getLibCountries.toImmutableList(), + countryList = CountryData.entries.toImmutableList(), onDismissRequest = {}, + modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(DEFAULT_ROUNDING)), ) } diff --git a/ccp/src/main/java/com/togitech/ccp/component/TogiCodePicker.kt b/ccp/src/main/java/com/togitech/ccp/component/TogiCodeDialog.kt similarity index 64% rename from ccp/src/main/java/com/togitech/ccp/component/TogiCodePicker.kt rename to ccp/src/main/java/com/togitech/ccp/component/TogiCodeDialog.kt index 4357251..2ae8f96 100644 --- a/ccp/src/main/java/com/togitech/ccp/component/TogiCodePicker.kt +++ b/ccp/src/main/java/com/togitech/ccp/component/TogiCodeDialog.kt @@ -5,60 +5,63 @@ import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Icon import androidx.compose.material.MaterialTheme import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowDropDown import androidx.compose.runtime.Composable +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import com.togitech.ccp.data.CountryData -import com.togitech.ccp.data.utils.countryCodeToEmojiFlag -import com.togitech.ccp.data.utils.getLibCountries -import com.togitech.ccp.data.utils.unitedStates -import com.togitech.ccp.utils.sortedByLocalizedName +import com.togitech.ccp.data.utils.emojiFlag +import com.togitech.ccp.data.utils.sortedByLocalizedName import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.toImmutableList -private val DEFAULT_PADDING = 10.dp +internal val DEFAULT_PADDING = 10.dp @Composable internal fun TogiCodeDialog( - defaultSelectedCountry: CountryData, + selectedCountry: CountryData, includeOnly: ImmutableSet?, onCountryChange: (CountryData) -> Unit, textColor: Color, showCountryCode: Boolean, showFlag: Boolean, modifier: Modifier = Modifier, - padding: Dp = DEFAULT_PADDING, ) { val context = LocalContext.current - var country by remember { mutableStateOf(defaultSelectedCountry) } + var country by remember { mutableStateOf(selectedCountry) } var isOpenDialog by remember { mutableStateOf(false) } val interactionSource = remember { MutableInteractionSource() } - val allCountries = getLibCountries.sortedByLocalizedName(context) - val countryList = includeOnly?.run { - val includeLowercase = map { it.lowercase() } - allCountries.filter { it.countryCode in includeLowercase } - } ?: allCountries + val countryList by remember(context, includeOnly) { + derivedStateOf { + val allCountries = CountryData.entries.sortedByLocalizedName(context) + includeOnly?.run { + val includeUppercase = map { it.uppercase() } + allCountries.filter { it.countryIso in includeUppercase } + } ?: allCountries + } + } Column( modifier = modifier - .padding(padding) .clickable( interactionSource = interactionSource, indication = null, @@ -66,7 +69,7 @@ internal fun TogiCodeDialog( isOpenDialog = true }, ) { - CodePickerRow( + CountryRow( showCountryCode = showCountryCode, showFlag = showFlag, country = country, @@ -75,48 +78,46 @@ internal fun TogiCodeDialog( if (isOpenDialog) { CountryDialog( + modifier = Modifier.fillMaxWidth().clip(RoundedCornerShape(DEFAULT_ROUNDING)), onDismissRequest = { isOpenDialog = false }, - context = context, onSelect = { countryItem -> onCountryChange(countryItem) country = countryItem isOpenDialog = false }, - filteredCountryList = countryList.toImmutableList(), + countryList = countryList.toImmutableList(), ) } } } @Composable -private fun CodePickerRow( +private fun CountryRow( showCountryCode: Boolean, showFlag: Boolean, country: CountryData, textColor: Color, fontWeight: FontWeight = FontWeight.Medium, +) = Row( + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, ) { - Row( - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - ) { - Text( - text = emojiCodeText( - showFlag = showFlag, - isPickCountry = country, - showCountryCode = showCountryCode, - ), - modifier = Modifier.padding(start = DEFAULT_PADDING), - fontStyle = MaterialTheme.typography.body1.fontStyle, - fontWeight = fontWeight, - color = textColor, - ) - Icon( - imageVector = Icons.Default.ArrowDropDown, - contentDescription = null, - tint = textColor, - ) - } + Text( + text = emojiCodeText( + showFlag = showFlag, + isPickCountry = country, + showCountryCode = showCountryCode, + ), + modifier = Modifier.padding(start = DEFAULT_PADDING), + fontStyle = MaterialTheme.typography.body1.fontStyle, + fontWeight = fontWeight, + color = textColor, + ) + Icon( + imageVector = Icons.Default.ArrowDropDown, + contentDescription = null, + tint = textColor, + ) } @Composable @@ -124,7 +125,7 @@ private fun emojiCodeText( showFlag: Boolean, isPickCountry: CountryData, showCountryCode: Boolean, -) = (if (showFlag) countryCodeToEmojiFlag(isPickCountry.countryCode) else "") + +) = (if (showFlag) isPickCountry.emojiFlag else "") + (if (showCountryCode && showFlag) " " else "") + (if (showCountryCode) isPickCountry.countryPhoneCode else "") @@ -132,7 +133,7 @@ private fun emojiCodeText( @Composable private fun TogiCodeDialogPreview() { TogiCodeDialog( - defaultSelectedCountry = unitedStates, + selectedCountry = CountryData.UnitedStates, includeOnly = null, textColor = MaterialTheme.colors.onSurface, showCountryCode = true, diff --git a/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt b/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt index 1a60841..95b2e8b 100644 --- a/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt +++ b/ccp/src/main/java/com/togitech/ccp/component/TogiCountryCodePicker.kt @@ -1,13 +1,14 @@ package com.togitech.ccp.component +import android.util.Log import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.Icon import androidx.compose.material.IconButton -import androidx.compose.material.MaterialTheme import androidx.compose.material.OutlinedTextField import androidx.compose.material.Text import androidx.compose.material.TextFieldColors @@ -29,7 +30,6 @@ import androidx.compose.ui.composed import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.focus.onFocusChanged -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.boundsInWindow @@ -45,16 +45,17 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import com.togitech.ccp.R import com.togitech.ccp.data.CountryData +import com.togitech.ccp.data.Iso31661alpha2 +import com.togitech.ccp.data.PhoneCode import com.togitech.ccp.data.utils.ValidatePhoneNumber -import com.togitech.ccp.data.utils.countryDataMap -import com.togitech.ccp.data.utils.countryDataMapPhoneCode -import com.togitech.ccp.data.utils.getDefaultCountryAndPhoneCode +import com.togitech.ccp.data.utils.getCountryFromPhoneCode +import com.togitech.ccp.data.utils.getUserIsoCode import com.togitech.ccp.data.utils.numberHint -import com.togitech.ccp.data.utils.unitedStates import com.togitech.ccp.transformation.PhoneNumberTransformation import kotlinx.collections.immutable.ImmutableSet private val DEFAULT_TEXT_FIELD_SHAPE = RoundedCornerShape(24.dp) +private const val TAG = "TogiCountryCodePicker" /** * @param onValueChange Called when the text in the text field changes. @@ -66,14 +67,14 @@ private val DEFAULT_TEXT_FIELD_SHAPE = RoundedCornerShape(24.dp) * @param showCountryCode Whether to show the country code in the text field. * @param showCountryFlag Whether to show the country flag in the text field. * @param colors Colors to be used for the text field. - * @param fallbackCountryCode The country to be used as a fallback if the user's country cannot be determined. + * @param fallbackCountry The country to be used as a fallback if the user's country cannot be determined. * @param showPlaceholder Whether to show the placeholder number in the text field. * @param includeOnly A set of 2 digit country codes to be included in the list of countries. * Set to null to include all supported countries. * @param clearIcon The icon to be used for the clear button. Set to null to disable the clear button. * @param initialPhoneNumber an optional phone number to be initial value of the input field - * @param initialCountryCode an optional ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) - * of the initially selected country. + * @param initialCountryIsoCode an optional ISO-3166-1 alpha-2 country code equivalent of the MCC (Mobile Country Code) + * of the initially selected country. Note that if a valid initialCountryPhoneCode is provided, this will be ignored. * @param initialCountryPhoneCode an optional Phone calling code of initially selected country * @param label An optional composable to be used as a label for input field @@ -82,52 +83,57 @@ private val DEFAULT_TEXT_FIELD_SHAPE = RoundedCornerShape(24.dp) @Suppress("LongMethod") @Composable fun TogiCountryCodePicker( - onValueChange: (Pair, Boolean) -> Unit, + onValueChange: (Pair, Boolean) -> Unit, modifier: Modifier = Modifier, enabled: Boolean = true, shape: Shape = DEFAULT_TEXT_FIELD_SHAPE, showCountryCode: Boolean = true, showCountryFlag: Boolean = true, colors: TextFieldColors = TextFieldDefaults.outlinedTextFieldColors(), - fallbackCountryCode: String = "us", + fallbackCountry: CountryData = CountryData.UnitedStates, showPlaceholder: Boolean = true, includeOnly: ImmutableSet? = null, clearIcon: ImageVector? = Icons.Filled.Clear, initialPhoneNumber: String? = null, - initialCountryCode: String? = null, - initialCountryPhoneCode: String? = null, - label: - @Composable() - (() -> Unit)? = null, + initialCountryIsoCode: Iso31661alpha2? = null, + initialCountryPhoneCode: PhoneCode? = null, + label: @Composable (() -> Unit)? = null, ) { val context = LocalContext.current val focusRequester = remember { FocusRequester() } - var phoneNumber by rememberSaveable(initialPhoneNumber) { mutableStateOf(initialPhoneNumber.orEmpty()) } + var phoneNumber by rememberSaveable(initialPhoneNumber) { + mutableStateOf(initialPhoneNumber.orEmpty()) + } val keyboardController = LocalSoftwareKeyboardController.current - val fallbackCountry = countryDataMap[fallbackCountryCode] - ?: unitedStates - val initialCountry: CountryData? = countryDataMapPhoneCode[initialCountryPhoneCode] - ?: countryDataMap[initialCountryCode] - var langAndCode by rememberSaveable( + + var country: CountryData by rememberSaveable( context, - fallbackCountry, - initialCountry, + initialCountryPhoneCode, + initialCountryIsoCode, ) { - mutableStateOf(getDefaultCountryAndPhoneCode(context, fallbackCountry, initialCountry)) + if (initialPhoneNumber?.startsWith("+") == true) { + Log.e(TAG, "initialPhoneNumber must not include the country code") + } + if (initialCountryPhoneCode?.startsWith("+") != true) { + Log.e(TAG, "initialCountryPhoneCode must start with +") + } + val initialCountry: CountryData? = initialCountryPhoneCode?.let { + getCountryFromPhoneCode(it, context) + } ?: CountryData.entries.firstOrNull { it.countryIso == initialCountryIsoCode } + mutableStateOf( + initialCountry ?: CountryData.isoMap[getUserIsoCode(context)] ?: fallbackCountry, + ) } - val phoneNumberTransformation = remember(langAndCode) { - PhoneNumberTransformation( - countryDataMap.getOrDefault(langAndCode.first, fallbackCountry).countryCode.uppercase(), - context, - ) + val phoneNumberTransformation = remember(country) { + PhoneNumberTransformation(country.countryIso, context) } val validatePhoneNumber = remember(context) { ValidatePhoneNumber(context) } - var isNumberValid: Boolean by rememberSaveable(langAndCode.second, phoneNumber) { + var isNumberValid: Boolean by rememberSaveable(country, phoneNumber) { mutableStateOf( validatePhoneNumber( - fullPhoneNumber = langAndCode.second + phoneNumber, + fullPhoneNumber = country.countryPhoneCode + phoneNumber, ), ) } @@ -137,9 +143,9 @@ fun TogiCountryCodePicker( onValueChange = { enteredPhoneNumber -> phoneNumber = phoneNumberTransformation.preFilter(enteredPhoneNumber) isNumberValid = validatePhoneNumber( - fullPhoneNumber = langAndCode.second + phoneNumber, + fullPhoneNumber = country.countryPhoneCode + phoneNumber, ) - onValueChange(langAndCode.second to phoneNumber, isNumberValid) + onValueChange(country.countryPhoneCode to phoneNumber, isNumberValid) }, modifier = modifier .fillMaxWidth() @@ -154,22 +160,20 @@ fun TogiCountryCodePicker( label = label, placeholder = { if (showPlaceholder) { - PlaceholderNumberHint(langAndCode, fallbackCountry) + PlaceholderNumberHint(country.countryIso) } }, leadingIcon = { TogiCodeDialog( - defaultSelectedCountry = countryDataMap.getOrDefault( - langAndCode.first, - fallbackCountry, - ), + modifier = Modifier.padding(DEFAULT_PADDING), + selectedCountry = country, includeOnly = includeOnly, onCountryChange = { countryData -> - langAndCode = countryData.countryCode to countryData.countryPhoneCode + country = countryData isNumberValid = validatePhoneNumber( - fullPhoneNumber = langAndCode.second + phoneNumber, + fullPhoneNumber = country.countryPhoneCode + phoneNumber, ) - onValueChange(langAndCode.second to phoneNumber, isNumberValid) + onValueChange(country.countryPhoneCode to phoneNumber, isNumberValid) }, textColor = colors.textColor(enabled = enabled).value, showCountryCode = showCountryCode, @@ -182,13 +186,21 @@ fun TogiCountryCodePicker( onClick = { phoneNumber = "" isNumberValid = false - onValueChange(langAndCode.second to phoneNumber, isNumberValid) + onValueChange(country.countryPhoneCode to phoneNumber, isNumberValid) }, ) { Icon( imageVector = it, contentDescription = "Clear", - tint = if (!isNumberValid) Color.Red else MaterialTheme.colors.onSurface, + tint = if (!isNumberValid) { + colors + .trailingIconColor(enabled = true, isError = true) + .value + } else { + colors + .trailingIconColor(enabled = true, isError = false) + .value + }, ) } } @@ -213,16 +225,10 @@ fun TogiCountryCodePicker( } @Composable -private fun PlaceholderNumberHint( - langAndCode: Pair, - fallbackCountry: CountryData, -) { +private fun PlaceholderNumberHint(countryIso: Iso31661alpha2) { Text( text = stringResource( - id = numberHint.getOrDefault( - countryDataMap.getOrDefault(langAndCode.first, fallbackCountry).countryCode, - R.string.unknown, - ), + id = numberHint.getOrDefault(countryIso, R.string.unknown), ), ) } diff --git a/ccp/src/main/java/com/togitech/ccp/data/CountryData.kt b/ccp/src/main/java/com/togitech/ccp/data/CountryData.kt index b710fc6..138c86d 100644 --- a/ccp/src/main/java/com/togitech/ccp/data/CountryData.kt +++ b/ccp/src/main/java/com/togitech/ccp/data/CountryData.kt @@ -1,10 +1,253 @@ package com.togitech.ccp.data -@Suppress("UnusedPrivateMember") -internal data class CountryData( - private val cCodes: String, - val countryPhoneCode: String, - private val cNames: String, // bookkeeping only -) { - val countryCode: String = cCodes.lowercase() +typealias Iso31661alpha2 = String +typealias PhoneCode = String + +enum class CountryData(val countryIso: Iso31661alpha2, val countryPhoneCode: PhoneCode) { + Andorra("AD", "+376"), + UnitedArabEmirates("AE", "+971"), + Afghanistan("AF", "+93"), + AntiguaAndBarbuda("AG", "+1"), + Anguilla("AI", "+1"), + Albania("AL", "+355"), + Armenia("AM", "+374"), + Angola("AO", "+244"), + Antarctica("AQ", "+672"), + Argentina("AR", "+54"), + AmericanSamoa("AS", "+1"), + Austria("AT", "+43"), + Australia("AU", "+61"), + Aruba("AW", "+297"), + AlandIslands("AX", "+358"), + Azerbaijan("AZ", "+994"), + BosniaAndHerzegovina("BA", "+387"), + Barbados("BB", "+1"), + Bangladesh("BD", "+880"), + Belgium("BE", "+32"), + BurkinaFaso("BF", "+226"), + Bulgaria("BG", "+359"), + Bahrain("BH", "+973"), + Burundi("BI", "+257"), + Benin("BJ", "+229"), + SaintBarthelemy("BL", "+590"), + Bermuda("BM", "+1"), + BruneiDarussalam("BN", "+673"), + Bolivia("BO", "+591"), + Brazil("BR", "+55"), + Bahamas("BS", "+1"), + Bhutan("BT", "+975"), + Botswana("BW", "+267"), + Belarus("BY", "+375"), + Belize("BZ", "+501"), + Canada("CA", "+1"), + CocosKeelingIslands("CC", "+61"), + CongoKinshasaDRC("CD", "+243"), + CentralAfricanRepublic("CF", "+236"), + CongoBrazzavilleRepublic("CG", "+242"), + Switzerland("CH", "+41"), + CoteDivoire("CI", "+225"), + CookIslands("CK", "+682"), + Chile("CL", "+56"), + Cameroon("CM", "+237"), + China("CN", "+86"), + Colombia("CO", "+57"), + CostaRica("CR", "+506"), + Cuba("CU", "+53"), + CapeVerde("CV", "+238"), + Curacao("CW", "+599"), + Christmas("CX", "+61"), + CyprusIsland("CY", "+357"), + CzechRepublic("CZ", "+420"), + Germany("DE", "+49"), + Djibouti("DJ", "+253"), + Denmark("DK", "+45"), + Dominica("DM", "+1"), + DominicanRepublic("DO", "+1"), + Algeria("DZ", "+213"), + Ecuador("EC", "+593"), + Estonia("EE", "+372"), + Egypt("EG", "+20"), + Eritrea("ER", "+291"), + Spain("ES", "+34"), + Ethiopia("ET", "+251"), + Finland("FI", "+358"), + Fiji("FJ", "+679"), + FalklandIslands("FK", "+500"), + Micronesia("FM", "+691"), + FaroeIslands("FO", "+298"), + France("FR", "+33"), + Gabon("GA", "+241"), + UnitedKingdom("GB", "+44"), + Grenada("GD", "+1"), + Georgia("GE", "+995"), + FrenchGuyana("GF", "+594"), + Ghana("GH", "+233"), + Gibraltar("GI", "+350"), + Greenland("GL", "+299"), + Gambia("GM", "+220"), + Guinea("GN", "+224"), + Guadeloupe("GP", "+590"), + EquatorialGuinea("GQ", "+240"), + Greece("GR", "+30"), + Guatemala("GT", "+502"), + Guam("GU", "+1"), + GuineaBissau("GW", "+245"), + Guyana("GY", "+592"), + HongKong("HK", "+852"), + Honduras("HN", "+504"), + Croatia("HR", "+385"), + Haiti("HT", "+509"), + Hungary("HU", "+36"), + Indonesia("ID", "+62"), + Ireland("IE", "+353"), + Israel("IL", "+972"), + IsleOfMan("IM", "+44"), + India("IN", "+91"), + BritishIndianOceanTerritory("IO", "+246"), + Iraq("IQ", "+964"), + Iran("IR", "+98"), + Iceland("IS", "+354"), + Italy("IT", "+39"), + Jersey("JE", "+44"), + Jamaica("JM", "+1"), + Jordan("JO", "+962"), + Japan("JP", "+81"), + Kenya("KE", "+254"), + Kyrgyzstan("KG", "+996"), + Cambodia("KH", "+855"), + Kiribati("KI", "+686"), + Comoros("KM", "+269"), + SaintKittsAndNevis("KN", "+1"), + NorthKorea("KP", "+850"), + SouthKorea("KR", "+82"), + Kuwait("KW", "+965"), + CaymanIslands("KY", "+1"), + Kazakhstan("KZ", "+7"), + Lao("LA", "+856"), + Lebanon("LB", "+961"), + SaintLucia("LC", "+1"), + Liechtenstein("LI", "+423"), + SriLanka("LK", "+94"), + Liberia("LR", "+231"), + Lesotho("LS", "+266"), + Lithuania("LT", "+370"), + Luxembourg("LU", "+352"), + Latvia("LV", "+371"), + Libya("LY", "+218"), + Morocco("MA", "+212"), + Monaco("MC", "+377"), + Moldova("MD", "+373"), + Montenegro("ME", "+382"), + SaintMartin("MF", "+590"), + Madagascar("MG", "+261"), + MarshallIslands("MH", "+692"), + NorthMacedonia("MK", "+389"), + Mali("ML", "+223"), + Myanmar("MM", "+95"), + Mongolia("MN", "+976"), + Macau("MO", "+853"), + NorthernMarianaIslands("MP", "+1"), + Martinique("MQ", "+596"), + Mauritania("MR", "+222"), + Montserrat("MS", "+1"), + Malta("MT", "+356"), + Mauritius("MU", "+230"), + Maldives("MV", "+960"), + Malawi("MW", "+265"), + Mexico("MX", "+52"), + Malaysia("MY", "+60"), + Mozambique("MZ", "+258"), + Namibia("NA", "+264"), + NewCaledonia("NC", "+687"), + Niger("NE", "+227"), + NorfolkIslands("NF", "+672"), + Nigeria("NG", "+234"), + Nicaragua("NI", "+505"), + Netherlands("NL", "+31"), + Norway("NO", "+47"), + Nepal("NP", "+977"), + Nauru("NR", "+674"), + Niue("NU", "+683"), + NewZealand("NZ", "+64"), + Oman("OM", "+968"), + Panama("PA", "+507"), + Peru("PE", "+51"), + FrenchPolynesia("PF", "+689"), + PapuaNewGuinea("PG", "+675"), + Philippines("PH", "+63"), + Pakistan("PK", "+92"), + Poland("PL", "+48"), + SaintPierreAndMiquelon("PM", "+508"), + PitcairnIslands("PN", "+870"), + PuertoRico("PR", "+1"), + Palestine("PS", "+970"), + Portugal("PT", "+351"), + Palau("PW", "+680"), + Paraguay("PY", "+595"), + Qatar("QA", "+974"), + Reunion("RE", "+262"), + Romania("RO", "+40"), + Serbia("RS", "+381"), + RussianFederation("RU", "+7"), + Rwanda("RW", "+250"), + SaudiArabia("SA", "+966"), + SolomonIslands("SB", "+677"), + Seychelles("SC", "+248"), + Sudan("SD", "+249"), + Sweden("SE", "+46"), + Singapore("SG", "+65"), + SaintHelena("SH", "+290"), + Slovenia("SI", "+386"), + Slovakia("SK", "+421"), + SierraLeone("SL", "+232"), + SanMarino("SM", "+378"), + Senegal("SN", "+221"), + Somalia("SO", "+252"), + Suriname("SR", "+597"), + SouthSudan("SS", "+211"), + SaoTomeAndPrincipe("ST", "+239"), + ElSalvador("SV", "+503"), + SintMaarten("SX", "+1"), + Syria("SY", "+963"), + Swaziland("SZ", "+268"), + TurksAndCaicosIslands("TC", "+1"), + Chad("TD", "+235"), + Togo("TG", "+228"), + Thailand("TH", "+66"), + Tajikistan("TJ", "+992"), + Tokelau("TK", "+690"), + TimorLeste("TL", "+670"), + Turkmenistan("TM", "+993"), + Tunisia("TN", "+216"), + Tonga("TO", "+676"), + Turkey("TR", "+90"), + TrinidadAndTobago("TT", "+1"), + Tuvalu("TV", "+688"), + Taiwan("TW", "+886"), + Tanzania("TZ", "+255"), + Ukraine("UA", "+380"), + Uganda("UG", "+256"), + UnitedStates("US", "+1"), + Uruguay("UY", "+598"), + Uzbekistan("UZ", "+998"), + HolySee("VA", "+379"), + SaintVincentAndTheGrenadines("VC", "+1"), + Venezuela("VE", "+58"), + BritishVirginIslands("VG", "+1"), + USVirginIslands("VI", "+1"), + Vietnam("VN", "+84"), + Vanuatu("VU", "+678"), + WallisAndFutuna("WF", "+681"), + Samoa("WS", "+685"), + Kosovo("XK", "+383"), + Yemen("YE", "+967"), + Mayotte("YT", "+262"), + SouthAfrica("ZA", "+27"), + Zambia("ZM", "+260"), + Zimbabwe("ZW", "+263"), + ; + + companion object { + val isoMap: Map = entries.associateBy { it.countryIso } + } } diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/CountryCodeUtils.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/CountryCodeUtils.kt new file mode 100644 index 0000000..3c7ad8c --- /dev/null +++ b/ccp/src/main/java/com/togitech/ccp/data/utils/CountryCodeUtils.kt @@ -0,0 +1,41 @@ +package com.togitech.ccp.data.utils + +import android.content.Context +import android.telephony.TelephonyManager +import com.togitech.ccp.data.CountryData +import com.togitech.ccp.data.Iso31661alpha2 +import com.togitech.ccp.data.PhoneCode + +private const val EMOJI_UNICODE = 0x1F1A5 + +internal fun getCountryFromPhoneCode(code: PhoneCode, context: Context): CountryData? { + val countries = CountryData.entries.filter { it.countryPhoneCode == code } + return when (countries.size) { + 0 -> null + 1 -> countries.firstOrNull() + else -> { + val userIso = getUserIsoCode(context) + countries.firstOrNull { it.countryIso == userIso } + ?: if (code == "+1") CountryData.UnitedStates else countries.firstOrNull() + } + } +} + +@Suppress("SwallowedException", "TooGenericExceptionCaught", "Deprecation") +internal fun getUserIsoCode(context: Context): Iso31661alpha2 = try { + val telephonyManager = context.telephonyManager + telephonyManager?.networkCountryIso ?: telephonyManager?.simCountryIso +} catch (ex: Exception) { + null +}.takeIf { !it.isNullOrBlank() } ?: context.resources.configuration.locale.country + +val CountryData.emojiFlag: String get() = countryCodeToEmojiFlag(countryIso) + +fun countryCodeToEmojiFlag(countryCode: Iso31661alpha2): String = + countryCode + .uppercase() + .map { char -> Character.codePointAt("$char", 0) + EMOJI_UNICODE } + .joinToString("") { String(Character.toChars(it)) } + +private val Context.telephonyManager: TelephonyManager? + get() = getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/CountryNameMap.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/CountryNameMap.kt new file mode 100644 index 0000000..95abc49 --- /dev/null +++ b/ccp/src/main/java/com/togitech/ccp/data/utils/CountryNameMap.kt @@ -0,0 +1,249 @@ +package com.togitech.ccp.data.utils + +import com.togitech.ccp.R +import com.togitech.ccp.data.Iso31661alpha2 + +internal val countryNames: Map = mapOf( + "AD" to R.string.andorra, + "AE" to R.string.united_arab_emirates, + "AF" to R.string.afghanistan, + "AG" to R.string.antigua_and_barbuda, + "AI" to R.string.anguilla, + "AL" to R.string.albania, + "AM" to R.string.armenia, + "AO" to R.string.angola, + "AQ" to R.string.antarctica, + "AR" to R.string.argentina, + "AS" to R.string.american_samoa, + "AT" to R.string.austria, + "AU" to R.string.australia, + "AW" to R.string.aruba, + "AX" to R.string.aland_islands, + "AZ" to R.string.azerbaijan, + "BA" to R.string.bosnia, + "BB" to R.string.barbados, + "BD" to R.string.bangladesh, + "BE" to R.string.belgium, + "BF" to R.string.burkina_faso, + "BG" to R.string.bulgaria, + "BH" to R.string.bahrain, + "BI" to R.string.burundi, + "BJ" to R.string.benin, + "BL" to R.string.saint_barhelemy, + "BM" to R.string.bermuda, + "BN" to R.string.brunei_darussalam, + "BO" to R.string.bolivia, + "BR" to R.string.brazil, + "BS" to R.string.bahamas, + "BT" to R.string.bhutan, + "BW" to R.string.botswana, + "BY" to R.string.belarus, + "BZ" to R.string.belize, + "CA" to R.string.canada, + "CC" to R.string.cocos, + "CD" to R.string.congo_democratic, + "CF" to R.string.central_african, + "CG" to R.string.congo, + "CH" to R.string.switzerland, + "CI" to R.string.cote_dlvoire, + "CK" to R.string.cook_islands, + "CL" to R.string.chile, + "CM" to R.string.cameroon, + "CN" to R.string.china, + "CO" to R.string.colombia, + "CR" to R.string.costa_rica, + "CU" to R.string.cuba, + "CV" to R.string.cape_verde, + "CW" to R.string.curacao, + "CX" to R.string.christmas_island, + "CY" to R.string.cyprus, + "CZ" to R.string.czech_republic, + "DE" to R.string.germany, + "DJ" to R.string.djibouti, + "DK" to R.string.denmark, + "DM" to R.string.dominica, + "DO" to R.string.dominican_republic, + "DZ" to R.string.algeria, + "EC" to R.string.ecuador, + "EE" to R.string.estonia, + "EG" to R.string.egypt, + "ER" to R.string.eritrea, + "ES" to R.string.spain, + "ET" to R.string.ethiopia, + "FI" to R.string.finland, + "FJ" to R.string.fiji, + "FK" to R.string.falkland_islands, + "FM" to R.string.micronesia, + "FO" to R.string.faroe_islands, + "FR" to R.string.france, + "GA" to R.string.gabon, + "GB" to R.string.united_kingdom, + "GD" to R.string.grenada, + "GE" to R.string.georgia, + "GF" to R.string.french_guiana, + "GG" to R.string.guernsey, + "GH" to R.string.ghana, + "GI" to R.string.gibraltar, + "GL" to R.string.greenland, + "GM" to R.string.gambia, + "GN" to R.string.guinea, + "GP" to R.string.guadeloupe, + "GQ" to R.string.equatorial_guinea, + "GR" to R.string.greece, + "GT" to R.string.guatemala, + "GU" to R.string.guam, + "GW" to R.string.guinea_bissau, + "GY" to R.string.guyana, + "HK" to R.string.hong_kong, + "HN" to R.string.honduras, + "HR" to R.string.croatia, + "HT" to R.string.haiti, + "HU" to R.string.hungary, + "ID" to R.string.indonesia, + "IE" to R.string.ireland, + "IL" to R.string.israil, + "IM" to R.string.isle_of_man, + "IN" to R.string.india, + "IO" to R.string.british_indian_ocean, + "IQ" to R.string.iraq, + "IR" to R.string.iran, + "IS" to R.string.iceland, + "IT" to R.string.italia, + "JE" to R.string.jersey, + "JM" to R.string.jamaica, + "JO" to R.string.jordan, + "JP" to R.string.japan, + "KE" to R.string.kenya, + "KG" to R.string.kyrgyzstan, + "KH" to R.string.cambodia, + "KI" to R.string.kiribati, + "KM" to R.string.comoros, + "KN" to R.string.saint_kitts, + "KP" to R.string.north_korea, + "KR" to R.string.south_korea, + "KW" to R.string.kuwait, + "KY" to R.string.cayman_islands, + "KZ" to R.string.kazakhstan, + "LA" to R.string.laos, + "LB" to R.string.lebanon, + "LC" to R.string.saint_lucia, + "LI" to R.string.liechtenstein, + "LK" to R.string.siri_lanka, + "LR" to R.string.liberia, + "LS" to R.string.lesotho, + "LT" to R.string.lithuania, + "LU" to R.string.luxembourg, + "LV" to R.string.latvia, + "LY" to R.string.libya, + "MA" to R.string.morocco, + "MC" to R.string.monaco, + "MD" to R.string.moldova, + "ME" to R.string.montenegro, + "MF" to R.string.saint_martin, + "MG" to R.string.madagascar, + "MH" to R.string.marshall_islands, + "MK" to R.string.north_macedonia, + "ML" to R.string.mali, + "MM" to R.string.myanmar, + "MN" to R.string.mongolia, + "MO" to R.string.macau, + "MP" to R.string.northern_mariana, + "MQ" to R.string.martinique, + "MR" to R.string.mauritania, + "MS" to R.string.montserrat, + "MT" to R.string.malta, + "MU" to R.string.mauritius, + "MV" to R.string.maldives, + "MW" to R.string.malawi, + "MX" to R.string.mexico, + "MY" to R.string.malaysia, + "MZ" to R.string.mozambique, + "NA" to R.string.namibia, + "NC" to R.string.new_caledonia, + "NE" to R.string.niger, + "NF" to R.string.norfolk, + "NG" to R.string.nigeria, + "NI" to R.string.nicaragua, + "NL" to R.string.netherlands, + "NO" to R.string.norway, + "NP" to R.string.nepal, + "NR" to R.string.nauru, + "NU" to R.string.niue, + "NZ" to R.string.new_zealand, + "OM" to R.string.oman, + "PA" to R.string.panama, + "PE" to R.string.peru, + "PF" to R.string.french_polynesia, + "PG" to R.string.papua_new_guinea, + "PH" to R.string.philippines, + "PK" to R.string.pakistan, + "PL" to R.string.poland, + "PM" to R.string.saint_pierre, + "PN" to R.string.pitcairn, + "PR" to R.string.puerto_rico, + "PS" to R.string.state_of_palestine, + "PT" to R.string.portugal, + "PW" to R.string.palau, + "PY" to R.string.paraguay, + "QA" to R.string.qatar, + "RE" to R.string.reunion, + "RO" to R.string.romania, + "RS" to R.string.serbia, + "RU" to R.string.russia, + "RW" to R.string.rwanda, + "SA" to R.string.saudi_arabia, + "SB" to R.string.solomon_islands, + "SC" to R.string.seychelles, + "SD" to R.string.sudan, + "SE" to R.string.sweden, + "SG" to R.string.singapore, + "SH" to R.string.saint_helena, + "SI" to R.string.slovenia, + "SK" to R.string.slovakia, + "SL" to R.string.sierra_leone, + "SM" to R.string.san_marino, + "SN" to R.string.senegal, + "SO" to R.string.somalia, + "SR" to R.string.suriname, + "SS" to R.string.south_sudan, + "ST" to R.string.sao_tome, + "SV" to R.string.el_salvador, + "SX" to R.string.sint_maarten, + "SY" to R.string.syria, + "SZ" to R.string.swaziland, + "TC" to R.string.turks_and_caicos, + "TD" to R.string.chad, + "TG" to R.string.togo, + "TH" to R.string.thailand, + "TJ" to R.string.taijikistan, + "TK" to R.string.tokelau, + "TL" to R.string.timor_leste, + "TM" to R.string.turkmenistan, + "TN" to R.string.tunisia, + "TO" to R.string.tonga, + "TR" to R.string.turkey, + "TT" to R.string.trinidad_and_tobago, + "TV" to R.string.tuvalu, + "TW" to R.string.taiwan, + "TZ" to R.string.tazmania, + "UA" to R.string.ukraine, + "UG" to R.string.uganda, + "US" to R.string.united_states_america, + "UY" to R.string.uruguay, + "UZ" to R.string.uzbekistan, + "VA" to R.string.holy_see, + "VC" to R.string.saint_vincent, + "VE" to R.string.venezuela, + "VG" to R.string.virgin_islands, + "VI" to R.string.virgin_islands_us, + "VN" to R.string.vietnam, + "VU" to R.string.vanuatu, + "WF" to R.string.wallis_and_futuna, + "WS" to R.string.samoa, + "XK" to R.string.kosovo, + "YE" to R.string.yemen, + "YT" to R.string.mayotte, + "ZA" to R.string.south_africa, + "ZM" to R.string.zambia, + "ZW" to R.string.zimbabwe, +) diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryName.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryName.kt deleted file mode 100644 index 37b5dfe..0000000 --- a/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryName.kt +++ /dev/null @@ -1,248 +0,0 @@ -package com.togitech.ccp.data.utils - -import com.togitech.ccp.R - -internal val countryNames: Map = mapOf( - "ad" to R.string.andorra, - "ae" to R.string.united_arab_emirates, - "af" to R.string.afghanistan, - "ag" to R.string.antigua_and_barbuda, - "ai" to R.string.anguilla, - "al" to R.string.albania, - "am" to R.string.armenia, - "ao" to R.string.angola, - "aq" to R.string.antarctica, - "ar" to R.string.argentina, - "as" to R.string.american_samoa, - "at" to R.string.austria, - "au" to R.string.australia, - "aw" to R.string.aruba, - "ax" to R.string.aland_islands, - "az" to R.string.azerbaijan, - "ba" to R.string.bosnia, - "bb" to R.string.barbados, - "bd" to R.string.bangladesh, - "be" to R.string.belgium, - "bf" to R.string.burkina_faso, - "bg" to R.string.bulgaria, - "bh" to R.string.bahrain, - "bi" to R.string.burundi, - "bj" to R.string.benin, - "bl" to R.string.saint_barhelemy, - "bm" to R.string.bermuda, - "bn" to R.string.brunei_darussalam, - "bo" to R.string.bolivia, - "br" to R.string.brazil, - "bs" to R.string.bahamas, - "bt" to R.string.bhutan, - "bw" to R.string.botswana, - "by" to R.string.belarus, - "bz" to R.string.belize, - "ca" to R.string.canada, - "cc" to R.string.cocos, - "cd" to R.string.congo_democratic, - "cf" to R.string.central_african, - "cg" to R.string.congo, - "ch" to R.string.switzerland, - "ci" to R.string.cote_dlvoire, - "ck" to R.string.cook_islands, - "cl" to R.string.chile, - "cm" to R.string.cameroon, - "cn" to R.string.china, - "co" to R.string.colombia, - "cr" to R.string.costa_rica, - "cu" to R.string.cuba, - "cv" to R.string.cape_verde, - "cw" to R.string.curacao, - "cx" to R.string.christmas_island, - "cy" to R.string.cyprus, - "cz" to R.string.czech_republic, - "de" to R.string.germany, - "dj" to R.string.djibouti, - "dk" to R.string.denmark, - "dm" to R.string.dominica, - "do" to R.string.dominican_republic, - "dz" to R.string.algeria, - "ec" to R.string.ecuador, - "ee" to R.string.estonia, - "eg" to R.string.egypt, - "er" to R.string.eritrea, - "es" to R.string.spain, - "et" to R.string.ethiopia, - "fi" to R.string.finland, - "fj" to R.string.fiji, - "fk" to R.string.falkland_islands, - "fm" to R.string.micronesia, - "fo" to R.string.faroe_islands, - "fr" to R.string.france, - "ga" to R.string.gabon, - "gb" to R.string.united_kingdom, - "gd" to R.string.grenada, - "ge" to R.string.georgia, - "gf" to R.string.french_guiana, - "gg" to R.string.guernsey, - "gh" to R.string.ghana, - "gi" to R.string.gibraltar, - "gl" to R.string.greenland, - "gm" to R.string.gambia, - "gn" to R.string.guinea, - "gp" to R.string.guadeloupe, - "gq" to R.string.equatorial_guinea, - "gr" to R.string.greece, - "gt" to R.string.guatemala, - "gu" to R.string.guam, - "gw" to R.string.guinea_bissau, - "gy" to R.string.guyana, - "hk" to R.string.hong_kong, - "hn" to R.string.honduras, - "hr" to R.string.croatia, - "ht" to R.string.haiti, - "hu" to R.string.hungary, - "id" to R.string.indonesia, - "ie" to R.string.ireland, - "il" to R.string.israil, - "im" to R.string.isle_of_man, - "in" to R.string.india, - "io" to R.string.british_indian_ocean, - "iq" to R.string.iraq, - "ir" to R.string.iran, - "is" to R.string.iceland, - "it" to R.string.italia, - "je" to R.string.jersey, - "jm" to R.string.jamaica, - "jo" to R.string.jordan, - "jp" to R.string.japan, - "ke" to R.string.kenya, - "kg" to R.string.kyrgyzstan, - "kh" to R.string.cambodia, - "ki" to R.string.kiribati, - "km" to R.string.comoros, - "kn" to R.string.saint_kitts, - "kp" to R.string.north_korea, - "kr" to R.string.south_korea, - "kw" to R.string.kuwait, - "ky" to R.string.cayman_islands, - "kz" to R.string.kazakhstan, - "la" to R.string.laos, - "lb" to R.string.lebanon, - "lc" to R.string.saint_lucia, - "li" to R.string.liechtenstein, - "lk" to R.string.siri_lanka, - "lr" to R.string.liberia, - "ls" to R.string.lesotho, - "lt" to R.string.lithuania, - "lu" to R.string.luxembourg, - "lv" to R.string.latvia, - "ly" to R.string.libya, - "ma" to R.string.morocco, - "mc" to R.string.monaco, - "md" to R.string.moldova, - "me" to R.string.montenegro, - "mf" to R.string.saint_martin, - "mg" to R.string.madagascar, - "mh" to R.string.marshall_islands, - "mk" to R.string.north_macedonia, - "ml" to R.string.mali, - "mm" to R.string.myanmar, - "mn" to R.string.mongolia, - "mo" to R.string.macau, - "mp" to R.string.northern_mariana, - "mq" to R.string.martinique, - "mr" to R.string.mauritania, - "ms" to R.string.montserrat, - "mt" to R.string.malta, - "mu" to R.string.mauritius, - "mv" to R.string.maldives, - "mw" to R.string.malawi, - "mx" to R.string.mexico, - "my" to R.string.malaysia, - "mz" to R.string.mozambique, - "na" to R.string.namibia, - "nc" to R.string.new_caledonia, - "ne" to R.string.niger, - "nf" to R.string.norfolk, - "ng" to R.string.nigeria, - "ni" to R.string.nicaragua, - "nl" to R.string.netherlands, - "no" to R.string.norway, - "np" to R.string.nepal, - "nr" to R.string.nauru, - "nu" to R.string.niue, - "nz" to R.string.new_zealand, - "om" to R.string.oman, - "pa" to R.string.panama, - "pe" to R.string.peru, - "pf" to R.string.french_polynesia, - "pg" to R.string.papua_new_guinea, - "ph" to R.string.philippines, - "pk" to R.string.pakistan, - "pl" to R.string.poland, - "pm" to R.string.saint_pierre, - "pn" to R.string.pitcairn, - "pr" to R.string.puerto_rico, - "ps" to R.string.state_of_palestine, - "pt" to R.string.portugal, - "pw" to R.string.palau, - "py" to R.string.paraguay, - "qa" to R.string.qatar, - "re" to R.string.reunion, - "ro" to R.string.romania, - "rs" to R.string.serbia, - "ru" to R.string.russia, - "rw" to R.string.rwanda, - "sa" to R.string.saudi_arabia, - "sb" to R.string.solomon_islands, - "sc" to R.string.seychelles, - "sd" to R.string.sudan, - "se" to R.string.sweden, - "sg" to R.string.singapore, - "sh" to R.string.saint_helena, - "si" to R.string.slovenia, - "sk" to R.string.slovakia, - "sl" to R.string.sierra_leone, - "sm" to R.string.san_marino, - "sn" to R.string.senegal, - "so" to R.string.somalia, - "sr" to R.string.suriname, - "ss" to R.string.south_sudan, - "st" to R.string.sao_tome, - "sv" to R.string.el_salvador, - "sx" to R.string.sint_maarten, - "sy" to R.string.syria, - "sz" to R.string.swaziland, - "tc" to R.string.turks_and_caicos, - "td" to R.string.chad, - "tg" to R.string.togo, - "th" to R.string.thailand, - "tj" to R.string.taijikistan, - "tk" to R.string.tokelau, - "tl" to R.string.timor_leste, - "tm" to R.string.turkmenistan, - "tn" to R.string.tunisia, - "to" to R.string.tonga, - "tr" to R.string.turkey, - "tt" to R.string.trinidad_and_tobago, - "tv" to R.string.tuvalu, - "tw" to R.string.taiwan, - "tz" to R.string.tazmania, - "ua" to R.string.ukraine, - "ug" to R.string.uganda, - "us" to R.string.united_states_america, - "uy" to R.string.uruguay, - "uz" to R.string.uzbekistan, - "va" to R.string.holy_see, - "vc" to R.string.saint_vincent, - "ve" to R.string.venezuela, - "vg" to R.string.virgin_islands, - "vi" to R.string.virgin_islands_us, - "vn" to R.string.vietnam, - "vu" to R.string.vanuatu, - "wf" to R.string.wallis_and_futuna, - "ws" to R.string.samoa, - "xk" to R.string.kosovo, - "ye" to R.string.yemen, - "yt" to R.string.mayotte, - "za" to R.string.south_africa, - "zm" to R.string.zambia, - "zw" to R.string.zimbabwe, -) diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryPhoneCode.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryPhoneCode.kt deleted file mode 100644 index d373dff..0000000 --- a/ccp/src/main/java/com/togitech/ccp/data/utils/GetCountryPhoneCode.kt +++ /dev/null @@ -1,262 +0,0 @@ -package com.togitech.ccp.data.utils - -import com.togitech.ccp.data.CountryData - -internal val unitedStates: CountryData = CountryData( - cCodes = "us", - countryPhoneCode = "+1", - cNames = "United States", -) - -internal val getLibCountries: List = listOf( - CountryData("ad", "+376", "Andorra"), - CountryData("ae", "+971", "United Arab Emirates (UAE)"), - CountryData("af", "+93", "Afghanistan"), - CountryData("ag", "+1", "Antigua and Barbuda"), - CountryData("ai", "+1", "Anguilla"), - CountryData("al", "+355", "Albania"), - CountryData("am", "+374", "Armenia"), - CountryData("ao", "+244", "Angola"), - CountryData("aq", "+672", "Antarctica"), - CountryData("ar", "+54", "Argentina"), - CountryData("as", "+1", "American Samoa"), - CountryData("at", "+43", "Austria"), - CountryData("au", "+61", "Australia"), - CountryData("aw", "+297", "Aruba"), - CountryData("ax", "+358", "Åland Islands"), - CountryData("az", "+994", "Azerbaijan"), - CountryData("ba", "+387", "Bosnia And Herzegovina"), - CountryData("bb", "+1", "Barbados"), - CountryData("bd", "+880", "Bangladesh"), - CountryData("be", "+32", "Belgium"), - CountryData("bf", "+226", "Burkina Faso"), - CountryData("bg", "+359", "Bulgaria"), - CountryData("bh", "+973", "Bahrain"), - CountryData("bi", "+257", "Burundi"), - CountryData("bj", "+229", "Benin"), - CountryData("bl", "+590", "Saint Barthélemy"), - CountryData("bm", "+1", "Bermuda"), - CountryData("bn", "+673", "Brunei Darussalam"), - CountryData("bo", "+591", "Bolivia, Plurinational State Of"), - CountryData("br", "+55", "Brazil"), - CountryData("bs", "+1", "Bahamas"), - CountryData("bt", "+975", "Bhutan"), - CountryData("bw", "+267", "Botswana"), - CountryData("by", "+375", "Belarus"), - CountryData("bz", "+501", "Belize"), - CountryData("ca", "+1", "Canada"), - CountryData("cc", "+61", "Cocos (keeling) Islands"), - CountryData("cd", "+243", "Congo, The Democratic Republic Of The"), - CountryData("cf", "+236", "Central African Republic"), - CountryData("cg", "+242", "Congo"), - CountryData("ch", "+41", "Switzerland"), - CountryData("ci", "+225", "Côte D'ivoire"), - CountryData("ck", "+682", "Cook Islands"), - CountryData("cl", "+56", "Chile"), - CountryData("cm", "+237", "Cameroon"), - CountryData("cn", "+86", "China"), - CountryData("co", "+57", "Colombia"), - CountryData("cr", "+506", "Costa Rica"), - CountryData("cu", "+53", "Cuba"), - CountryData("cv", "+238", "Cape Verde"), - CountryData("cw", "+599", "Curaçao"), - CountryData("cx", "+61", "Christmas Island"), - CountryData("cy", "+357", "Cyprus"), - CountryData("cz", "+420", "Czech Republic"), - CountryData("de", "+49", "Germany"), - CountryData("dj", "+253", "Djibouti"), - CountryData("dk", "+45", "Denmark"), - CountryData("dm", "+1", "Dominica"), - CountryData("do", "+1", "Dominican Republic"), - CountryData("dz", "+213", "Algeria"), - CountryData("ec", "+593", "Ecuador"), - CountryData("ee", "+372", "Estonia"), - CountryData("eg", "+20", "Egypt"), - CountryData("er", "+291", "Eritrea"), - CountryData("es", "+34", "Spain"), - CountryData("et", "+251", "Ethiopia"), - CountryData("fi", "+358", "Finland"), - CountryData("fj", "+679", "Fiji"), - CountryData("fk", "+500", "Falkland Islands (malvinas)"), - CountryData("fm", "+691", "Micronesia, Federated States Of"), - CountryData("fo", "+298", "Faroe Islands"), - CountryData("fr", "+33", "France"), - CountryData("ga", "+241", "Gabon"), - CountryData("gb", "+44", "United Kingdom"), - CountryData("gd", "+1", "Grenada"), - CountryData("ge", "+995", "Georgia"), - CountryData("gf", "+594", "French Guyana"), - CountryData("gh", "+233", "Ghana"), - CountryData("gi", "+350", "Gibraltar"), - CountryData("gl", "+299", "Greenland"), - CountryData("gm", "+220", "Gambia"), - CountryData("gn", "+224", "Guinea"), - CountryData("gp", "+450", "Guadeloupe"), - CountryData("gq", "+240", "Equatorial Guinea"), - CountryData("gr", "+30", "Greece"), - CountryData("gt", "+502", "Guatemala"), - CountryData("gu", "+1", "Guam"), - CountryData("gw", "+245", "Guinea-bissau"), - CountryData("gy", "+592", "Guyana"), - CountryData("hk", "+852", "Hong Kong"), - CountryData("hn", "+504", "Honduras"), - CountryData("hr", "+385", "Croatia"), - CountryData("ht", "+509", "Haiti"), - CountryData("hu", "+36", "Hungary"), - CountryData("id", "+62", "Indonesia"), - CountryData("ie", "+353", "Ireland"), - CountryData("il", "+972", "Israel"), - CountryData("im", "+44", "Isle Of Man"), - CountryData("in", "+91", "India"), - CountryData("io", "+246", "British Indian Ocean Territory"), - CountryData("iq", "+964", "Iraq"), - CountryData("ir", "+98", "Iran, Islamic Republic Of"), - CountryData("is", "+354", "Iceland"), - CountryData("it", "+39", "Italy"), - CountryData("je", "+44", "Jersey "), - CountryData("jm", "+1", "Jamaica"), - CountryData("jo", "+962", "Jordan"), - CountryData("jp", "+81", "Japan"), - CountryData("ke", "+254", "Kenya"), - CountryData("kg", "+996", "Kyrgyzstan"), - CountryData("kh", "+855", "Cambodia"), - CountryData("ki", "+686", "Kiribati"), - CountryData("km", "+269", "Comoros"), - CountryData("kn", "+1", "Saint Kitts and Nevis"), - CountryData("kp", "+850", "North Korea"), - CountryData("kr", "+82", "South Korea"), - CountryData("kw", "+965", "Kuwait"), - CountryData("ky", "+1", "Cayman Islands"), - CountryData("kz", "+7", "Kazakhstan"), - CountryData("la", "+856", "Lao People's Democratic Republic"), - CountryData("lb", "+961", "Lebanon"), - CountryData("lc", "+1", "Saint Lucia"), - CountryData("li", "+423", "Liechtenstein"), - CountryData("lk", "+94", "Sri Lanka"), - CountryData("lr", "+231", "Liberia"), - CountryData("ls", "+266", "Lesotho"), - CountryData("lt", "+370", "Lithuania"), - CountryData("lu", "+352", "Luxembourg"), - CountryData("lv", "+371", "Latvia"), - CountryData("ly", "+218", "Libya"), - CountryData("ma", "+212", "Morocco"), - CountryData("mc", "+377", "Monaco"), - CountryData("md", "+373", "Moldova, Republic Of"), - CountryData("me", "+382", "Montenegro"), - CountryData("mf", "+590", "Saint Martin"), - CountryData("mg", "+261", "Madagascar"), - CountryData("mh", "+692", "Marshall Islands"), - CountryData("mk", "+389", "Macedonia (FYROM)"), - CountryData("ml", "+223", "Mali"), - CountryData("mm", "+95", "Myanmar"), - CountryData("mn", "+976", "Mongolia"), - CountryData("mo", "+853", "Macau"), - CountryData("mp", "+1", "Northern Mariana Islands"), - CountryData("mq", "+596", "Martinique"), - CountryData("mr", "+222", "Mauritania"), - CountryData("ms", "+1", "Montserrat"), - CountryData("mt", "+356", "Malta"), - CountryData("mu", "+230", "Mauritius"), - CountryData("mv", "+960", "Maldives"), - CountryData("mw", "+265", "Malawi"), - CountryData("mx", "+52", "Mexico"), - CountryData("my", "+60", "Malaysia"), - CountryData("mz", "+258", "Mozambique"), - CountryData("na", "+264", "Namibia"), - CountryData("nc", "+687", "New Caledonia"), - CountryData("ne", "+227", "Niger"), - CountryData("nf", "+672", "Norfolk Islands"), - CountryData("ng", "+234", "Nigeria"), - CountryData("ni", "+505", "Nicaragua"), - CountryData("nl", "+31", "Netherlands"), - CountryData("no", "+47", "Norway"), - CountryData("np", "+977", "Nepal"), - CountryData("nr", "+674", "Nauru"), - CountryData("nu", "+683", "Niue"), - CountryData("nz", "+64", "New Zealand"), - CountryData("om", "+968", "Oman"), - CountryData("pa", "+507", "Panama"), - CountryData("pe", "+51", "Peru"), - CountryData("pf", "+689", "French Polynesia"), - CountryData("pg", "+675", "Papua New Guinea"), - CountryData("ph", "+63", "Philippines"), - CountryData("pk", "+92", "Pakistan"), - CountryData("pl", "+48", "Poland"), - CountryData("pm", "+508", "Saint Pierre And Miquelon"), - CountryData("pn", "+870", "Pitcairn Islands"), - CountryData("pr", "+1", "Puerto Rico"), - CountryData("ps", "+970", "Palestine"), - CountryData("pt", "+351", "Portugal"), - CountryData("pw", "+680", "Palau"), - CountryData("py", "+595", "Paraguay"), - CountryData("qa", "+974", "Qatar"), - CountryData("re", "+262", "Réunion"), - CountryData("ro", "+40", "Romania"), - CountryData("rs", "+381", "Serbia"), - CountryData("ru", "+7", "Russian Federation"), - CountryData("rw", "+250", "Rwanda"), - CountryData("sa", "+966", "Saudi Arabia"), - CountryData("sb", "+677", "Solomon Islands"), - CountryData("sc", "+248", "Seychelles"), - CountryData("sd", "+249", "Sudan"), - CountryData("se", "+46", "Sweden"), - CountryData("sg", "+65", "Singapore"), - CountryData("sh", "+290", "Saint Helena, Ascension And Tristan Da Cunha"), - CountryData("si", "+386", "Slovenia"), - CountryData("sk", "+421", "Slovakia"), - CountryData("sl", "+232", "Sierra Leone"), - CountryData("sm", "+378", "San Marino"), - CountryData("sn", "+221", "Senegal"), - CountryData("so", "+252", "Somalia"), - CountryData("sr", "+597", "Suriname"), - CountryData("ss", "+211", "South Sudan"), - CountryData("st", "+239", "Sao Tome And Principe"), - CountryData("sv", "+503", "El Salvador"), - CountryData("sx", "+1", "Sint Maarten"), - CountryData("sy", "+963", "Syrian Arab Republic"), - CountryData("sz", "+268", "Swaziland"), - CountryData("tc", "+1", "Turks and Caicos Islands"), - CountryData("td", "+235", "Chad"), - CountryData("tg", "+228", "Togo"), - CountryData("th", "+66", "Thailand"), - CountryData("tj", "+992", "Tajikistan"), - CountryData("tk", "+690", "Tokelau"), - CountryData("tl", "+670", "Timor-leste"), - CountryData("tm", "+993", "Turkmenistan"), - CountryData("tn", "+216", "Tunisia"), - CountryData("to", "+676", "Tonga"), - CountryData("tr", "+90", "Turkey"), - CountryData("tt", "+1", "Trinidad & Tobago"), - CountryData("tv", "+688", "Tuvalu"), - CountryData("tw", "+886", "Taiwan"), - CountryData("tz", "+255", "Tanzania, United Republic Of"), - CountryData("ua", "+380", "Ukraine"), - CountryData("ug", "+256", "Uganda"), - unitedStates, - CountryData("uy", "+598", "Uruguay"), - CountryData("uz", "+998", "Uzbekistan"), - CountryData("va", "+379", "Holy See (vatican City State)"), - CountryData("vc", "+1", "Saint Vincent & The Grenadines"), - CountryData("ve", "+58", "Venezuela, Bolivarian Republic Of"), - CountryData("vg", "+1", "British Virgin Islands"), - CountryData("vi", "+1", "US Virgin Islands"), - CountryData("vn", "+84", "Vietnam"), - CountryData("vu", "+678", "Vanuatu"), - CountryData("wf", "+681", "Wallis And Futuna"), - CountryData("ws", "4685", "Samoa"), - CountryData("xk", "+383", "Kosovo"), - CountryData("ye", "+967", "Yemen"), - CountryData("yt", "+262", "Mayotte"), - CountryData("za", "+27", "South Africa"), - CountryData("zm", "+260", "Zambia"), - CountryData("zw", "+263", "Zimbabwe"), -) - -internal val countryDataMap: Map = - getLibCountries.associateBy { it.countryCode } - -/** - * Retrieve Country Data using country phone code. - */ -internal val countryDataMapPhoneCode: Map = - getLibCountries.associateBy { it.countryPhoneCode } diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/GetNumberHint.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/GetNumberHint.kt deleted file mode 100644 index 13b212e..0000000 --- a/ccp/src/main/java/com/togitech/ccp/data/utils/GetNumberHint.kt +++ /dev/null @@ -1,249 +0,0 @@ -package com.togitech.ccp.data.utils - -import com.togitech.ccp.R - -@Suppress("LongMethod", "CyclomaticComplexMethod") -val numberHint: Map = mapOf( - "ad" to R.string.andorra_hint, - "ae" to R.string.united_arab_emirates_hint, - "af" to R.string.afganistan_hint, - "ag" to R.string.antigua_and_barbuda_hint, - "ai" to R.string.anguilla_hint, - "al" to R.string.albania_hint, - "am" to R.string.armenia_hint, - "ao" to R.string.angola_hint, - "aq" to R.string.antarctica_hint, - "ar" to R.string.argentina_hint, - "as" to R.string.american_samoa_hint, - "at" to R.string.austria_hint, - "au" to R.string.australia_hint, - "aw" to R.string.aruba_hint, - "ax" to R.string.aland_islands_hint, - "az" to R.string.azerbaijan_hint, - "ba" to R.string.bosnia_hint, - "bb" to R.string.barbados_hint, - "bd" to R.string.bangladesh_hint, - "be" to R.string.belgium_hint, - "bf" to R.string.burkina_faso_hint, - "bg" to R.string.bulgaria_hint, - "bh" to R.string.bahrain_hint, - "bi" to R.string.burundi_hint, - "bj" to R.string.benin_hint, - "bl" to R.string.saint_barhelemy_hint, - "bm" to R.string.bermuda_hint, - "bn" to R.string.brunei_darussalam_hint, - "bo" to R.string.bolivia_hint, - "br" to R.string.brazil_hint, - "bs" to R.string.bahamas_hint, - "bt" to R.string.bhutan_hint, - "bw" to R.string.botswana_hint, - "by" to R.string.belarus_hint, - "bz" to R.string.belize_hint, - "ca" to R.string.canada_hint, - "cc" to R.string.cocos_hint, - "cd" to R.string.congo_democratic_hint, - "cf" to R.string.central_african_hint, - "cg" to R.string.congo_hint, - "ch" to R.string.switzerland_hint, - "ci" to R.string.cote_dlvoire_hint, - "ck" to R.string.cook_islands_hint, - "cl" to R.string.chile_hint, - "cm" to R.string.cameroon_hint, - "cn" to R.string.china_hint, - "co" to R.string.colombia_hint, - "cr" to R.string.costa_rica_hint, - "cu" to R.string.cuba_hint, - "cv" to R.string.cape_verde_hint, - "cw" to R.string.curacao_hint, - "cx" to R.string.christmas_island_hint, - "cy" to R.string.cyprus_hint, - "cz" to R.string.czech_republic_hint, - "de" to R.string.germany_hint, - "dj" to R.string.djibouti_hint, - "dk" to R.string.denmark_hint, - "dm" to R.string.dominica_hint, - "do" to R.string.dominician_republic_hint, - "dz" to R.string.algeria_hint, - "ec" to R.string.ecuador_hint, - "ee" to R.string.estonia_hint, - "eg" to R.string.egypt_hint, - "er" to R.string.eritrea_hint, - "es" to R.string.spain_hint, - "et" to R.string.ethiopia_hint, - "fi" to R.string.finland_hint, - "fj" to R.string.fiji_hint, - "fk" to R.string.falkland_islands_hint, - "fm" to R.string.micro_hint, - "fo" to R.string.faroe_islands_hint, - "fr" to R.string.france_hint, - "ga" to R.string.gabon_hint, - "gb" to R.string.united_kingdom_hint, - "gd" to R.string.grenada_hint, - "ge" to R.string.georgia_hint, - "gf" to R.string.french_guyana_hint, - "gg" to R.string.guernsey_hint, - "gh" to R.string.ghana_hint, - "gi" to R.string.gibraltar_hint, - "gl" to R.string.greenland_hint, - "gm" to R.string.gambia_hint, - "gn" to R.string.guinea_hint, - "gp" to R.string.guadeloupe_hint, - "gq" to R.string.equatorial_guinea_hint, - "gr" to R.string.greece_hint, - "gt" to R.string.guatemala_hint, - "gu" to R.string.guam_hint, - "gw" to R.string.guinea_bissau_hint, - "gy" to R.string.guyana_hint, - "hk" to R.string.hong_kong_hint, - "hn" to R.string.honduras_hint, - "hr" to R.string.croatia_hint, - "ht" to R.string.haiti_hint, - "hu" to R.string.hungary_hint, - "id" to R.string.indonesia_hint, - "ie" to R.string.ireland_hint, - "il" to R.string.israil_hint, - "im" to R.string.isle_of_man, - "is" to R.string.iceland, - "in" to R.string.india_hint, - "io" to R.string.british_indian_ocean, - "iq" to R.string.iraq_hint, - "ir" to R.string.iran_hint, - "it" to R.string.italia_hint, - "je" to R.string.jersey_hint, - "jm" to R.string.jamaica_hint, - "jo" to R.string.jordan_hint, - "jp" to R.string.japan_hint, - "ke" to R.string.kenya_hint, - "kg" to R.string.kyrgyzstan_hint, - "kh" to R.string.cambodia_hint, - "ki" to R.string.kiribati, - "km" to R.string.comoros_hint, - "kn" to R.string.saint_kitts_hint, - "kp" to R.string.north_korea_hint, - "kr" to R.string.south_korea_hint, - "kw" to R.string.kuwait_hint, - "ky" to R.string.cayman_islands_hint, - "kz" to R.string.kazakhstan_hint, - "la" to R.string.laos_hint, - "lb" to R.string.lebanon_hint, - "lc" to R.string.saint_lucia_hint, - "li" to R.string.liechtenstein, - "lk" to R.string.siri_lanka_hint, - "lr" to R.string.liberia_hint, - "ls" to R.string.lesotho_hint, - "lt" to R.string.lithuania_hint, - "lu" to R.string.luxembourg_hint, - "lv" to R.string.latvia_hint, - "ly" to R.string.libya_hint, - "ma" to R.string.marocco_hint, - "mc" to R.string.monaco_hint, - "md" to R.string.moldova_hint, - "me" to R.string.montenegro_hint, - "mf" to R.string.saint_martin_hint, - "mg" to R.string.madagascar_hint, - "mh" to R.string.marshall_islands_hint, - "mk" to R.string.north_macedonia_hint, - "ml" to R.string.mali_hint, - "mm" to R.string.myanmar_hint, - "mn" to R.string.mongolia_hint, - "mo" to R.string.macau_hint, - "mp" to R.string.northern_mariana_hint, - "mq" to R.string.martinique_hint, - "mr" to R.string.mauriatana_hint, - "ms" to R.string.montserrat_hint, - "mt" to R.string.malta_hint, - "mu" to R.string.mauritius_hint, - "mv" to R.string.maldives_hint, - "mw" to R.string.malawi_hint, - "mx" to R.string.mexico_hint, - "my" to R.string.malaysia_hint, - "mz" to R.string.mozambique_hint, - "na" to R.string.namibia_hint, - "nc" to R.string.new_caledonia_hint, - "ne" to R.string.niger_hint, - "nf" to R.string.norfolk_hint, - "ng" to R.string.nigeria_hint, - "ni" to R.string.nicaragua, - "nl" to R.string.netherlands_hint, - "no" to R.string.norway_hint, - "np" to R.string.nepal_hint, - "nr" to R.string.nauru_hint, - "nu" to R.string.niue_hint, - "nz" to R.string.new_zealand_hint, - "om" to R.string.oman_hint, - "pa" to R.string.panama_hint, - "pe" to R.string.peru_hint, - "pf" to R.string.french_polynesia_hint, - "pg" to R.string.papua_new_guinea_hint, - "ph" to R.string.philippinies_hint, - "pk" to R.string.pakistan_hint, - "pl" to R.string.poland_hint, - "pm" to R.string.saint_pierre_hint, - "pn" to R.string.pitcairn, - "pr" to R.string.puerto_rico_hint, - "ps" to R.string.state_of_palestine_hint, - "pt" to R.string.portugal_hint, - "pw" to R.string.palau_hint, - "py" to R.string.paraguay_hint, - "qa" to R.string.qatar_hint, - "re" to R.string.reunion_hint, - "ro" to R.string.romania_hint, - "rs" to R.string.serbia_hint, - "ru" to R.string.russia_hint, - "rw" to R.string.rwanda_hint, - "sa" to R.string.saudi_arabia_hint, - "sb" to R.string.solomon_islands_hint, - "sc" to R.string.seychelles_hint, - "sd" to R.string.sudan_hint, - "se" to R.string.sweden_hint, - "sg" to R.string.singapore_hint, - "sh" to R.string.saint_helena_hint, - "si" to R.string.slovenia_hint, - "sk" to R.string.slovakia_hint, - "sl" to R.string.sierra_leone_hint, - "sm" to R.string.san_marino_hint, - "sn" to R.string.senegal_hint, - "so" to R.string.somali_hint, - "sr" to R.string.suriname_hint, - "ss" to R.string.south_sudan_hint, - "st" to R.string.sao_tome_hint, - "sv" to R.string.el_salvador_hint, - "sx" to R.string.sint_maarten_hint, - "sy" to R.string.syrian_hint, - "sz" to R.string.swaziland_hint, - "tc" to R.string.turks_and_caicos_hint, - "td" to R.string.chad_hint, - "tg" to R.string.togo_hint, - "th" to R.string.thailand_hint, - "tj" to R.string.taijikistan_hint, - "tk" to R.string.tokelau_hint, - "tl" to R.string.timor_leste_hint, - "tm" to R.string.turkmenistan_hint, - "tn" to R.string.tunisia_hint, - "to" to R.string.tonga_hint, - "tr" to R.string.turkey_hint, - "tt" to R.string.trinidad_and_tobago_hint, - "tv" to R.string.tuvalu_hint, - "tw" to R.string.taiwan_hint, - "tz" to R.string.tazmania_hint, - "ua" to R.string.ukraina_hint, - "ug" to R.string.uganda_hint, - "us" to R.string.united_states_america_hint, - "uy" to R.string.uruguay_hint, - "uz" to R.string.uzbekistan_hint, - "va" to R.string.holy_see, - "vc" to R.string.saint_vincent_hint, - "ve" to R.string.venezuela_hint, - "vg" to R.string.virgin_islands_hint, - "vi" to R.string.virgin_islands_us, - "vn" to R.string.vietnam_hint, - "vu" to R.string.vanuatu_hint, - "wf" to R.string.walli_and_fatuna_hint, - "ws" to R.string.samoa_hint, - "xk" to R.string.kosovo_hint, - "ye" to R.string.yemen_hint, - "yt" to R.string.mayotte_hint, - "za" to R.string.south_africa_hint, - "zm" to R.string.zambia_hint, - "zw" to R.string.zimbabwe_hint, -) diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/NumberHintMap.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/NumberHintMap.kt new file mode 100644 index 0000000..69c27d2 --- /dev/null +++ b/ccp/src/main/java/com/togitech/ccp/data/utils/NumberHintMap.kt @@ -0,0 +1,250 @@ +package com.togitech.ccp.data.utils + +import com.togitech.ccp.R +import com.togitech.ccp.data.Iso31661alpha2 + +@Suppress("LongMethod", "CyclomaticComplexMethod") +internal val numberHint: Map = mapOf( + "AD" to R.string.andorra_hint, + "AE" to R.string.united_arab_emirates_hint, + "AF" to R.string.afganistan_hint, + "AG" to R.string.antigua_and_barbuda_hint, + "AI" to R.string.anguilla_hint, + "AL" to R.string.albania_hint, + "AM" to R.string.armenia_hint, + "AO" to R.string.angola_hint, + "AQ" to R.string.antarctica_hint, + "AR" to R.string.argentina_hint, + "AS" to R.string.american_samoa_hint, + "AT" to R.string.austria_hint, + "AU" to R.string.australia_hint, + "AW" to R.string.aruba_hint, + "AX" to R.string.aland_islands_hint, + "AZ" to R.string.azerbaijan_hint, + "BA" to R.string.bosnia_hint, + "BB" to R.string.barbados_hint, + "BD" to R.string.bangladesh_hint, + "BE" to R.string.belgium_hint, + "BF" to R.string.burkina_faso_hint, + "BG" to R.string.bulgaria_hint, + "BH" to R.string.bahrain_hint, + "BI" to R.string.burundi_hint, + "BJ" to R.string.benin_hint, + "BL" to R.string.saint_barhelemy_hint, + "BM" to R.string.bermuda_hint, + "BN" to R.string.brunei_darussalam_hint, + "BO" to R.string.bolivia_hint, + "BR" to R.string.brazil_hint, + "BS" to R.string.bahamas_hint, + "BT" to R.string.bhutan_hint, + "BW" to R.string.botswana_hint, + "BY" to R.string.belarus_hint, + "BZ" to R.string.belize_hint, + "CA" to R.string.canada_hint, + "CC" to R.string.cocos_hint, + "CD" to R.string.congo_democratic_hint, + "CF" to R.string.central_african_hint, + "CG" to R.string.congo_hint, + "CH" to R.string.switzerland_hint, + "CI" to R.string.cote_dlvoire_hint, + "CK" to R.string.cook_islands_hint, + "CL" to R.string.chile_hint, + "CM" to R.string.cameroon_hint, + "CN" to R.string.china_hint, + "CO" to R.string.colombia_hint, + "CR" to R.string.costa_rica_hint, + "CU" to R.string.cuba_hint, + "CV" to R.string.cape_verde_hint, + "CW" to R.string.curacao_hint, + "CX" to R.string.christmas_island_hint, + "CY" to R.string.cyprus_hint, + "CZ" to R.string.czech_republic_hint, + "DE" to R.string.germany_hint, + "DJ" to R.string.djibouti_hint, + "DK" to R.string.denmark_hint, + "DM" to R.string.dominica_hint, + "DO" to R.string.dominician_republic_hint, + "DZ" to R.string.algeria_hint, + "EC" to R.string.ecuador_hint, + "EE" to R.string.estonia_hint, + "EG" to R.string.egypt_hint, + "ER" to R.string.eritrea_hint, + "ES" to R.string.spain_hint, + "ET" to R.string.ethiopia_hint, + "FI" to R.string.finland_hint, + "FJ" to R.string.fiji_hint, + "FK" to R.string.falkland_islands_hint, + "FM" to R.string.micro_hint, + "FO" to R.string.faroe_islands_hint, + "FR" to R.string.france_hint, + "GA" to R.string.gabon_hint, + "GB" to R.string.united_kingdom_hint, + "GD" to R.string.grenada_hint, + "GE" to R.string.georgia_hint, + "GF" to R.string.french_guyana_hint, + "GG" to R.string.guernsey_hint, + "GH" to R.string.ghana_hint, + "GI" to R.string.gibraltar_hint, + "GL" to R.string.greenland_hint, + "GM" to R.string.gambia_hint, + "GN" to R.string.guinea_hint, + "GP" to R.string.guadeloupe_hint, + "GQ" to R.string.equatorial_guinea_hint, + "GR" to R.string.greece_hint, + "GT" to R.string.guatemala_hint, + "GU" to R.string.guam_hint, + "GW" to R.string.guinea_bissau_hint, + "GY" to R.string.guyana_hint, + "HK" to R.string.hong_kong_hint, + "HN" to R.string.honduras_hint, + "HR" to R.string.croatia_hint, + "HT" to R.string.haiti_hint, + "HU" to R.string.hungary_hint, + "ID" to R.string.indonesia_hint, + "IE" to R.string.ireland_hint, + "IL" to R.string.israil_hint, + "IM" to R.string.isle_of_man_hint, + "IS" to R.string.iceland_hint, + "IN" to R.string.india_hint, + "IO" to R.string.british_indian_ocean_hint, + "IQ" to R.string.iraq_hint, + "IR" to R.string.iran_hint, + "IT" to R.string.italia_hint, + "JE" to R.string.jersey_hint, + "JM" to R.string.jamaica_hint, + "JO" to R.string.jordan_hint, + "JP" to R.string.japan_hint, + "KE" to R.string.kenya_hint, + "KG" to R.string.kyrgyzstan_hint, + "KH" to R.string.cambodia_hint, + "KI" to R.string.kiribati_hint, + "KM" to R.string.comoros_hint, + "KN" to R.string.saint_kitts_hint, + "KP" to R.string.north_korea_hint, + "KR" to R.string.south_korea_hint, + "KW" to R.string.kuwait_hint, + "KY" to R.string.cayman_islands_hint, + "KZ" to R.string.kazakhstan_hint, + "LA" to R.string.laos_hint, + "LB" to R.string.lebanon_hint, + "LC" to R.string.saint_lucia_hint, + "LI" to R.string.liechtenstein_hint, + "LK" to R.string.siri_lanka_hint, + "LR" to R.string.liberia_hint, + "LS" to R.string.lesotho_hint, + "LT" to R.string.lithuania_hint, + "LU" to R.string.luxembourg_hint, + "LV" to R.string.latvia_hint, + "LY" to R.string.libya_hint, + "MA" to R.string.marocco_hint, + "MC" to R.string.monaco_hint, + "MD" to R.string.moldova_hint, + "ME" to R.string.montenegro_hint, + "MF" to R.string.saint_martin_hint, + "MG" to R.string.madagascar_hint, + "MH" to R.string.marshall_islands_hint, + "MK" to R.string.north_macedonia_hint, + "ML" to R.string.mali_hint, + "MM" to R.string.myanmar_hint, + "MN" to R.string.mongolia_hint, + "MO" to R.string.macau_hint, + "MP" to R.string.northern_mariana_hint, + "MQ" to R.string.martinique_hint, + "MR" to R.string.mauriatana_hint, + "MS" to R.string.montserrat_hint, + "MT" to R.string.malta_hint, + "MU" to R.string.mauritius_hint, + "MV" to R.string.maldives_hint, + "MW" to R.string.malawi_hint, + "MX" to R.string.mexico_hint, + "MY" to R.string.malaysia_hint, + "MZ" to R.string.mozambique_hint, + "NA" to R.string.namibia_hint, + "NC" to R.string.new_caledonia_hint, + "NE" to R.string.niger_hint, + "NF" to R.string.norfolk_hint, + "NG" to R.string.nigeria_hint, + "NI" to R.string.nicaragua_hint, + "NL" to R.string.netherlands_hint, + "NO" to R.string.norway_hint, + "NP" to R.string.nepal_hint, + "NR" to R.string.nauru_hint, + "NU" to R.string.niue_hint, + "NZ" to R.string.new_zealand_hint, + "OM" to R.string.oman_hint, + "PA" to R.string.panama_hint, + "PE" to R.string.peru_hint, + "PF" to R.string.french_polynesia_hint, + "PG" to R.string.papua_new_guinea_hint, + "PH" to R.string.philippinies_hint, + "PK" to R.string.pakistan_hint, + "PL" to R.string.poland_hint, + "PM" to R.string.saint_pierre_hint, + "PN" to R.string.pitcairn_hint, + "PR" to R.string.puerto_rico_hint, + "PS" to R.string.state_of_palestine_hint, + "PT" to R.string.portugal_hint, + "PW" to R.string.palau_hint, + "PY" to R.string.paraguay_hint, + "QA" to R.string.qatar_hint, + "RE" to R.string.reunion_hint, + "RO" to R.string.romania_hint, + "RS" to R.string.serbia_hint, + "RU" to R.string.russia_hint, + "RW" to R.string.rwanda_hint, + "SA" to R.string.saudi_arabia_hint, + "SB" to R.string.solomon_islands_hint, + "SC" to R.string.seychelles_hint, + "SD" to R.string.sudan_hint, + "SE" to R.string.sweden_hint, + "SG" to R.string.singapore_hint, + "SH" to R.string.saint_helena_hint, + "SI" to R.string.slovenia_hint, + "SK" to R.string.slovakia_hint, + "SL" to R.string.sierra_leone_hint, + "SM" to R.string.san_marino_hint, + "SN" to R.string.senegal_hint, + "SO" to R.string.somali_hint, + "SR" to R.string.suriname_hint, + "SS" to R.string.south_sudan_hint, + "ST" to R.string.sao_tome_hint, + "SV" to R.string.el_salvador_hint, + "SX" to R.string.sint_maarten_hint, + "SY" to R.string.syrian_hint, + "SZ" to R.string.swaziland_hint, + "TC" to R.string.turks_and_caicos_hint, + "TD" to R.string.chad_hint, + "TG" to R.string.togo_hint, + "TH" to R.string.thailand_hint, + "TJ" to R.string.taijikistan_hint, + "TK" to R.string.tokelau_hint, + "TL" to R.string.timor_leste_hint, + "TM" to R.string.turkmenistan_hint, + "TN" to R.string.tunisia_hint, + "TO" to R.string.tonga_hint, + "TR" to R.string.turkey_hint, + "TT" to R.string.trinidad_and_tobago_hint, + "TV" to R.string.tuvalu_hint, + "TW" to R.string.taiwan_hint, + "TZ" to R.string.tazmania_hint, + "UA" to R.string.ukraina_hint, + "UG" to R.string.uganda_hint, + "US" to R.string.united_states_america_hint, + "UY" to R.string.uruguay_hint, + "UZ" to R.string.uzbekistan_hint, + "VA" to R.string.holy_see_hint, + "VC" to R.string.saint_vincent_hint, + "VE" to R.string.venezuela_hint, + "VG" to R.string.virgin_islands_hint, + "VI" to R.string.virgin_islands_us_hint, + "VN" to R.string.vietnam_hint, + "VU" to R.string.vanuatu_hint, + "WF" to R.string.walli_and_fatuna_hint, + "WS" to R.string.samoa_hint, + "XK" to R.string.kosovo_hint, + "YE" to R.string.yemen_hint, + "YT" to R.string.mayotte_hint, + "ZA" to R.string.south_africa_hint, + "ZM" to R.string.zambia_hint, + "ZW" to R.string.zimbabwe_hint, +) diff --git a/ccp/src/main/java/com/togitech/ccp/utils/SearchCountryList.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/SearchCountryList.kt similarity index 79% rename from ccp/src/main/java/com/togitech/ccp/utils/SearchCountryList.kt rename to ccp/src/main/java/com/togitech/ccp/data/utils/SearchCountryList.kt index 5c9429d..57f605d 100644 --- a/ccp/src/main/java/com/togitech/ccp/utils/SearchCountryList.kt +++ b/ccp/src/main/java/com/togitech/ccp/data/utils/SearchCountryList.kt @@ -1,13 +1,12 @@ -package com.togitech.ccp.utils +package com.togitech.ccp.data.utils import android.content.Context import com.togitech.ccp.R import com.togitech.ccp.data.CountryData -import com.togitech.ccp.data.utils.countryNames internal fun List.searchCountry(key: String, context: Context): List = this.mapNotNull { countryData -> - countryNames[countryData.countryCode]?.let { countryName -> + countryNames[countryData.countryIso]?.let { countryName -> val localizedCountryName = context.resources.getString(countryName).lowercase() if (localizedCountryName.contains(key.lowercase())) { countryData to localizedCountryName @@ -24,6 +23,6 @@ internal fun List.searchCountry(key: String, context: Context): Lis internal fun List.sortedByLocalizedName(context: Context): List = this.sortedBy { context.resources.getString( - countryNames.getOrDefault(it.countryCode, R.string.unknown), + countryNames.getOrDefault(it.countryIso, R.string.unknown), ) } diff --git a/ccp/src/main/java/com/togitech/ccp/data/utils/TogiUtils.kt b/ccp/src/main/java/com/togitech/ccp/data/utils/TogiUtils.kt deleted file mode 100644 index b5c934b..0000000 --- a/ccp/src/main/java/com/togitech/ccp/data/utils/TogiUtils.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.togitech.ccp.data.utils - -import android.content.Context -import android.telephony.TelephonyManager -import androidx.compose.ui.text.intl.Locale -import com.togitech.ccp.data.CountryData - -private const val EMOJI_UNICODE = 0x1F1A5 - -@Suppress("SwallowedException") -private fun getDefaultLangCode(context: Context): String { - val countryCode = try { - context.telephonyManager?.networkCountryIso - } catch (ex: java.lang.AssertionError) { - null - } - return countryCode.takeIf { !it.isNullOrBlank() } ?: Locale.current.language -} -internal fun getDefaultCountryAndPhoneCode( - context: Context, - fallbackCountryData: CountryData, - initialCountryData: CountryData?, -): Pair { - // return initial country data if passed - if (initialCountryData != null) { - val initialCountryCode = initialCountryData.countryCode - val initialCountryPhoneCode = initialCountryData.countryPhoneCode - return initialCountryCode to initialCountryPhoneCode - } - val defaultCountry = getDefaultLangCode(context) - val defaultCode: CountryData? = getLibCountries.firstOrNull { it.countryCode == defaultCountry } - return defaultCountry to ( - defaultCode?.countryPhoneCode.takeIf { - !it.isNullOrBlank() - } ?: fallbackCountryData.countryPhoneCode - ) -} - -fun countryCodeToEmojiFlag(countryCode: String): String = - countryCode - .uppercase() - .map { char -> - Character.codePointAt("$char", 0) + EMOJI_UNICODE - } - .joinToString("") { - String(Character.toChars(it)) - } - -private val Context.telephonyManager: TelephonyManager? - get() = getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager diff --git a/ccp/src/main/res/values/strings.xml b/ccp/src/main/res/values/strings.xml index 9c4554e..3efdf40 100644 --- a/ccp/src/main/res/values/strings.xml +++ b/ccp/src/main/res/values/strings.xml @@ -478,6 +478,15 @@ (876) 123-4567 0777 123 4567 070 123 456 + 06 698xxxxx + (340) xxx-xxxx + 3xx xxxx + xxxx xxxxxx + xxx xxxx + xxxxxxxx + xxx xxxx + xxxx xxxx + xxxxxxxx(x) Select Country Invalid Phone Number \ No newline at end of file diff --git a/ccp/src/test/java/com/togitech/ccp/CountryCodePickTest.kt b/ccp/src/test/java/com/togitech/ccp/CountryCodePickTest.kt index 1c5905d..bafc4b4 100644 --- a/ccp/src/test/java/com/togitech/ccp/CountryCodePickTest.kt +++ b/ccp/src/test/java/com/togitech/ccp/CountryCodePickTest.kt @@ -49,6 +49,7 @@ class CountryCodePickTest { fullPhoneNumber.value = code + phone isNumberValid = isValid }, + initialCountryIsoCode = "US", ) Spacer(modifier = Modifier.height(10.dp)) diff --git a/detekt.yml b/detekt.yml index 8093782..40c044a 100644 --- a/detekt.yml +++ b/detekt.yml @@ -458,6 +458,7 @@ potential-bugs: ImplicitUnitReturnType: active: true allowExplicitReturnType: true + ignoreAnnotated: [ 'Composable' ] InvalidRange: active: true IteratorHasNextCallsNextMethod: @@ -617,6 +618,8 @@ style: singleLine: never BracesOnWhenStatements: active: true + singleLine: consistent + multiLine: necessary MandatoryBracesLoops: active: true MaxChainedCallsOnSameLine: @@ -1160,7 +1163,7 @@ compose: TopLevelComposableFunctions: active: true ComposableFunctionName: - active: true + active: false ConditionCouldBeLifted: active: true ignoreCallsWithArgumentNames: [ 'modifier', 'contentAlignment' ] \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 28c9249..7b39f51 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,7 @@ targetSdk = "34" compileSdk = "34" # Dependencies -android-gradle-plugin = "8.2.0-beta05" +android-gradle-plugin = "8.2.0-beta06" gradle-versions = "0.48.0" detekt = "1.23.1" @@ -18,7 +18,7 @@ androidx-core = "1.12.0" androidx-lifecycle = "2.6.2" androidx-test-junit = "1.1.5" -compose = "1.5.1" +compose = "1.5.2" # https://androidx.dev/storage/compose-compiler/repository/ # https://developer.android.com/jetpack/androidx/releases/compose-compiler composeCompiler = "1.5.3"