Search in sources :

Example 1 with StructListOfContact

use of net.iGap.module.structs.StructListOfContact in project iGap-Android by KianIranian-STDG.

the class Contacts method getSearchContact.

public static void getSearchContact(String text, ContactCallback callback) {
    if (!HelperPermission.grantedContactPermission()) {
        return;
    }
    int currentItemIndex = 0;
    ArrayList<String> tempList = new ArrayList<>();
    ArrayList<StructListOfContact> contactList = new ArrayList<>();
    ContentResolver cr = G.context.getContentResolver();
    String whereString = "display_name LIKE ?";
    String[] whereParams = new String[] { "%" + text + "%" };
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, whereString, whereParams, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
    if (cur != null) {
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                currentItemIndex++;
                int contactId = cur.getInt(cur.getColumnIndex(ContactsContract.Contacts._ID));
                try {
                    if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                        Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { String.valueOf(contactId) }, null);
                        if (pCur != null) {
                            while (pCur.moveToNext()) {
                                String number = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                                if (number != null) {
                                    String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                                    if (!tempList.contains(number.replace("[\\s\\-()]", "").replace(" ", ""))) {
                                        StructListOfContact itemContact = new StructListOfContact();
                                        itemContact.setDisplayName(name);
                                        itemContact.setPhone(number);
                                        contactList.add(itemContact);
                                        tempList.add(number.replace("[\\s\\-()]", "").replace(" ", ""));
                                    }
                                }
                            }
                            pCur.close();
                        }
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (NullPointerException e1) {
                    e1.printStackTrace();
                }
                // limit search in contact
                if (currentItemIndex == 300) {
                    break;
                }
            }
        }
        cur.close();
    }
    callback.onLocalContactRetriveForSearch(contactList);
}
Also used : ArrayList(java.util.ArrayList) StructListOfContact(net.iGap.module.structs.StructListOfContact) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 2 with StructListOfContact

use of net.iGap.module.structs.StructListOfContact in project iGap-Android by KianIranian-STDG.

the class Contacts method getAllPhoneContactForServer.

private static void getAllPhoneContactForServer() {
    if (!HelperPermission.grantedContactPermission()) {
        return;
    }
    if (HelperPreferences.getInstance().readBoolean(SHP_SETTING.FILE_NAME, SHP_SETTING.EXCEED_CONTACTS_NUMBER)) {
        showLimitDialog();
        return;
    }
    String[] projectionPhones = { ContactsContract.CommonDataKinds.Phone.LOOKUP_KEY, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.LABEL, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.RawContacts.ACCOUNT_TYPE };
    ArrayList<StructListOfContact> contactList = new ArrayList<>();
    ContentResolver cr = G.context.getContentResolver();
    try {
        Cursor pCur = null;
        pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projectionPhones, null, null, null);
        if (pCur != null) {
            int count = pCur.getCount();
            if (count > 0) {
                StructListOfContact contact = null;
                String displayName;
                String number;
                while (pCur.moveToNext()) {
                    number = pCur.getString(1);
                    displayName = pCur.getString(4);
                    contact = new StructListOfContact();
                    checkContactsData(displayName, number, contact, contactList);
                }
            }
            pCur.close();
        }
        if (G.onContactFetchForServer != null) {
            G.onContactFetchForServer.onFetch(contactList, true);
        }
    } catch (Exception e) {
    // nothing
    }
}
Also used : ArrayList(java.util.ArrayList) StructListOfContact(net.iGap.module.structs.StructListOfContact) Cursor(android.database.Cursor) ContentResolver(android.content.ContentResolver)

Example 3 with StructListOfContact

use of net.iGap.module.structs.StructListOfContact in project iGap-Android by KianIranian-STDG.

the class RealmPhoneContacts method sendContactList.

