Skip to content

Commit

Permalink
Merge pull request #11 from Willena/feature/country-whitelist
Browse files Browse the repository at this point in the history
Updated gradle scripts and implemented whitelist feature as requested…
  • Loading branch information
Willena authored Mar 17, 2022
2 parents 37dfca4 + e1d7901 commit 1a7f77f
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 74 deletions.
11 changes: 5 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 29
buildToolsVersion "25.0.3"
compileSdkVersion 31
defaultConfig {
applicationId "com.github.willena.android_phonenumber_input"
minSdkVersion 15
targetSdkVersion 29
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand All @@ -21,11 +20,11 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('androidx.test.espresso:espresso-core:3.1.0', {
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.appcompat:appcompat:1.4.1'

implementation project(":phoneinputview")
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:label="@string/app_name"
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,51 @@ public class MainActivity extends AppCompatActivity {

private PhoneInputView phoneView1;
private Button b;
private PhoneInputView phoneView2;
private PhoneInputView phoneView0;
private PhoneInputView phoneView4;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Default config
phoneView0 = (PhoneInputView) findViewById(R.id.phoneId1);
PhoneInputView phoneView0 = findViewById(R.id.phoneId1);
phoneView0.setConfig(new CountryConfigurator());


// Define number and country
b = (Button) findViewById(R.id.button_validate2);
phoneView1 = (PhoneInputView) findViewById(R.id.phoneId2);
b = findViewById(R.id.button_validate2);
phoneView1 = findViewById(R.id.phoneId2);
phoneView1.setConfig(new CountryConfigurator());
phoneView1.addOnValidEntryListener(new OnValidEntryListener() {
@Override
public void onValidEntry(Boolean valid) {
b.setEnabled(valid);
Log.d("MAINACTIVITY", "onValidEntry: " + phoneView1.getFormatedNumber());
}
phoneView1.addOnValidEntryListener(valid -> {
b.setEnabled(valid);
Log.d("MAINACTIVITY", "onValidEntry: " + phoneView1.getFormatedNumber());
});
phoneView1.setPhoneNumber("0102030405", "FR");


//Define default country value
phoneView2 = (PhoneInputView) findViewById(R.id.phoneId3);
PhoneInputView phoneView2 = findViewById(R.id.phoneId3);
CountryConfigurator config2 = new CountryConfigurator();
config2.setDefaultCountry("US");
phoneView2.setConfig(config2);


// Only flag and code
phoneView4 = (PhoneInputView) findViewById(R.id.phoneId4);
PhoneInputView phoneView4 = findViewById(R.id.phoneId4);
CountryConfigurator config = new CountryConfigurator();
config.setDisplayFlag(true);
config.setDisplayCountryCode(true);
config.setDisplayDialingCode(false);
config.setPhoneNumberHintType(null);

phoneView4.setConfig(config);


// Using whitelisted countries
PhoneInputView phoneView5 = findViewById(R.id.phoneId5);
CountryConfigurator config3 = new CountryConfigurator();
config3.setDefaultCountry("GB");
config3.setCountryWhitelist("FR", "GB", "US");
phoneView5.setConfig(config3);

}
}
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@
android:layout_width="match_parent"
android:layout_height="60dp" />


<TextView
android:id="@+id/hello5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whitelisted countries" />

<com.github.willena.phoneinputview.PhoneInputView
android:id="@+id/phoneId5"
android:layout_width="match_parent"
android:layout_height="60dp" />

</LinearLayout>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -16,7 +16,7 @@ buildscript {

allprojects {
repositories {
jcenter()
mavenCentral()
google()
}
}
Expand Down
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-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
24 changes: 10 additions & 14 deletions phoneinputview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ apply plugin: 'maven-publish'
repositories {
mavenCentral()
google()
jcenter()
maven { url "https://jitpack.io" }
}

group = 'com.github.willena'
version = '1.3.1'
version = '1.3.3'

android {
compileSdkVersion 29
buildToolsVersion '25.0.3'
compileSdkVersion 31

defaultConfig {
minSdkVersion 15
targetSdkVersion 29
versionCode 16
versionName "1.3.2"
targetSdkVersion 31
consumerProguardFiles 'proguard-rules.pro'
}

Expand All @@ -38,11 +34,11 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
testImplementation 'junit:junit:4.13.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testImplementation 'junit:junit:4.13.2'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.15'
}

Expand All @@ -52,9 +48,9 @@ afterEvaluate {
// Creates a Maven publication called "release".
release(MavenPublication) {
from components.release
groupId = 'com.github.willena'
groupId = group
artifactId = 'phonenumber-widget'
version = '1.3.2'
version = version
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.github.willena.phoneinputview;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by Guillaume on 15/04/2017.
*/

public class CountryConfigurator {


public enum HintType {
MOBILE,
FIXED,
Expand All @@ -17,13 +22,15 @@ public enum HintType {
private Boolean displayDialingCode;
private HintType phoneNumberHintType;
private String defaultCountry;
private List<String> countryWhitelist;

public CountryConfigurator() {
displayFlag = true;
displayCountryCode = true;
displayDialingCode = true;
phoneNumberHintType = HintType.MOBILE;
defaultCountry = null;
countryWhitelist = new ArrayList<>(0);
}

public void setDefaultCountry(String defaultCode) {
Expand Down Expand Up @@ -68,4 +75,19 @@ public HintType getPhoneNumberHintType() {
public String getDefaultCountry() {
return defaultCountry;
}

public List<String> getCountryWhitelist() {
return countryWhitelist;
}

/**
* @param countryWhitelist list of 2 let names
*/
public void setCountryWhitelist(String... countryWhitelist) {
this.countryWhitelist = Arrays.asList(countryWhitelist);
}

public void setCountryWhitelist(List<String> countryWhitelist) {
this.countryWhitelist = countryWhitelist;
}
}
Loading

0 comments on commit 1a7f77f

Please sign in to comment.