Skip to content

Commit c933e88

Browse files
committed
Updated and Code Cleanup
1 parent 9a854b0 commit c933e88

File tree

27 files changed

+636
-958
lines changed

27 files changed

+636
-958
lines changed

.idea/deploymentTargetDropDown.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 45 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Jetpack Compose Country Code Picker
88

99
If you are looking for Country Phone Code Picker for Jetpack Compose you can use the package.
1010

11-
1211
* Country numbers hints
1312
* Phone number visualTransformation (Automatic number formatting)
1413
* Automatic country recognition (detection by sim card if sim card is inserted)
@@ -25,8 +24,7 @@ Languages:
2524
* Italian
2625
* Arabic
2726
* Russian
28-
29-
New features will be added every day. This project is open source without any profit motive.
27+
* Dutch
3028

3129
For language support, you can translate the file below and send it to me.
3230
https://github.com/togisoft/jetpack_compose_country_code_picker/blob/master/ccp/src/main/res/values/strings.xml
@@ -44,166 +42,84 @@ https://github.com/togisoft/jetpack_compose_country_code_picker/blob/master/ccp/
4442
</div>
4543

4644

47-
**** Specifications ****
4845

49-
<h3> DEFAULT </h3>
46+
<h3> USAGE </h3>
5047

5148
```kotlin
5249
@Composable
5350
fun TogiCountryCodePicker(
54-
text: String,
55-
onValueChange: (String) -> Unit,
5651
modifier: Modifier = Modifier,
57-
color: Color = MaterialTheme.colors.background,
58-
showCountryCode: Boolean = true,
59-
showCountryFlag: Boolean = true,
60-
defaultCountry: CountryData,
61-
pickedCountry: (CountryData) -> Unit,
62-
focusedBorderColor: Color = MaterialTheme.colors.primary,
63-
unfocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
64-
cursorColor: Color = MaterialTheme.colors.primary,
65-
error: Boolean,
66-
rowPadding: Modifier = modifier.padding(vertical = 16.dp, horizontal = 16.dp)
67-
)
68-
69-
```
70-
71-
<h3> Rounded </h3>
72-
73-
```kotlin
74-
@Composable
75-
fun TogiRoundedPicker(
76-
value: String,
77-
onValueChange: (String) -> Unit,
78-
modifier: Modifier = Modifier,
79-
shape: Shape = RoundedCornerShape(24.dp),
80-
color: Color = MaterialTheme.colors.background,
81-
showCountryCode: Boolean = true,
82-
showCountryFlag: Boolean = true,
83-
defaultCountry: CountryData,
84-
pickedCountry: (CountryData) -> Unit,
85-
focusedBorderColor: Color = MaterialTheme.colors.primary,
86-
unFocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
87-
cursorColor: Color = MaterialTheme.colors.primary,
88-
error: Boolean,
89-
rowPadding: Modifier = modifier.padding(vertical = 16.dp, horizontal = 16.dp)
90-
)
91-
92-
```
93-
94-
<h3> Bottom Text Field </h3>
95-
96-
```kotlin
97-
@Composable
98-
fun TogiBottomCodePicker(
9952
text: String,
10053
onValueChange: (String) -> Unit,
101-
modifier: Modifier = Modifier,
54+
shape: Shape = RoundedCornerShape(24.dp),
10255
color: Color = MaterialTheme.colors.background,
10356
showCountryCode: Boolean = true,
10457
showCountryFlag: Boolean = true,
105-
showCountryName: Boolean = true,
106-
defaultCountry: CountryData,
107-
pickedCountry: (CountryData) -> Unit,
10858
focusedBorderColor: Color = MaterialTheme.colors.primary,
10959
unfocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
11060
cursorColor: Color = MaterialTheme.colors.primary,
111-
error: Boolean,
112-
rowPadding: Modifier = modifier.padding(vertical = 16.dp, horizontal = 16.dp)
61+
bottomStyle: Boolean = false
11362
)
11463

11564
```
11665

66+
<h3> EXAMPLE </h3>
11767

118-
<h3> Rounded Field Usage </h3>
11968

