Search in sources :

Example 11 with CacheContact

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

the class MessageDatabaseHelper method saveBlockedContact.

/**
 * Blocked Contacts in Cache
 *
 * @param blockedContact blocked contact
 * @param expireSecond   validation second
 */
public void saveBlockedContact(@NonNull BlockedContact blockedContact, 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());
        Contact contact = blockedContact.getContactVO();
        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);
        }
        messageDao.insertBlockedContact(cacheBlockedContact);
    });
}
Also used : CacheBlockedContact(com.fanap.podchat.cachemodel.CacheBlockedContact) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) 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 12 with CacheContact

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

the class MessageDatabaseHelper method getBlockedContacts.

@NonNull
public List<BlockedContact> getBlockedContacts(Long count, Long offset) {
    List<BlockedContact> contacts = new ArrayList<>();
    List<CacheBlockedContact> cacheBlockedContacts = messageDao.getBlockedContacts(count, offset);
    if (cacheBlockedContacts != null && cacheBlockedContacts.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 (CacheBlockedContact blockedContact : cacheBlockedContacts) {
            try {
                Date expireDate = format.parse(blockedContact.getExpireDate());
                if (expireDate != null && expireDate.compareTo(nowDate) < 0) {
                    deleteBlockedContact(blockedContact);
                } else {
                    Contact contactVO = null;
                    if (blockedContact.getContactId() > 0) {
                        CacheContact cacheContact = messageDao.getContactById(blockedContact.getContactId());
                        blockedContact.setCacheContact(cacheContact);
                    }
                    if (blockedContact.getCacheContact() != null) {
                        try {
                            contactVO = new Contact(blockedContact.getCacheContact().getId(), blockedContact.getCacheContact().getFirstName(), blockedContact.getCacheContact().getUserId(), blockedContact.getCacheContact().getLastName(), blockedContact.getCacheContact().getBlocked(), blockedContact.getCacheContact().getCreationDate(), blockedContact.getCacheContact().getLinkedUser(), blockedContact.getCacheContact().getCellphoneNumber(), blockedContact.getCacheContact().getEmail(), blockedContact.getCacheContact().getUniqueId(), blockedContact.getCacheContact().getNotSeenDuration(), blockedContact.getCacheContact().isHasUser(), true, blockedContact.getCacheContact().getProfileImage());
                        } catch (Exception e) {
                            captureException("GET BLOCK LIST", e);
                        }
                    }
                    BlockedContact blocked = new BlockedContact(blockedContact.getBlockId(), blockedContact.getFirstName(), blockedContact.getLastName(), blockedContact.getNickName(), blockedContact.getProfileImage(), blockedContact.getCoreUserId(), contactVO);
                    contacts.add(blocked);
                }
            } catch (ParseException e) {
                captureException("GET BLOCK LIST", e);
            }
        }
    }
    return contacts;
}
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) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CacheContact(com.fanap.podchat.cachemodel.CacheContact) 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) NonNull(android.support.annotation.NonNull)

Example 13 with CacheContact

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

the class MessageDatabaseHelper method getContacts.

@NonNull
public List<Contact> getContacts(Integer count, Long offset, String username) throws RoomIntegrityException {
    if (!canUseDatabase())
        throw new RoomIntegrityException();
    List<Contact> contacts = new ArrayList<>();
    List<CacheContact> cacheContacts = null;
    if (username != null) {
        cacheContacts = messageDao.getRawContacts(count, offset, username);
    } else {
        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 14 with CacheContact

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

the class MessageDatabaseHelper method getContactsByFirst.

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

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