Skip to content

Commit

Permalink
Preparation for release
Browse files Browse the repository at this point in the history
  • Loading branch information
hbmartin committed Mar 7, 2023
1 parent 93a02d4 commit e2f1cfc
Show file tree
Hide file tree
Showing 22 changed files with 97 additions and 244 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
.externalNativeBuild
.cxx
local.properties
Screenshot*
2 changes: 1 addition & 1 deletion .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

164 changes: 53 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,143 +1,85 @@
# Jetpack Compose Country Code Picker

Jetpack Compose Country Code Picker
[![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)

* 😍 Emoji flag icons - beautiful and minimizes library size
* 🤔 Country numbers hints (option to disable)
* 🔢 Phone number visualTransformation (Automatic number formatting)
* 🇺🇳 Automatic country recognition (detection by sim card if sim card is inserted)
* ⚙️ Advanced customization options (see usage below)
* 🏁 Fast! Flattened layouts and immutable collections prevent unwanted recomposition.
* 🗣 Multilingual:
* Turkish
* English
* Italian
* Arabic
* Russian
* Dutch
* Spanish
* Somali


## Screenshots

<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>

<h1>Updated</h1>

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

* Country numbers hints
* Phone number visualTransformation (Automatic number formatting)
* Automatic country recognition (detection by sim card if sim card is inserted)
* With TextField
* Can Customize
* Added language translations
* Added clear text button
* Dialog changed

Languages:

* Turkish
* English
* Italian
* Arabic
* Russian
* Dutch

For language support, you can translate the file below and send it to me.
https://github.com/togisoft/jetpack_compose_country_code_picker/blob/master/ccp/src/main/res/values/strings.xml

<h3>Screenshots</h3>
<div class="row">
<img src="screenshots/1.png" width="300">
<img src="screenshots/2.png" width="300">
<img src="screenshots/3.png" width="300">
<img src="screenshots/4.png" width="300">
<img src="screenshots/5.png" width="300">
<img src="screenshots/6.png" width="300">
<img src="screenshots/7.png" width="300">
<img src="screenshots/8.png" width="300">
</div>



<h3> USAGE </h3>

```kotlin
@Composable
fun TogiCountryCodePicker(
modifier: Modifier = Modifier,
text: String,
onValueChange: (String) -> Unit,
shape: Shape = RoundedCornerShape(24.dp),
color: Color = MaterialTheme.colors.background,
showCountryCode: Boolean = true,
showCountryFlag: Boolean = true,
focusedBorderColor: Color = MaterialTheme.colors.primary,
unfocusedBorderColor: Color = MaterialTheme.colors.onSecondary,
cursorColor: Color = MaterialTheme.colors.primary,
bottomStyle: Boolean = false
)

```

<h3> EXAMPLE </h3>


```kotlin
@Composable
fun CountryCodePickerExample() {
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {

val phoneNumber = rememberSaveable { mutableStateOf("") }
val fullPhoneNumber = rememberSaveable { mutableStateOf("") }
val onlyPhoneNumber = rememberSaveable { mutableStateOf("") }

TogiCountryCodePicker(
text = phoneNumber.value,
onValueChange = { phoneNumber.value = it },
unfocusedBorderColor = MaterialTheme.colors.primary,
bottomStyle =false, // if true the text-field is below the country code selector at the top.
shape = RoundedCornerShape(24.dp)
)
Spacer(modifier = Modifier.height(10.dp))
Button(onClick = {
if (!isPhoneNumber()) {
fullPhoneNumber.value = getFullPhoneNumber()
onlyPhoneNumber.value = getOnlyPhoneNumber()
} else {
fullPhoneNumber.value = "Error"
onlyPhoneNumber.value = "Error"
}
}) {
Text(text = "Check")
}

Text(
text = "Full Phone Number: ${fullPhoneNumber.value}",
color = if (getErrorStatus()) Color.Red else Color.Green
)

Text(
text = "Only Phone Number: ${onlyPhoneNumber.value}",
color = if (getErrorStatus()) Color.Red else Color.Green
)
}
}
## Usage

```

<h3><- Functions -></h3>
See MainActivity in the sample app for a full example.


<b>getFullPhoneNumber()</b> => Phone number with country code => return type <b>String</b> </br>
<b>getOnlyPhoneNumber()</b> => Phone number only => return type <b>String</b> </br>
<b>isPhoneNumber()</b> => Checks if the phone number is correct based on the country code => return type <b>Boolean</b>/</br>
| Parameter | Description |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| text | The text to be displayed in the text field. |
| onValueChange | Called when the text in the text field changes. The first parameter is string pair of (country code, phone number) and the second parameter is a boolean indicating whether the phone number is valid. |
| modifier | Modifier to be applied to the inner OutlinedTextField. |
| shape | Shape of the text field. |
| showCountryCode | Whether to show the country code in the text field. |
| showCountryFlag | Whether to show the country flag in the text field. |
| colors | Colors to be used for the text field. |
| fallbackCountry | The country to be used as a fallback if the user's country cannot be determined. |
| showPlaceholder | Whether to show the placeholder number in the text field. |
| includeOnly | A set of 2 digit country codes to be included in the list of countries. Set to null to include all supported countries. |
| clearIcon | The icon to be used for the clear button. Set to null to disable the clear button. |

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

## How to add in your project

In the build.gradle add maven central repository

```groovy
repositories {
maven { url 'https://jitpack.io' }
}
maven { url 'https://jitpack.io' }
}
```

Step 2. Add the dependency

```
dependencies {
dependencies {
implementation 'com.github.togisoft:jetpack_compose_country_code_picker:1.1.4'
}
```

## Contributing

* [PRs](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/pulls) and [bug reports / feature requests](https://github.com/jump-sdk/jetpack_compose_country_code_picker_emoji/issues) are welcome!
* This project is linted with [ktlint](https://github.com/pinterest/ktlint) and statically checked with [detekt](https://github.com/detekt/detekt)
* Addtional checking done with [Twitter's](https://twitter.github.io/compose-rules/detekt/) and [appKODE's](https://github.com/appKODE/detekt-rules-compose) Jetpack Compose rules for Detekt
* Treat other people with helpfulness, gratitude, and consideration! See the [JetBrains CoC](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct)


## Based on [togisoft's Jetpack Compose Country Code Picker](https://github.com/togisoft/jetpack_compose_country_code_picker)

All support goes to the original author

<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>
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '1.8'
Expand All @@ -44,6 +44,7 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
namespace 'com.togitech.togii'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.togitech.togii">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ buildscript {
lifecycle_version = '2.6.0-rc01'
material3_version = '1.1.0-alpha07'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
}

plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id "com.github.ben-manes.versions" version "0.46.0"
id 'org.jetbrains.dokka' version '1.8.10'
}

task clean(type: Delete) {
Expand Down
27 changes: 13 additions & 14 deletions ccp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
id "io.gitlab.arturbosch.detekt" version "1.22.0"
id 'org.jetbrains.dokka'
}

group 'com.togitech'
version '1.1.3'
version '2.0.1'

kotlin {
jvmToolchain(11)
}

android {
compileSdk 33
Expand All @@ -16,24 +20,14 @@ android {
defaultConfig {
minSdk 24
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"

}
buildFeatures {
compose true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
Expand All @@ -48,6 +42,11 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
publishing {
singleVariant('release') {
withJavadocJar()
}
}
}

dependencies {
Expand Down Expand Up @@ -80,7 +79,7 @@ afterEvaluate {
from components.release
groupId = 'com.togisoft'
artifactId = 'jetpack_country_code_picker'
version = '1.0'
version = '2.0.1'
}
})
}
Expand Down
Empty file removed ccp/consumer-rules.pro
Empty file.
21 changes: 0 additions & 21 deletions ccp/proguard-rules.pro

This file was deleted.

3 changes: 1 addition & 2 deletions ccp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.togitech.ccp">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ private val DEFAULT_TEXT_FIELD_SHAPE = RoundedCornerShape(24.dp)
@OptIn(ExperimentalComposeUiApi::class)
@Suppress("LongMethod")
@Composable
/**
* @param text The text to be displayed in the text field.
* @param onValueChange Called when the text in the text field changes.
* The first parameter is string pair of (country code, phone number) and the second parameter is
* a boolean indicating whether the phone number is valid.
* @param modifier Modifier to be applied to the inner OutlinedTextField.
* @param shape Shape of the text field.
* @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 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.
*/
fun TogiCountryCodePicker(
text: String,
onValueChange: (Pair<String, String>, Boolean) -> Unit,
Expand Down
Loading

0 comments on commit e2f1cfc

Please sign in to comment.