Search in sources :

Example 6 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getContactByCell.

@NonNull
public List<Contact> getContactByCell(String cellphoneNumber) {
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = messageDao.getContactByCell(cellphoneNumber);
    if (cacheContacts != null) {
        for (CacheContact cacheContact : cacheContacts) {
            Contact contact = new Contact(cacheContact.getId(), cacheContact.getFirstName(), cacheContact.getUserId(), cacheContact.getLastName(), cacheContact.getBlocked(), cacheContact.getCreationDate(), cacheContact.getLinkedUser(), cacheContact.getCellphoneNumber(), cacheContact.getEmail(), cacheContact.getUniqueId(), cacheContact.getNotSeenDuration(), cacheContact.isHasUser());
            contacts.add(contact);
        }
    }
    return contacts;
}
Also used : ArrayList(java.util.ArrayList) CacheContact(com.fanap.podchat.cachemodel.CacheContact) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) NonNull(android.support.annotation.NonNull)

Example 7 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method saveBlockedContacts.

public void saveBlockedContacts(@NonNull List<BlockedContact> contacts, int expireAmount) {
    worker(() -> {
        List<CacheBlockedContact> cacheBlockedContacts = new ArrayList<>();
        for (BlockedContact blockedContact : contacts) {
            SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
            Calendar c = Calendar.getInstance();
            c.setTime(new Date());
            c.add(Calendar.SECOND, expireAmount);
            String expireDate = format.format(c.getTime());
            @Nullable Contact contact = blockedContact.getContactVO();
            // BlockedContact to CacheBlockedContact
            CacheBlockedContact cacheBlockedContact;
            if (contact != null) {
                CacheContact cacheContact = getCacheContact(expireDate, contact, true, null);
                cacheBlockedContact = getCacheBlockedContact(blockedContact, expireDate, cacheContact);
                saveContactVoInBlockedContact(cacheContact);
            } else {
                cacheBlockedContact = getCacheBlockedContact(blockedContact, expireDate, null);
            }
            cacheBlockedContacts.add(cacheBlockedContact);
        }
        if (cacheBlockedContacts.size() > 0)
            messageDao.insertBlockedContacts(cacheBlockedContacts);
    });
}
Also used : CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Nullable(android.support.annotation.Nullable) CacheContact(com.fanap.podchat.cachemodel.CacheContact) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact)

Example 8 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getContactsByLast.

@NonNull
public List<Contact> getContactsByLast(String lastName) {
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = messageDao.getContactsByLast(lastName);
    if (cacheContacts != null) {
        for (CacheContact cacheContact : cacheContacts) {
            Contact contact = new Contact(cacheContact.getId(), cacheContact.getFirstName(), cacheContact.getUserId(), cacheContact.getLastName(), cacheContact.getBlocked(), cacheContact.getCreationDate(), cacheContact.getLinkedUser(), cacheContact.getCellphoneNumber(), cacheContact.getEmail(), cacheContact.getUniqueId(), cacheContact.getNotSeenDuration(), cacheContact.isHasUser());
            contacts.add(contact);
        }
    }
    return contacts;
}
Also used : ArrayList(java.util.ArrayList) CacheContact(com.fanap.podchat.cachemodel.CacheContact) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) NonNull(android.support.annotation.NonNull)

Example 9 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getContacts.

@NonNull
public List<Contact> getContacts(Integer count, Long offset) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = messageDao.getContacts(count, offset);
    if (cacheContacts != null && cacheContacts.size() > 0) {
        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        Date nowDate = c.getTime();
        for (CacheContact cacheContact : cacheContacts) {
            try {
                Date expireDate = format.parse(cacheContact.getExpireDate());
                if (expireDate != null && expireDate.compareTo(nowDate) < 0) {
                    deleteContact(cacheContact);
                } else {
                    Contact contact = new Contact(cacheContact.getId(), cacheContact.getFirstName(), cacheContact.getUserId(), cacheContact.getLastName(), cacheContact.getBlocked(), cacheContact.getCreationDate(), cacheContact.getLinkedUser(), cacheContact.getCellphoneNumber(), cacheContact.getEmail(), cacheContact.getUniqueId(), cacheContact.getNotSeenDuration(), cacheContact.isHasUser());
                    contact.setCache(true);
                    contacts.add(contact);
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    }
    return contacts;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) CacheContact(com.fanap.podchat.cachemodel.CacheContact) Date(java.util.Date) ResultContact(com.fanap.podchat.model.ResultContact) BlockedContact(com.fanap.podchat.mainmodel.BlockedContact) RequestSearchContact(com.fanap.podchat.mainmodel.RequestSearchContact) Contact(com.fanap.podchat.mainmodel.Contact) CacheContact(com.fanap.podchat.cachemodel.CacheContact) CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) NonNull(android.support.annotation.NonNull)

Example 10 with Contact

use of com.fanap.podchat.mainmodel.Contact in project pod-chat-android-sdk by FanapSoft.

the class DbTest method getPhoneContact.

@Test
public void getPhoneContact() {
    String name;
    String phoneNumber;
    String lastName;
    int version;
    Cursor cursor = appContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    if (cursor == null)
        throw new AssertionError();
    ArrayList<Contact> storeContacts = new ArrayList<>();
    while (cursor.moveToNext()) {
        name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        lastName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME));
        version = cursor.getInt(cursor.getColumnIndex(ContactsContract.RawContacts.VERSION));
        // creationDate = Long.valueOf(cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_LAST_UPDATED_TIMESTAMP)));
        phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        Contact contact = new Contact();
        char ch1 = phoneNumber.charAt(0);
        if (!Character.toString(ch1).equals("+")) {
            contact.setCellphoneNumber(phoneNumber.replaceAll(Character.toString(ch1), "+98"));
        }
        contact.setCellphoneNumber(phoneNumber.replaceAll(" ", ""));
        contact.setFirstName(name.replaceAll(" ", ""));
        contact.setLastName(lastName.replaceAll(" ", ""));
        storeContacts.add(contact);
    }
    cursor.close();
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) Contact(com.fanap.podchat.mainmodel.Contact) Test(org.junit.Test)

Aggregations

Contact (com.fanap.podchat.mainmodel.Contact)30 ResultContact (com.fanap.podchat.model.ResultContact)22 ArrayList (java.util.ArrayList)20 RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)17 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)15 CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)13 CacheContact (com.fanap.podchat.cachemodel.CacheContact)13 Test (org.junit.Test)12 NonNull (android.support.annotation.NonNull)11 RequestGetContact (com.fanap.podchat.requestobject.RequestGetContact)9 LargeTest (android.support.test.filters.LargeTest)8 Invitee (com.fanap.podchat.mainmodel.Invitee)8 ChatResponse (com.fanap.podchat.model.ChatResponse)8 SimpleDateFormat (java.text.SimpleDateFormat)6 Calendar (java.util.Calendar)6 Date (java.util.Date)6 ChatListener (com.fanap.podchat.chat.ChatListener)5 AssistantVo (com.fanap.podchat.chat.assistant.model.AssistantVo)5 ResultAddContact (com.fanap.podchat.model.ResultAddContact)5 RegisterAssistantRequest (com.fanap.podchat.chat.assistant.request_model.RegisterAssistantRequest)4