Search in sources :

Example 1 with CacheContact

use of com.fanap.podchat.cachemodel.CacheContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method saveContacts.

public void saveContacts(@NonNull List<Contact> contacts, int expireAmount) {
    worker(() -> {
        List<CacheContact> cacheContacts = new ArrayList<>();
        for (Contact contact : 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());
            CacheContact cacheContact = null;
            try {
                cacheContact = getCacheContact(expireDate, contact, contact.getBlocked(), contact.getLinkedUser());
            } catch (Exception e) {
                captureException("SAVE CONTACT", e);
                continue;
            }
            cacheContacts.add(cacheContact);
        }
        messageDao.insertContacts(cacheContacts);
    });
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) SimpleDateFormat(java.text.SimpleDateFormat) CacheContact(com.fanap.podchat.cachemodel.CacheContact) Date(java.util.Date) IOException(java.io.IOException) ParseException(java.text.ParseException) 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 2 with CacheContact

use of com.fanap.podchat.cachemodel.CacheContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getContactsByFirstAndLast.

@NonNull
public List<Contact> getContactsByFirstAndLast(String firstName, String lastName) {
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = messageDao.getContactsByFirstAndLast(firstName, 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 3 with CacheContact

use of com.fanap.podchat.cachemodel.CacheContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method getContactsByEmail.

@NonNull
public List<Contact> getContactsByEmail(String email) {
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = messageDao.getContactsByEmail(email);
    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 4 with CacheContact

use of com.fanap.podchat.cachemodel.CacheContact 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 5 with CacheContact

use of com.fanap.podchat.cachemodel.CacheContact in project pod-chat-android-sdk by FanapSoft.

the class MessageDatabaseHelper method saveContact.

public void saveContact(@NonNull Contact contact, int expireSecond) {
    worker(() -> {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss", Locale.getDefault());
        Calendar c = Calendar.getInstance();
        c.setTime(new Date());
        c.add(Calendar.DATE, expireSecond);
        String expireDate = dateFormat.format(c.getTime());
        CacheContact cacheContact = getCacheContact(expireDate, contact, contact.getBlocked(), contact.getLinkedUser());
        messageDao.insertContact(cacheContact);
    });
}
Also used : Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CacheContact(com.fanap.podchat.cachemodel.CacheContact)

Aggregations

CacheContact (com.fanap.podchat.cachemodel.CacheContact)14 CacheBlockedContact (com.fanap.podchat.cachemodel.CacheBlockedContact)13 BlockedContact (com.fanap.podchat.mainmodel.BlockedContact)13 Contact (com.fanap.podchat.mainmodel.Contact)13 RequestSearchContact (com.fanap.podchat.mainmodel.RequestSearchContact)13 ResultContact (com.fanap.podchat.model.ResultContact)13 ArrayList (java.util.ArrayList)11 NonNull (android.support.annotation.NonNull)9 SimpleDateFormat (java.text.SimpleDateFormat)7 Calendar (java.util.Calendar)7 Date (java.util.Date)7 ParseException (java.text.ParseException)4 IOException (java.io.IOException)2 SimpleSQLiteQuery (android.arch.persistence.db.SimpleSQLiteQuery)1 Nullable (android.support.annotation.Nullable)1 ChatResponse (com.fanap.podchat.model.ChatResponse)1