Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ unlinked_spec.ds

# code coverage
coverage
example/ios/Flutter/ephemeral/flutter_lldbinit
example/ios/Flutter/ephemeral/flutter_lldb_helper.py
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
analyzer:
exclude:
- "**"
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
namespace 'flutter.plugins.contactsservice.contactsservice'
compileSdkVersion 30

defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;

import static android.app.Activity.RESULT_CANCELED;
import static android.provider.ContactsContract.CommonDataKinds;
Expand All @@ -66,16 +65,6 @@ public class ContactsServicePlugin implements MethodCallHandler, FlutterPlugin,
private final ExecutorService executor =
new ThreadPoolExecutor(0, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1000));

private void initDelegateWithRegister(Registrar registrar) {
this.delegate = new ContactServiceDelegateOld(registrar);
}

public static void registerWith(Registrar registrar) {
ContactsServicePlugin instance = new ContactsServicePlugin();
instance.initInstance(registrar.messenger(), registrar.context());
instance.initDelegateWithRegister(registrar);
}

private void initInstance(BinaryMessenger messenger, Context context) {
methodChannel = new MethodChannel(messenger, "github.com/clovisnicolas/flutter_contacts");
methodChannel.setMethodCallHandler(this);
Expand Down Expand Up @@ -282,21 +271,24 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent intent)
}

if (requestCode == REQUEST_OPEN_CONTACT_PICKER) {
if (resultCode == RESULT_CANCELED) {
if (resultCode == RESULT_CANCELED || intent == null) {
finishWithResult(FORM_OPERATION_CANCELED);
return true;
}
Uri contactUri = intent.getData();
if (intent != null){
Cursor cursor = contentResolver.query(contactUri, null, null, null, null);
if (cursor.moveToFirst()) {
String id = contactUri.getLastPathSegment();
getContacts("openDeviceContactPicker", id, false, false, false, localizedLabels, this.result);
if (cursor != null) {
if (cursor.moveToFirst()) {
String id = contactUri.getLastPathSegment();
getContacts("openDeviceContactPicker", id, false, false, false, localizedLabels, this.result);
} else {
Log.e(LOG_TAG, "onActivityResult - cursor.moveToFirst() returns false");
finishWithResult(FORM_OPERATION_CANCELED);
}
cursor.close();
} else {
Log.e(LOG_TAG, "onActivityResult - cursor.moveToFirst() returns false");
finishWithResult(FORM_OPERATION_CANCELED);
}}else{return true;}
cursor.close();
}
return true;
}

Expand Down Expand Up @@ -374,25 +366,6 @@ private void openDeviceContactPicker(Result result, boolean localizedLabels) {
result.success(FORM_COULD_NOT_BE_OPEN);
}
}

private class ContactServiceDelegateOld extends BaseContactsServiceDelegate {
private final PluginRegistry.Registrar registrar;

ContactServiceDelegateOld(PluginRegistry.Registrar registrar) {
this.registrar = registrar;
registrar.addActivityResultListener(this);
}

@Override
void startIntent(Intent intent, int request) {
if (registrar.activity() != null) {
registrar.activity().startActivityForResult(intent, request);
} else {
registrar.context().startActivity(intent);
}
}
}

private class ContactServiceDelegate extends BaseContactsServiceDelegate {
private final Context context;
private ActivityPluginBinding activityPluginBinding;
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: contacts_service_example
description: Demonstrates how to use the contacts_service plugin.
environment:
sdk: '>=2.10.0 <3.0.0'
sdk: '>=2.12.0 <4.0.0'
dependencies:
flutter:
sdk: flutter
Expand Down
14 changes: 13 additions & 1 deletion ios/Classes/SwiftContactsServicePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,19 @@ public class SwiftContactsServicePlugin: NSObject, FlutterPlugin, CNContactViewC

public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "github.com/clovisnicolas/flutter_contacts", binaryMessenger: registrar.messenger())
let rootViewController = UIApplication.shared.delegate!.window!!.rootViewController!;
var rootViewController: UIViewController
if #available(iOS 13.0, *),
let sceneWindow = UIApplication.shared.connectedScenes
.compactMap({ $0 as? UIWindowScene })
.flatMap({ $0.windows })
.first(where: { $0.isKeyWindow }),
let root = sceneWindow.rootViewController {
rootViewController = root
} else if let delegate = UIApplication.shared.delegate, let win = delegate.window, let root = win?.rootViewController {
rootViewController = root
} else {
rootViewController = UIViewController()
}
let instance = SwiftContactsServicePlugin(rootViewController)
registrar.addMethodCallDelegate(instance, channel: channel)
instance.preLoadContactView()
Expand Down