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;
}
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);
});
}
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;
}
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;
}
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();
}
Aggregations