Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
emostar authored Dec 17, 2019
2 parents 6d55ca0 + 312fc90 commit 955a8f5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.0.0

* AndroidX support
* Bump libphonenumber java dep to latest version

## 0.0.4

* Another iOS fix, this time for getRegionInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;

import com.google.i18n.phonenumbers.AsYouTypeFormatter;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
Expand Down Expand Up @@ -39,6 +40,8 @@ public void onMethodCall(MethodCall call, Result result) {
break;
case "getNumberType":
handleGetNumberType(call, result);
case "formatAsYouType":
formatAsYouType(call, result);
break;
default:
result.notImplemented();
Expand Down Expand Up @@ -141,4 +144,16 @@ private void handleGetNumberType(MethodCall call, Result result) {
result.error("NumberParseException", e.getMessage(), null);
}
}

private void formatAsYouType(MethodCall call, Result result) {
final String phoneNumber = call.argument("phone_number");
final String isoCode = call.argument("iso_code");

AsYouTypeFormatter asYouTypeFormatter = phoneUtil.getAsYouTypeFormatter(isoCode.toUpperCase());
String res = null;
for (int i = 0; i < phoneNumber.length(); i++) {
res = asYouTypeFormatter.inputDigit(phoneNumber.charAt(i));
}
result.success(res);
}
}
10 changes: 5 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 27
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
Expand All @@ -35,10 +35,10 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.mathrawk.libphonenumberexample"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -56,6 +56,6 @@ flutter {

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
9 changes: 9 additions & 0 deletions ios/Classes/LibphonenumberPlugin.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "LibphonenumberPlugin.h"

#import "NBPhoneNumberUtil.h"
#import "NBAsYouTypeFormatter.h"

@interface LibphonenumberPlugin ()
@property(nonatomic, retain) NBPhoneNumberUtil *phoneUtil;
Expand All @@ -23,6 +24,14 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString *phoneNumber = call.arguments[@"phone_number"];
NSString *isoCode = call.arguments[@"iso_code"];
NBPhoneNumber *number = nil;

// Call formatAsYouType before parse below because a partial number will not be parsable.
if ([@"formatAsYouType" isEqualToString:call.method]) {
NBAsYouTypeFormatter *f = [[NBAsYouTypeFormatter alloc] initWithRegionCode:isoCode];
result([f inputString:phoneNumber]);
return;
}

if (phoneNumber != nil) {
number = [self.phoneUtil parse:phoneNumber defaultRegion:isoCode error:&err];
if (err != nil) {
Expand Down
10 changes: 10 additions & 0 deletions lib/libphonenumber.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ class PhoneNumberUtil {
}
return PhoneNumberType.values[result];
}

static Future<String> formatAsYouType({
@required String phoneNumber,
@required String isoCode,
}) async {
return await _channel.invokeMethod('formatAsYouType', {
'phone_number': phoneNumber,
'iso_code': isoCode,
});
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: libphonenumber
description: This is a Flutter implementation of libphonenumber. It includes only a few features at the moment, and are added when more functionality is desired.
version: 0.0.4
version: 1.0.0
author: Jon Keating <jon@licq.org>
homepage: https://github.com/emostar/flutter-libphonenumber

Expand Down

0 comments on commit 955a8f5

Please sign in to comment.