diff --git a/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java b/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java index 000aa5ff..3cc2a108 100644 --- a/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java +++ b/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsManager.java @@ -1,17 +1,14 @@ package com.rt2zz.reactnativecontacts; import android.content.ContentProviderOperation; -import android.content.pm.PackageManager; import android.content.ContentResolver; import android.content.Context; -import android.database.Cursor; +import android.content.pm.PackageManager; import android.provider.ContactsContract; -import android.provider.ContactsContract.RawContacts; import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.CommonDataKinds.StructuredName; -import android.net.Uri; +import android.provider.ContactsContract.RawContacts; -import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.Callback; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; @@ -19,284 +16,286 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableArray; -import com.facebook.react.bridge.WritableMap; import java.util.ArrayList; public class ContactsManager extends ReactContextBaseJavaModule { - public ContactsManager(ReactApplicationContext reactContext) { - super(reactContext); - } - - /* - * Returns all contactable records on phone - * queries CommonDataKinds.Contactables to get phones and emails - */ - @ReactMethod - public void getAll(Callback callback) { - Context context = getReactApplicationContext(); - ContentResolver cr = context.getContentResolver(); - - ContactsProvider contactsProvider = new ContactsProvider(cr, context); - WritableArray contacts = contactsProvider.getContacts(); - - callback.invoke(null, contacts); - } - - /* - * Adds contact to phone's addressbook - */ - @ReactMethod - public void addContact(ReadableMap contact, Callback callback) { - - String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null; - String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null; - String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null; - - // String name = givenName; - // name += middleName != "" ? " " + middleName : ""; - // name += familyName != "" ? " " + familyName : ""; - - ReadableArray phoneNumbers = contact.hasKey("phoneNumbers") ? contact.getArray("phoneNumbers") : null; - int numOfPhones = 0; - String[] phones = null; - Integer[] phonesLabels = null; - if (phoneNumbers != null) { - numOfPhones = phoneNumbers.size(); - phones = new String[numOfPhones]; - phonesLabels = new Integer[numOfPhones]; - for(int i=0; i < numOfPhones; i++) { - phones[i] = phoneNumbers.getMap(i).getString("number"); - String label = phoneNumbers.getMap(i).getString("label"); - phonesLabels[i] = mapStringToPhoneType(label); - } + public ContactsManager(ReactApplicationContext reactContext) { + super(reactContext); } - ReadableArray emailAddresses = contact.hasKey("emailAddresses") ? contact.getArray("emailAddresses") : null; - int numOfEmails = 0; - String[] emails = null; - Integer[] emailsLabels = null; - if (emailAddresses != null) { - numOfEmails = emailAddresses.size(); - emails = new String[numOfEmails]; - emailsLabels = new Integer[numOfEmails]; - for(int i=0; i < numOfEmails; i++) { - emails[i] = emailAddresses.getMap(i).getString("email"); - String label = emailAddresses.getMap(i).getString("label"); - emailsLabels[i] = mapStringToEmailType(label); - } + /* + * Returns all contactable records on phone + * queries CommonDataKinds.Contactables to get phones and emails + */ + @ReactMethod + public void getAll(Callback callback) { + Context context = getReactApplicationContext(); + ContentResolver cr = context.getContentResolver(); + + ContactsProvider contactsProvider = new ContactsProvider(cr, context); + WritableArray contacts = contactsProvider.getContacts(); + + callback.invoke(null, contacts); } - ArrayList ops = new ArrayList(); - - ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) - .withValue(RawContacts.ACCOUNT_TYPE, null) - .withValue(RawContacts.ACCOUNT_NAME, null); - ops.add(op.build()); - - op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) - // .withValue(StructuredName.DISPLAY_NAME, name) - .withValue(StructuredName.GIVEN_NAME, givenName) - .withValue(StructuredName.MIDDLE_NAME, middleName) - .withValue(StructuredName.FAMILY_NAME, familyName); - ops.add(op.build()); - - //TODO not sure where to allow yields - op.withYieldAllowed(true); - - for (int i=0; i < numOfPhones; i++) { - op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) - .withValue(CommonDataKinds.Phone.NUMBER, phones[i]) - .withValue(CommonDataKinds.Phone.TYPE, phonesLabels[i]); - ops.add(op.build()); + /* + * Adds contact to phone's addressbook + */ + @ReactMethod + public void addContact(ReadableMap contact, Callback callback) { + + String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null; + String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null; + String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null; + + // String name = givenName; + // name += middleName != "" ? " " + middleName : ""; + // name += familyName != "" ? " " + familyName : ""; + + ReadableArray phoneNumbers = contact.hasKey("phoneNumbers") ? contact.getArray("phoneNumbers") : null; + int numOfPhones = 0; + String[] phones = null; + Integer[] phonesLabels = null; + if (phoneNumbers != null) { + numOfPhones = phoneNumbers.size(); + phones = new String[numOfPhones]; + phonesLabels = new Integer[numOfPhones]; + for (int i = 0; i < numOfPhones; i++) { + phones[i] = phoneNumbers.getMap(i).getString("number"); + String label = phoneNumbers.getMap(i).getString("label"); + phonesLabels[i] = mapStringToPhoneType(label); + } + } + + ReadableArray emailAddresses = contact.hasKey("emailAddresses") ? contact.getArray("emailAddresses") : null; + int numOfEmails = 0; + String[] emails = null; + Integer[] emailsLabels = null; + if (emailAddresses != null) { + numOfEmails = emailAddresses.size(); + emails = new String[numOfEmails]; + emailsLabels = new Integer[numOfEmails]; + for (int i = 0; i < numOfEmails; i++) { + emails[i] = emailAddresses.getMap(i).getString("email"); + String label = emailAddresses.getMap(i).getString("label"); + emailsLabels[i] = mapStringToEmailType(label); + } + } + + ArrayList ops = new ArrayList(); + + ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI) + .withValue(RawContacts.ACCOUNT_TYPE, null) + .withValue(RawContacts.ACCOUNT_NAME, null); + ops.add(op.build()); + + op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) + // .withValue(StructuredName.DISPLAY_NAME, name) + .withValue(StructuredName.GIVEN_NAME, givenName) + .withValue(StructuredName.MIDDLE_NAME, middleName) + .withValue(StructuredName.FAMILY_NAME, familyName); + ops.add(op.build()); + + //TODO not sure where to allow yields + op.withYieldAllowed(true); + + for (int i = 0; i < numOfPhones; i++) { + op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(CommonDataKinds.Phone.NUMBER, phones[i]) + .withValue(CommonDataKinds.Phone.TYPE, phonesLabels[i]); + ops.add(op.build()); + } + + for (int i = 0; i < numOfEmails; i++) { + op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) + .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) + .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) + .withValue(CommonDataKinds.Email.ADDRESS, emails[i]) + .withValue(CommonDataKinds.Email.TYPE, emailsLabels[i]); + ops.add(op.build()); + } + + Context ctx = getReactApplicationContext(); + try { + ContentResolver cr = ctx.getContentResolver(); + cr.applyBatch(ContactsContract.AUTHORITY, ops); + callback.invoke(); // success + } catch (Exception e) { + callback.invoke(e.toString()); + } } - for (int i=0; i < numOfEmails; i++) { - op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI) - .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) - .withValue(CommonDataKinds.Email.ADDRESS, emails[i]) - .withValue(CommonDataKinds.Email.TYPE, emailsLabels[i]); - ops.add(op.build()); + /* + * Update contact to phone's addressbook + */ + @ReactMethod + public void updateContact(ReadableMap contact, Callback callback) { + + String recordID = contact.hasKey("recordID") ? contact.getString("recordID") : null; + + String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null; + String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null; + String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null; + + ReadableArray phoneNumbers = contact.hasKey("phoneNumbers") ? contact.getArray("phoneNumbers") : null; + int numOfPhones = 0; + String[] phones = null; + Integer[] phonesLabels = null; + if (phoneNumbers != null) { + numOfPhones = phoneNumbers.size(); + phones = new String[numOfPhones]; + phonesLabels = new Integer[numOfPhones]; + for (int i = 0; i < numOfPhones; i++) { + ReadableMap phoneMap = phoneNumbers.getMap(i); + String phoneNumber = phoneMap.getString("number"); + String phoneLabel = phoneMap.getString("label"); + phones[i] = phoneNumber; + phonesLabels[i] = mapStringToPhoneType(phoneLabel); + } + } + + ReadableArray emailAddresses = contact.hasKey("emailAddresses") ? contact.getArray("emailAddresses") : null; + int numOfEmails = 0; + String[] emails = null; + Integer[] emailsLabels = null; + if (emailAddresses != null) { + numOfEmails = emailAddresses.size(); + emails = new String[numOfEmails]; + emailsLabels = new Integer[numOfEmails]; + for (int i = 0; i < numOfEmails; i++) { + ReadableMap emailMap = emailAddresses.getMap(i); + emails[i] = emailMap.getString("email"); + String label = emailMap.getString("label"); + emailsLabels[i] = mapStringToEmailType(label); + } + } + + ArrayList ops = new ArrayList(); + + ContentProviderOperation.Builder op = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI) + .withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[]{String.valueOf(recordID)}) + .withValue(RawContacts.ACCOUNT_TYPE, null) + .withValue(RawContacts.ACCOUNT_NAME, null); + ops.add(op.build()); + + op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) + .withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[]{String.valueOf(recordID)}) + .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) + .withValue(StructuredName.GIVEN_NAME, givenName) + .withValue(StructuredName.MIDDLE_NAME, middleName) + .withValue(StructuredName.FAMILY_NAME, familyName); + ops.add(op.build()); + + op.withYieldAllowed(true); + + for (int i = 0; i < numOfPhones; i++) { + op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) + .withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?", new String[]{String.valueOf(recordID), ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE}) + .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) + .withValue(CommonDataKinds.Phone.NUMBER, phones[i]) + .withValue(CommonDataKinds.Phone.TYPE, phonesLabels[i]); + ops.add(op.build()); + } + + for (int i = 0; i < numOfEmails; i++) { + op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) + .withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?", new String[]{String.valueOf(recordID), ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}) + .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) + .withValue(CommonDataKinds.Email.ADDRESS, emails[i]) + .withValue(CommonDataKinds.Email.TYPE, emailsLabels[i]); + ops.add(op.build()); + } + + Context ctx = getReactApplicationContext(); + try { + ContentResolver cr = ctx.getContentResolver(); + cr.applyBatch(ContactsContract.AUTHORITY, ops); + callback.invoke(); // success + } catch (Exception e) { + callback.invoke(e.toString()); + } } - Context ctx = getReactApplicationContext(); - try { - ContentResolver cr = ctx.getContentResolver(); - cr.applyBatch(ContactsContract.AUTHORITY, ops); - callback.invoke(); // success - } catch (Exception e) { - callback.invoke(e.toString()); + /* + * Check permission + */ + @ReactMethod + public void checkPermission(Callback callback) { + callback.invoke(null, isPermissionGranted()); } - } - - /* - * Update contact to phone's addressbook - */ - @ReactMethod - public void updateContact(ReadableMap contact, Callback callback) { - - String recordID = contact.hasKey("recordID") ? contact.getString("recordID") : null; - - String givenName = contact.hasKey("givenName") ? contact.getString("givenName") : null; - String middleName = contact.hasKey("middleName") ? contact.getString("middleName") : null; - String familyName = contact.hasKey("familyName") ? contact.getString("familyName") : null; - - ReadableArray phoneNumbers = contact.hasKey("phoneNumbers") ? contact.getArray("phoneNumbers") : null; - int numOfPhones = 0; - String[] phones = null; - Integer[] phonesLabels = null; - if (phoneNumbers != null) { - numOfPhones = phoneNumbers.size(); - phones = new String[numOfPhones]; - phonesLabels = new Integer[numOfPhones]; - for (int i = 0; i < numOfPhones; i++) { - ReadableMap phoneMap = phoneNumbers.getMap(i); - String phoneNumber = phoneMap.getString("number"); - String phoneLabel = phoneMap.getString("label"); - phones[i] = phoneNumber; - phonesLabels[i] = mapStringToPhoneType(phoneLabel); - } - } - - ReadableArray emailAddresses = contact.hasKey("emailAddresses") ? contact.getArray("emailAddresses") : null; - int numOfEmails = 0; - String[] emails = null; - Integer[] emailsLabels = null; - if (emailAddresses != null) { - numOfEmails = emailAddresses.size(); - emails = new String[numOfEmails]; - emailsLabels = new Integer[numOfEmails]; - for (int i = 0; i < numOfEmails; i++) { - ReadableMap emailMap = emailAddresses.getMap(i); - emails[i] = emailMap.getString("email"); - String label = emailMap.getString("label"); - emailsLabels[i] = mapStringToEmailType(label); - } - } - - ArrayList ops = new ArrayList(); - - ContentProviderOperation.Builder op = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI) - .withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[]{String.valueOf(recordID)}) - .withValue(RawContacts.ACCOUNT_TYPE, null) - .withValue(RawContacts.ACCOUNT_NAME, null); - ops.add(op.build()); - - op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) - .withSelection(ContactsContract.Data.CONTACT_ID + "=?", new String[]{String.valueOf(recordID)}) - .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE) - .withValue(StructuredName.GIVEN_NAME, givenName) - .withValue(StructuredName.MIDDLE_NAME, middleName) - .withValue(StructuredName.FAMILY_NAME, familyName); - ops.add(op.build()); - - op.withYieldAllowed(true); - - for (int i = 0; i < numOfPhones; i++) { - op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) - .withSelection(ContactsContract.Data.CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?", new String[]{String.valueOf(recordID), ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE}) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Phone.CONTENT_ITEM_TYPE) - .withValue(CommonDataKinds.Phone.NUMBER, phones[i]) - .withValue(CommonDataKinds.Phone.TYPE, phonesLabels[i]); - ops.add(op.build()); - } - - for (int i = 0; i < numOfEmails; i++) { - op = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI) - .withSelection(ContactsContract.Data.RAW_CONTACT_ID + "=? AND " + ContactsContract.Data.MIMETYPE + " = ?", new String[]{String.valueOf(recordID), ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE}) - .withValue(ContactsContract.Data.MIMETYPE, CommonDataKinds.Email.CONTENT_ITEM_TYPE) - .withValue(CommonDataKinds.Email.ADDRESS, emails[i]) - .withValue(CommonDataKinds.Email.TYPE, emailsLabels[i]); - ops.add(op.build()); - } - - Context ctx = getReactApplicationContext(); - try { - ContentResolver cr = ctx.getContentResolver(); - cr.applyBatch(ContactsContract.AUTHORITY, ops); - callback.invoke(); // success - } catch (Exception e) { - callback.invoke(e.toString()); - } - } - /* - * Check permission - */ - @ReactMethod - public void checkPermission(Callback callback) { - callback.invoke(null, isPermissionGranted()); - } - - /* - * Request permission - */ - @ReactMethod - public void requestPermission(Callback callback) { - callback.invoke(null, isPermissionGranted()); - } - - /* - * Check if READ_CONTACTS permission is granted - */ - private String isPermissionGranted() { - String permission = "android.permission.READ_CONTACTS"; - // return -1 for denied and 1 - int res = getReactApplicationContext().checkCallingOrSelfPermission(permission); - return (res == PackageManager.PERMISSION_GRANTED) ? "authorized" : "denied"; - } - - /* - * TODO support all phone types - * http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html - */ - private int mapStringToPhoneType(String label) { - int phoneType; - switch (label) { - case "home": - phoneType = CommonDataKinds.Phone.TYPE_HOME; - break; - case "work": - phoneType = CommonDataKinds.Phone.TYPE_WORK; - break; - case "mobile": - phoneType = CommonDataKinds.Phone.TYPE_MOBILE; - break; - default: phoneType = CommonDataKinds.Phone.TYPE_OTHER; - break; + + /* + * Request permission + */ + @ReactMethod + public void requestPermission(Callback callback) { + callback.invoke(null, isPermissionGranted()); } - return phoneType; - } - - /* - * TODO support TYPE_CUSTOM - * http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html - */ - private int mapStringToEmailType(String label) { - int emailType; - switch (label) { - case "home": - emailType = CommonDataKinds.Email.TYPE_HOME; - break; - case "work": - emailType = CommonDataKinds.Email.TYPE_WORK; - break; - case "mobile": - emailType = CommonDataKinds.Email.TYPE_MOBILE; - break; - default: emailType = CommonDataKinds.Email.TYPE_OTHER; - break; + + /* + * Check if READ_CONTACTS permission is granted + */ + private String isPermissionGranted() { + String permission = "android.permission.READ_CONTACTS"; + // return -1 for denied and 1 + int res = getReactApplicationContext().checkCallingOrSelfPermission(permission); + return (res == PackageManager.PERMISSION_GRANTED) ? "authorized" : "denied"; + } + + /* + * TODO support all phone types + * http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Phone.html + */ + private int mapStringToPhoneType(String label) { + int phoneType; + switch (label) { + case "home": + phoneType = CommonDataKinds.Phone.TYPE_HOME; + break; + case "work": + phoneType = CommonDataKinds.Phone.TYPE_WORK; + break; + case "mobile": + phoneType = CommonDataKinds.Phone.TYPE_MOBILE; + break; + default: + phoneType = CommonDataKinds.Phone.TYPE_OTHER; + break; + } + return phoneType; } - return emailType; - } - @Override - public String getName() { - return "Contacts"; - } + /* + * TODO support TYPE_CUSTOM + * http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.Email.html + */ + private int mapStringToEmailType(String label) { + int emailType; + switch (label) { + case "home": + emailType = CommonDataKinds.Email.TYPE_HOME; + break; + case "work": + emailType = CommonDataKinds.Email.TYPE_WORK; + break; + case "mobile": + emailType = CommonDataKinds.Email.TYPE_MOBILE; + break; + default: + emailType = CommonDataKinds.Email.TYPE_OTHER; + break; + } + return emailType; + } + + @Override + public String getName() { + return "Contacts"; + } } diff --git a/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java b/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java index 4cbb3e5b..e7866765 100644 --- a/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java +++ b/android/src/main/java/com/rt2zz/reactnativecontacts/ContactsProvider.java @@ -1,7 +1,7 @@ package com.rt2zz.reactnativecontacts; -import android.content.Context; import android.content.ContentResolver; +import android.content.Context; import android.database.Cursor; import android.net.Uri; import android.provider.ContactsContract; @@ -13,17 +13,20 @@ import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.io.BufferedInputStream; -import java.io.InputStream; -import java.io.File; -import java.io.FileOutputStream; -import static android.provider.ContactsContract.CommonDataKinds.*; +import static android.provider.ContactsContract.CommonDataKinds.Contactables; +import static android.provider.ContactsContract.CommonDataKinds.Email; +import static android.provider.ContactsContract.CommonDataKinds.Phone; +import static android.provider.ContactsContract.CommonDataKinds.StructuredName; public class ContactsProvider { public static final int ID_FOR_PROFILE_CONTACT = -1; @@ -192,7 +195,7 @@ private Map loadContactsFrom(Cursor cursor) { label = "mobile"; break; case Email.TYPE_CUSTOM: - if(cursor.getString(cursor.getColumnIndex(Email.LABEL)) != null){ + if (cursor.getString(cursor.getColumnIndex(Email.LABEL)) != null) { label = cursor.getString(cursor.getColumnIndex(Email.LABEL)).toLowerCase(); } else { label = ""; diff --git a/android/src/main/java/com/rt2zz/reactnativecontacts/ReactNativeContacts.java b/android/src/main/java/com/rt2zz/reactnativecontacts/ReactNativeContacts.java index 6d846999..632ea1f4 100644 --- a/android/src/main/java/com/rt2zz/reactnativecontacts/ReactNativeContacts.java +++ b/android/src/main/java/com/rt2zz/reactnativecontacts/ReactNativeContacts.java @@ -1,31 +1,34 @@ package com.rt2zz.reactnativecontacts; -import java.util.*; - import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + public class ReactNativeContacts implements ReactPackage { - @Override - public List createNativeModules( - ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); - modules.add(new ContactsManager(reactContext)); - return modules; - } + modules.add(new ContactsManager(reactContext)); + return modules; + } - @Override - public List> createJSModules() { - return Collections.emptyList(); - } + @Override + public List> createJSModules() { + return Collections.emptyList(); + } - @Override - public List createViewManagers(ReactApplicationContext reactContext) { - return Arrays.asList(); - } + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Arrays.asList(); + } }