Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	build.gradle
#	lib/build.gradle
#	lib/src/main/res/layout/bottom_sheet_country_picker.xml
#	lib/src/main/res/layout/item_country_picker.xml
  • Loading branch information
ibrahimsn98 committed Nov 7, 2021
2 parents 7e9b5d4 + f5353c4 commit b0a738d
Show file tree
Hide file tree
Showing 35 changed files with 897 additions and 680 deletions.
32 changes: 24 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,33 @@ Android **Kotlin** library to parse and format international phone numbers. Base
## Usage

Create a phoneNumberKit instance and attach it to an editTextLayout. That's all you have to do.
```kotlin
val phoneNumberKit = PhoneNumberKit(this) // Requires context

```kotlin
val phoneNumberKit = PhoneNumberKit.Builder(this)
.setIconEnabled(true)
.admitCountries(listOf("tr", "ca", "de")) // List only those county formats
.excludeCountries(listOf("tr", "ca")) // Exclude those county formats
.build()

phoneNumberKit.attachToInput(textField, "tr")
// OR
phoneNumberKit.attachToInput(textField, 1)
```

To setup with country code selection bottom sheet

```kotlin
phoneNumberKit.setupCountryPicker(this) // Requires activity
phoneNumberKit.setupCountryPicker(this) // Requires activity context
```

To get an example phone number for given **iso2 code**

```kotlin
val exampleNumber = phoneNumberKit.getExampleNumber("tr")
```

To parse raw text to phone number and receive country code, national number

```kotlin
val parsedNumber = phoneNumberKit.parsePhoneNumber(
number = "1266120000",
Expand All @@ -43,29 +56,32 @@ parsedNumber?.nationalNumber
parsedNumber?.countryCode
parsedNumber?.numberOfLeadingZeros
```

To convert raw text to formatted phone number string

```kotlin
val formattedNumber = phoneNumberKit.formatPhoneNumber(
number = "1266120000",
defaultRegion = "us"
)
```

To receive a country **flag icon** for given iso2 code

```kotlin
val flag = phoneNumberKit.getFlagIcon("ca")
```
To receive country name or iso2 code from given **country code**
```kotlin
val country = phoneNumberKit.getCountry(90)
```

## Usage with Custom Item Layout

Add your custom item layout resource as a parameter

```kotlin
phoneNumberKit.setupCountryPicker(this, R.layout.my_item_layout, searchEnabled = true)
```

You need to use below view ids in your layout file

```xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Expand Down Expand Up @@ -137,7 +153,7 @@ allprojects {
Step 2. Add the dependency
```
dependencies {
implementation 'com.github.ibrahimsn98:PhoneNumberKit:1.7.5'
implementation 'com.github.ibrahimsn98:PhoneNumberKit:2.0.0'
}
```

Expand Down
30 changes: 15 additions & 15 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-parcelize'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "me.ibrahimsn.phonenumberkit"
minSdkVersion 19
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildFeatures {
viewBinding true
}
}

buildTypes {
Expand All @@ -25,16 +29,12 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'

testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.google.android.material:material:1.2.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation project(":lib")
}
}
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
package="me.ibrahimsn.phonenumberkit">

<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity
android:name=".MainActivity"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
26 changes: 17 additions & 9 deletions app/src/main/java/me/ibrahimsn/phonenumberkit/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@ package me.ibrahimsn.phonenumberkit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
import android.util.Log
import me.ibrahimsn.lib.PhoneNumberKit
import me.ibrahimsn.phonenumberkit.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

val phoneNumberKit = PhoneNumberKit(this)
val phoneNumberKit = PhoneNumberKit.Builder(this)
.setIconEnabled(true)
.build()

// To attach an editTextLayout
phoneNumberKit.attachToInput(textField, 971)
phoneNumberKit.attachToInput(binding.textField, "tr")

// Setup country code picker optionally
phoneNumberKit.setupCountryPicker(
Expand All @@ -23,24 +30,25 @@ class MainActivity : AppCompatActivity() {

// Provides example phone number for given country iso2 code
val exampleNumber = phoneNumberKit.getExampleNumber("tr")
Log.d(TAG, "Example Number: $exampleNumber")

// Parses raw phone number to phone object
val parsedNumber = phoneNumberKit.parsePhoneNumber(
number = "05066120000",
defaultRegion = "us"
)
Log.d(TAG, "Parsed Number: $parsedNumber")

// Converts raw phone number to international formatted phone number
// Ex: +90 506 606 00 00
val formattedNumber = phoneNumberKit.formatPhoneNumber(
number = "05066120000",
defaultRegion = "tr"
)
Log.d(TAG, "Formatted Number: $formattedNumber")
}

// Provides country flag icon for given iso2 code
val flag = phoneNumberKit.getFlagIcon("tr")

// Provides country name, iso2 for given country code
val country = phoneNumberKit.getCountry(90)
companion object {
private const val TAG = "###"
}
}
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.android.tools.build:gradle:7.0.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -18,9 +18,10 @@ allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
34 changes: 18 additions & 16 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-parcelize'

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
minSdkVersion 19
targetSdkVersion 30
versionCode 1
versionName "1.0"
targetSdkVersion 31

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -21,6 +20,10 @@ android {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}

buildFeatures {
viewBinding true
}

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand All @@ -34,15 +37,14 @@ android {
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.google.android.material:material:1.2.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.31"
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.1'

implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'

implementation 'com.google.android.material:material:1.4.0'
implementation 'io.michaelrocks:libphonenumber-android:8.12.31'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0'
implementation 'com.github.RedMadRobot:input-mask-android:6.1.0'
}
Loading

0 comments on commit b0a738d

Please sign in to comment.