Skip to content

Commit 21d0389

Browse files
committed
Bug fix and update
1 parent f06f4d6 commit 21d0389

File tree

27 files changed

+420
-221
lines changed

27 files changed

+420
-221
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 5 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: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@ Jetpack Compose Country Code Picker
44

55
<a href="https://www.buymeacoffee.com/togitech" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
66

7+
<h1>Updated</h1>
8+
79
If you are looking for Country Phone Code Picker for Jetpack Compose you can use the package.
810

11+
912
* Country numbers hints
1013
* Phone number visualTransformation (Automatic number formatting)
1114
* Automatic country recognition (detection by sim card if sim card is inserted)
1215
* With TextField
1316
* Can Customize
14-
* Adding language translations
15-
17+
* Added language translations
18+
* Added clear text button
19+
* Dialog changed
1620

1721
Languages:
1822

1923
* Turkish
2024
* English
2125
* Italian
2226
* Arabic
27+
* Russian
2328

2429
New features will be added every day. This project is open source without any profit motive.
2530

@@ -28,23 +33,92 @@ https://github.com/togisoft/jetpack_compose_country_code_picker/blob/master/ccp/
2833

2934
<h3>Screenshots</h3>
3035
<div class="row">
31-
<img src="screenshots/1.gif" width="300">
32-
<img src="screenshots/1.jpg" width="300">
33-
<img src="screenshots/1-en.jpg" width="300">
34-
<img src="screenshots/2.jpg" width="300">
35-
<img src="screenshots/3.jpg" width="300">
36-
<img src="screenshots/4.jpg" width="300">
37-
<img src="screenshots/5.jpg" width="300">
38-
<img src="screenshots/6-dark.jpg" width="300">
39-
<img src="screenshots/7-dark.jpg" width="300">
36+
<img src="screenshots/1.png" width="300">
37+
<img src="screenshots/2.png" width="300">
38+
<img src="screenshots/3.png" width="300">
39+
<img src="screenshots/4.png" width="300">
40+
<img src="screenshots/5.png" width="300">
41+
<img src="screenshots/6.png" width="300">
42+
<img src="screenshots/7.png" width="300">
43+
<img src="screenshots/8.png" width="300">
4044
</div>
4145

4246

47+
**** Specifications ****
48+
49+
<h3> DEFAULT </h3>
50+
51+
```kotlin
52+
@Composable
53+
fun TogiCountryCodePicker(
54+
text: String,
55+
onValueChange: (String) -> Unit,
56+
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(
99+
text: String,
100+
onValueChange: (String) -> Unit,
101+
modifier: Modifier = Modifier,
102+
color: Color = MaterialTheme.colors.background,
103+
showCountryCode: Boolean = true,
104+
showCountryFlag: Boolean = true,
105+
showCountryName: Boolean = true,
106+
defaultCountry: CountryData,
107+
pickedCountry: (CountryData) -> Unit,
108+
focusedBorderColor: Color = MaterialTheme.colors.primary,
109+
unfocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
110+
cursorColor: Color = MaterialTheme.colors.primary,
111+
error: Boolean,
112+
rowPadding: Modifier = modifier.padding(vertical = 16.dp, horizontal = 16.dp)
113+
)
114+
115+
```
116+
43117

44118
<h3> Rounded Field Usage </h3>
45119