12069
```kotlin
121-
val context = LocalContext.current
122-
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
123-
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
124-
val phoneNumber = rememberSaveable { mutableStateOf("") }
125-
var isValidPhone by remember { mutableStateOf(true) }
126-
127-
TogiRoundedPicker(
128-
value = phoneNumber.value,
129-
onValueChange = { phoneNumber.value = it },
130-
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
131-
pickedCountry = {
132-
phoneCode = it.countryPhoneCode
133-
defaultLang = it.countryCode
134-
},
135-
error = isValidPhone
136-
)
137-
138-
139-
```
140-
141-
```kotlin
142-
// With Country Phone Code
14370
@Composable
144-
fun SelectCountryWithCountryCode() {
145-
val context = LocalContext.current
146-
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
147-
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
148-
val phoneNumber = rememberSaveable { mutableStateOf("") }
149-
var isValidPhone by remember { mutableStateOf(true) }
150-
var verifyText by remember { mutableStateOf("") }
71+
fun CountryCodePickerExample() {
15172
Column(
152-
modifier = Modifier.padding(16.dp)
73+
modifier = Modifier
74+
.verticalScroll(rememberScrollState())
75+
.fillMaxSize(),
76+
verticalArrangement = Arrangement.Center,
77+
horizontalAlignment = Alignment.CenterHorizontally
15378
) {
154-
Text(
155-
text = verifyText,
156-
fontWeight = FontWeight.Bold,
157-
modifier = Modifier
158-
.fillMaxWidth()
159-
.wrapContentSize(Alignment.Center)
160-
)
79+
80+
val phoneNumber = rememberSaveable { mutableStateOf("") }
81+
val fullPhoneNumber = rememberSaveable { mutableStateOf("") }
82+
val onlyPhoneNumber = rememberSaveable { mutableStateOf("") }
83+
16184
TogiCountryCodePicker(
162-
pickedCountry = {
163-
phoneCode = it.countryPhoneCode
164-
defaultLang = it.countryCode
165-
},
166-
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
167-
focusedBorderColor = MaterialTheme.colors.primary,
168-
unfocusedBorderColor = MaterialTheme.colors.primary,
169-
error = isValidPhone,
17085
text = phoneNumber.value,
171-
onValueChange = { phoneNumber.value = it }
86+
onValueChange = { phoneNumber.value = it },
87+
unfocusedBorderColor = MaterialTheme.colors.primary,
88+
bottomStyle =false, // if true the text-field is below the country code selector at the top.
89+
shape = RoundedCornerShape(24.dp)
17290
)
91+
Spacer(modifier = Modifier.height(10.dp))
92+
Button(onClick = {
93+
if (!isPhoneNumber()) {
94+
fullPhoneNumber.value = getFullPhoneNumber()
95+
onlyPhoneNumber.value = getOnlyPhoneNumber()
96+
} else {
97+
fullPhoneNumber.value = "Error"
98+
onlyPhoneNumber.value = "Error"
99+
}
100+
}) {
101+
Text(text = "Check")
102+
}
173103

174-
val fullPhoneNumber = "$phoneCode${phoneNumber.value}"
175-
val checkPhoneNumber = checkPhoneNumber(
176-
phone = phoneNumber.value,
177-
fullPhoneNumber = fullPhoneNumber,
178-
countryCode = defaultLang
104+
Text(
105+
text = "Full Phone Number: ${fullPhoneNumber.value}",
106+
color = if (getErrorStatus()) Color.Red else Color.Green
107+
)
108+
109+
Text(
110+
text = "Only Phone Number: ${onlyPhoneNumber.value}",
111+
color = if (getErrorStatus()) Color.Red else Color.Green
179112
)
180-
Button(
181-
onClick = {
182-
verifyText = if (checkPhoneNumber) {
183-
isValidPhone = true
184-
"Phone Number Correct"
185-
} else {
186-
isValidPhone = false
187-
"Phone Number is Wrong"
188-
189-
}
190-
},
191-
modifier = Modifier.fillMaxWidth()
192-
.padding(16.dp)
193-
.height(60.dp)
194-
) {
195-
Text(text = "Phone Verify")
196-
}
197113
}
198114
}
199-
```
200115

201-
<h3><- ********* Extras ********* -></h3>
116+
```
202117

203-
* focusedBorderColor = TextField Border Color
204-
* unfocusedBorderColor = TextField Unfocused Border Color
205-
* cursorColor = TextField Cursor Color
118+
<h3><- Functions -></h3>
206119

120+
<b>getFullPhoneNumber()</b> => Phone number with country code => return type <b>String</b>
121+
<b>getOnlyPhoneNumber()</b> => Phone number only => return type <b>String</b>
122+
<b>isPhoneNumber()</b> => Checks if the phone number is correct based on the country code => return type <b>Boolean</b>
207123

208124
<h3> How to add in your project </h3>
209125

app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ dependencies {
5252
implementation "androidx.compose.material:material:$compose_version"
5353
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
5454
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
55-
implementation 'androidx.activity:activity-compose:1.6.0'
55+
implementation 'androidx.activity:activity-compose:1.6.1'
5656
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.26.5-rc'
5757

5858
implementation project(path: ':ccp')
5959
testImplementation 'junit:junit:4.13.2'
60-
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
61-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
60+
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
61+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
6262
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
6363
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
6464
}

0 commit comments

Comments
 (0)