public static void sendContactList(final List<StructListOfContact> list, final boolean force, final boolean getContactList) {
    if (Contacts.isSendingContactToServer) {
        return;
    }
    final List<StructListOfContact> _list = fillContactsToDB(list);
    if (_list.size() > 0) {
        if (_list.size() > PHONE_CONTACT_FETCH_LIMIT) {
            RequestUserContactImport listContact = new RequestUserContactImport();
            final int loopCount = _list.size() / PHONE_CONTACT_FETCH_LIMIT;
            tmpList = _list.subList(0, PHONE_CONTACT_FETCH_LIMIT);
            Contacts.isSendingContactToServer = true;
            addListToDB(tmpList);
            listContact.contactImport(tmpList, force, false);
            G.onQueueSendContact = new OnQueueSendContact() {

                @Override
                public void sendContact() {
                    counter++;
                    tmpList.clear();
                    if (counter <= loopCount) {
                        RequestUserContactImport listContact = new RequestUserContactImport();
                        tmpList = _list.subList(0, PHONE_CONTACT_FETCH_LIMIT);
                        addListToDB(tmpList);
                        listContact.contactImport(tmpList, force, false);
                    } else {
                        if (_list.size() % PHONE_CONTACT_FETCH_LIMIT == 0) {
                            G.onQueueSendContact = null;
                            Contacts.isSendingContactToServer = false;
                            return;
                        } else {
                            RequestUserContactImport listContact = new RequestUserContactImport();
                            tmpList = _list.subList(0, _list.size() - 1);
                            addListToDB(tmpList);
                            listContact.contactImport(tmpList, force, true);
                            G.onQueueSendContact = null;
                        }
                    }
                }
            };
        } else {
            RequestUserContactImport listContact = new RequestUserContactImport();
            addListToDB(_list);
            listContact.contactImport(_list, force, true);
            G.onQueueSendContact = new OnQueueSendContact() {

                @Override
                public void sendContact() {
                    G.onQueueSendContact = null;
                    Contacts.isSendingContactToServer = false;
                }
            };
        }
    } else if (getContactList) {
        new RequestUserContactsGetList().userContactGetList();
    }
}
Also used : OnQueueSendContact(net.iGap.observers.interfaces.OnQueueSendContact) RequestUserContactImport(net.iGap.request.RequestUserContactImport) RequestUserContactsGetList(net.iGap.request.RequestUserContactsGetList) StructListOfContact(net.iGap.module.structs.StructListOfContact)

Example 4 with StructListOfContact

use of net.iGap.module.structs.StructListOfContact in project iGap-Android by KianIranian-STDG.

the class FragmentAddContact method addContactToServer.

private void addContactToServer() {
    if (HelperPreferences.getInstance().readBoolean(SHP_SETTING.FILE_NAME, SHP_SETTING.EXCEED_CONTACTS_DIALOG)) {
        showLimitDialog();
        return;
    }
    String _phone = binding.acEdtPhoneNumber.getText().toString();
    String codeCountry = binding.acTxtCodeCountry.getText().toString();
    String saveNumber = codeCountry + _phone;
    List<StructListOfContact> contacts = new ArrayList<>();
    StructListOfContact contact = new StructListOfContact();
    contact.firstName = binding.acEdtFirstName.getText().toString();
    contact.lastName = binding.acEdtLastName.getText().toString();
    contact.phone = saveNumber;
    contacts.add(contact);
    new RequestUserContactImport().contactImport(contacts, true, RequestUserContactImport.KEY);
}
Also used : RequestUserContactImport(net.iGap.request.RequestUserContactImport) ArrayList(java.util.ArrayList) StructListOfContact(net.iGap.module.structs.StructListOfContact)

Example 5 with StructListOfContact

use of net.iGap.module.structs.StructListOfContact in project iGap-Android by KianIranian-STDG.

the class FragmentContactsProfile method addContactToServer.

/**
 * import contact to server with True force
 */
private void addContactToServer() {
    if (HelperPreferences.getInstance().readBoolean(SHP_SETTING.FILE_NAME, SHP_SETTING.EXCEED_CONTACTS_DIALOG)) {
        showLimitDialog();
        return;
    }
    List<StructListOfContact> contacts = new ArrayList<>();
    StructListOfContact contact = new StructListOfContact();
    contact.firstName = viewModel.firstName;
    contact.lastName = viewModel.lastName;
    contact.phone = viewModel.phone.get() + "";
    contacts.add(contact);
    new RequestUserContactImport().contactImport(contacts, true);
}
Also used : RequestUserContactImport(net.iGap.request.RequestUserContactImport) ArrayList(java.util.ArrayList) StructListOfContact(net.iGap.module.structs.StructListOfContact)

Aggregations

StructListOfContact (net.iGap.module.structs.StructListOfContact)7 ArrayList (java.util.ArrayList)6 ContentResolver (android.content.ContentResolver)3 Cursor (android.database.Cursor)3 RequestUserContactImport (net.iGap.request.RequestUserContactImport)3 OnQueueSendContact (net.iGap.observers.interfaces.OnQueueSendContact)1 RequestUserContactsGetList (net.iGap.request.RequestUserContactsGetList)1