46120
```kotlin
47-
val context = LocalContext.current
121+
val context = LocalContext.current
48122
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
49123
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
50124
val phoneNumber = rememberSaveable { mutableStateOf("") }
@@ -92,8 +166,6 @@ fun SelectCountryWithCountryCode() {
92166
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
93167
focusedBorderColor = MaterialTheme.colors.primary,
94168
unfocusedBorderColor = MaterialTheme.colors.primary,
95-
dialogAppBarTextColor = Color.Black,
96-
dialogAppBarColor = Color.White,
97169
error = isValidPhone,
98170
text = phoneNumber.value,
99171
onValueChange = { phoneNumber.value = it }
@@ -131,8 +203,7 @@ fun SelectCountryWithCountryCode() {
131203
* focusedBorderColor = TextField Border Color
132204
* unfocusedBorderColor = TextField Unfocused Border Color
133205
* cursorColor = TextField Cursor Color
134-
* dialogAppBarColor = Dialog Top App Bar Background Color
135-
* dialogAppBarTextColor = Dialog Top App Bar Text Color
206+
136207

137208
<h3> How to add in your project </h3>
138209

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ plugins {
44
}
55

66
android {
7-
compileSdk 32
7+
compileSdk 33
88

99
defaultConfig {
1010
applicationId "com.togitech.togii"
1111
minSdk 21
12-
targetSdk 32
12+
targetSdk 33
1313
versionCode 1
1414
versionName "1.0"
1515

@@ -36,7 +36,7 @@ android {
3636
compose true
3737
}
3838
composeOptions {
39-
kotlinCompilerExtensionVersion compose_version
39+
kotlinCompilerExtensionVersion "1.3.2"
4040
}
4141
packagingOptions {
4242
resources {
@@ -47,13 +47,13 @@ android {
4747

4848
dependencies {
4949

50-
implementation 'androidx.core:core-ktx:1.7.0'
50+
implementation 'androidx.core:core-ktx:1.9.0'
5151
implementation "androidx.compose.ui:ui:$compose_version"
5252
implementation "androidx.compose.material:material:$compose_version"
5353
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
54-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
55-
implementation 'androidx.activity:activity-compose:1.4.0'
56-
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.24.5-alpha'
54+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
55+
implementation 'androidx.activity:activity-compose:1.6.0'
56+
implementation 'com.google.accompanist:accompanist-systemuicontroller:0.26.5-rc'
5757

5858
implementation project(path: ':ccp')
5959
testImplementation 'junit:junit:4.13.2'

app/src/main/java/com/togitech/togii/MainActivity.kt

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.togitech.togii
22

3+
import com.togitech.ccp.component.TogiBottomCodePicker
34
import android.os.Bundle
45
import androidx.activity.ComponentActivity
56
import androidx.activity.compose.setContent
@@ -11,7 +12,6 @@ import androidx.compose.runtime.*
1112
import androidx.compose.runtime.saveable.rememberSaveable
1213
import androidx.compose.ui.Alignment
1314
import androidx.compose.ui.Modifier
14-
import androidx.compose.ui.graphics.Color
1515
import androidx.compose.ui.platform.LocalContext
1616
import androidx.compose.ui.unit.dp
1717
import com.google.accompanist.systemuicontroller.rememberSystemUiController
@@ -61,6 +61,7 @@ class MainActivity : ComponentActivity() {
6161

6262
SelectCountryWithCountryCode()
6363
RoundedPicker()
64+
BottomCodePicker()
6465

6566
}
6667
}
@@ -84,8 +85,6 @@ class MainActivity : ComponentActivity() {
8485
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
8586
focusedBorderColor = MaterialTheme.colors.primary,
8687
unfocusedBorderColor = MaterialTheme.colors.primary,
87-
dialogAppBarTextColor = Color.Black,
88-
dialogAppBarColor = Color.White,
8988
error = isValidPhone,
9089
text = phoneNumber.value,
9190
onValueChange = { phoneNumber.value = it }
@@ -115,6 +114,54 @@ class MainActivity : ComponentActivity() {
115114
}
116115

117116

117+
@Composable
118+
fun BottomCodePicker() {
119+
val context = LocalContext.current
120+
var phoneCode by rememberSaveable { mutableStateOf(getDefaultPhoneCode(context)) }
121+
val phoneNumber = rememberSaveable { mutableStateOf("") }
122+
var defaultLang by rememberSaveable { mutableStateOf(getDefaultLangCode(context)) }
123+
var isValidPhone by remember { mutableStateOf(true) }
124+
125+
Column(
126+
modifier = Modifier.padding(8.dp),
127+
horizontalAlignment = Alignment.CenterHorizontally
128+
) {
129+
TogiBottomCodePicker(
130+
showCountryName = true,
131+
pickedCountry = {
132+
phoneCode = it.countryPhoneCode
133+
defaultLang = it.countryCode
134+
},
135+
defaultCountry = getLibCountries().single { it.countryCode == defaultLang },
136+
focusedBorderColor = MaterialTheme.colors.primary,
137+
unfocusedBorderColor = MaterialTheme.colors.primary,
138+
error = isValidPhone,
139+
text = phoneNumber.value,
140+
onValueChange = { phoneNumber.value = it }
141+
)
142+
val fullPhoneNumber = "$phoneCode${phoneNumber.value}"
143+
val checkPhoneNumber = checkPhoneNumber(
144+
phone = phoneNumber.value,
145+
fullPhoneNumber = fullPhoneNumber,
146+
countryCode = defaultLang
147+
)
148+
OutlinedButton(
149+
onClick = {
150+
isValidPhone = checkPhoneNumber
151+
},
152+
modifier = Modifier
153+
.fillMaxWidth()
154+
.padding(horizontal = 16.dp)
155+
.height(
156+
50.dp
157+
)
158+
) {
159+
Text(text = "Phone Verify")
160+
}
161+
}
162+
}
163+
164+
118165
@Composable
119166
private fun RoundedPicker() {
120167
val context = LocalContext.current

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
buildscript {
22
ext {
3-
compose_version = '1.2.0-beta02'
3+
compose_version = '1.2.1'
44
}
55
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
66
plugins {
7-
id 'com.android.application' version '7.1.2' apply false
8-
id 'com.android.library' version '7.1.2' apply false
9-
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
7+
id 'com.android.application' version '7.3.0' apply false
8+
id 'com.android.library' version '7.3.0' apply false
9+
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
1010
}
1111

1212
task clean(type: Delete) {

ccp/build.gradle

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ version '1.1.3'
1010

1111

1212
android {
13-
compileSdk 32
13+
compileSdk 33
1414
namespace = 'com.togitech.ccp'
1515

1616
defaultConfig {
1717
minSdk 21
18-
targetSdk 32
18+
targetSdk 33
1919
versionCode 1
2020
versionName "1.0"
2121
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -40,7 +40,7 @@ android {
4040
freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
4141
}
4242
composeOptions {
43-
kotlinCompilerExtensionVersion compose_version
43+
kotlinCompilerExtensionVersion "1.3.2"
4444
}
4545
packagingOptions {
4646
resources {
@@ -50,12 +50,16 @@ android {
5050
}
5151

5252
dependencies {
53+
def lifecycle_version = "2.5.1"
54+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
55+
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
56+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
5357

54-
implementation 'androidx.core:core-ktx:1.7.0'
55-
implementation 'androidx.appcompat:appcompat:1.4.1'
56-
implementation 'androidx.activity:activity-compose:1.4.0'
58+
implementation 'androidx.core:core-ktx:1.9.0'
59+
implementation 'androidx.appcompat:appcompat:1.5.1'
60+
implementation 'androidx.activity:activity-compose:1.6.0'
5761
implementation "androidx.compose.material:material:$compose_version"
58-
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1'
62+
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1'
5963
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.48'
6064

6165
}

0 commit comments

Comments
 (0)