use of dev.sagar.smsblocker.tech.datastructures.IndexedHashMap in project SMSBlocker by sagarpawardev.
the class ConversationMapFilter method performFiltering.
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
String searchStr = charSequence.toString().toLowerCase();
IndexedHashMap<String, Conversation> filteredConvMap = new IndexedHashMap<>();
if (searchStr.isEmpty()) {
filteredConvMap.update(conversationMap);
} else {
for (int i = 0; i < conversationMap.size(); i++) {
Conversation conv = conversationMap.get(i);
String addr = conv.getAddress().toLowerCase();
String displayName = conv.getContactName();
String body = conv.getBody().toLowerCase();
if (displayName != null)
displayName = displayName.toLowerCase();
if (addr.contains(searchStr) || (displayName != null && displayName.contains(searchStr)) || body.contains(searchStr)) {
filteredConvMap.put(addr, conv);
}
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = filteredConvMap;
return filterResults;
}
use of dev.sagar.smsblocker.tech.datastructures.IndexedHashMap in project SMSBlocker by sagarpawardev.
the class InboxUtil method getLatestMsgs.
/**
* Helps in getting most recent SMSes from all contacts
* @return key-value pair of contact_number and most_recent_message <Contact Number, Most Recent Message>
*/
public IndexedHashMap<String, SMS> getLatestMsgs() {
final String methodName = "getLatestMsgs()";
log.justEntered(methodName);
final String m_threadid = Telephony.Sms.Conversations.THREAD_ID;
final String mSnippet = Telephony.Sms.Conversations.SNIPPET;
final String mMessageCount = Telephony.Sms.Conversations.MESSAGE_COUNT;
final String mDate = Telephony.Sms.Conversations.DATE;
ContentResolver mContentResolver = context.getContentResolver();
Uri mConversationUri = Telephony.Sms.Conversations.CONTENT_URI;
IndexedHashMap<String, SMS> smsMap = new IndexedHashMap<>();
String[] mProjection = { m_threadid, mSnippet, mMessageCount };
String mSelection = "";
String[] mSelectionArgs = {};
String mSortOrder = mDate + " DESC";
Cursor mConversation = dbService.query(mContentResolver, mConversationUri, mProjection, mSelection, mSelectionArgs, mSortOrder);
log.info(methodName, "Reading Messages..");
if (mConversation == null) {
log.info(methodName, "Conversation Query returned null cursor");
return smsMap;
}
log.info(methodName, "Conversation Count: " + mConversation.getCount());
// Collecting ThreadId from Conversation Starts
String[] conversations = new String[mConversation.getCount()];
int count = 0;
while (mConversation.moveToNext()) {
conversations[count++] = mConversation.getString(mConversation.getColumnIndexOrThrow(m_threadid));
}
Uri mLatestSmsUri = Telephony.Sms.CONTENT_URI;
String[] mLatestSmsProjection = { _id, address, body, read, date, subscriptionId, type };
StringBuilder sb = new StringBuilder(threadId + " IN (");
for (int i = 0; i < conversations.length; i++) {
sb.append("?");
if (i != conversations.length - 1) {
// If not last index
sb.append(",");
}
}
sb.append(")");
String mLatestSmsSelection = sb.toString();
String[] mLatestSmsSelectionArgs = conversations;
String mLatestSmsSortOrder = this.date + " desc";
// -- Collecting ThreadId from Conversation Ends
Cursor mLatestSmsCursor = mContentResolver.query(mLatestSmsUri, mLatestSmsProjection, mLatestSmsSelection, mLatestSmsSelectionArgs, mLatestSmsSortOrder);
if (mLatestSmsCursor == null) {
log.info(methodName, "Latest SMS Query returned null cursor");
return smsMap;
}
while (mLatestSmsCursor.moveToNext()) {
String id = mLatestSmsCursor.getString(mLatestSmsCursor.getColumnIndexOrThrow(this._id));
String from = mLatestSmsCursor.getString(mLatestSmsCursor.getColumnIndexOrThrow(this.address));
String body = mLatestSmsCursor.getString(mLatestSmsCursor.getColumnIndexOrThrow(this.body));
int serviceCenter = mLatestSmsCursor.getInt(mLatestSmsCursor.getColumnIndexOrThrow(this.subscriptionId));
boolean readState = mLatestSmsCursor.getInt(mLatestSmsCursor.getColumnIndex(this.read)) == 1;
long time = mLatestSmsCursor.getLong(mLatestSmsCursor.getColumnIndexOrThrow(this.date));
long type = mLatestSmsCursor.getLong(mLatestSmsCursor.getColumnIndexOrThrow(this.type));
if (smsMap.containsKey(from)) {
continue;
}
SMS sms = new SMS();
sms.setId(id);
sms.setAddress(from);
sms.setBody(body);
sms.setRead(readState);
sms.setDateTime(time);
sms.setType(type);
sms.setSubscription(serviceCenter);
log.debug(methodName, from + "\t" + body + "\t" + id);
smsMap.put(from, sms);
}
mLatestSmsCursor.close();
mConversation.close();
log.returning(methodName);
return smsMap;
}
use of dev.sagar.smsblocker.tech.datastructures.IndexedHashMap in project SMSBlocker by sagarpawardev.
the class LatestMsgHandler method doInBackground.
@Override
protected IndexedHashMap<String, Conversation> doInBackground(Context... contexts) {
final String methodName = "doInBackground()";
log.justEntered(methodName);
Context context = contexts[0];
IndexedHashMap<String, Conversation> convMap = new IndexedHashMap<>();
DBHelper dbHelper = new DBHelper(context);
SQLiteDatabase db = dbHelper.getReadableDatabase();
String[] projection = { "*" };
String selection = null;
String[] selectionArgs = null;
String mSortOrder = date + " DESC";
Cursor c = db.query(Converesation.TABLE_NAME, projection, selection, selectionArgs, null, null, mSortOrder);
if (c == null) {
log.info(methodName, "Cursor for conversation Query Returned null");
return convMap;
}
log.info(methodName, "Latest Messages Cursor returned rows count: " + c.getCount());
while (c.moveToNext()) {
String address = c.getString(c.getColumnIndexOrThrow(this.address));
String id = c.getString(c.getColumnIndexOrThrow(this._id));
String body = c.getString(c.getColumnIndexOrThrow(this.body));
int subscriptionId = c.getInt(c.getColumnIndexOrThrow(this.subscriptionId));
boolean readState = c.getInt(c.getColumnIndex(this.read)) == 1;
long time = c.getLong(c.getColumnIndexOrThrow(this.date));
long type = c.getLong(c.getColumnIndexOrThrow(this.type));
String strPhotoUri = c.getString(c.getColumnIndexOrThrow(this.photo));
String strPhotoThumbUri = c.getString(c.getColumnIndexOrThrow(this.photothumb));
String contactName = c.getString(c.getColumnIndexOrThrow(this.contactName));
int unreadCount = c.getInt(c.getColumnIndexOrThrow(this.unreadCount));
Uri uriPhoto = null;
if (strPhotoUri != null) {
uriPhoto = Uri.parse(strPhotoUri);
}
Uri uriPhotoThumb = null;
if (strPhotoThumbUri != null) {
uriPhotoThumb = Uri.parse(strPhotoThumbUri);
}
Conversation conversation = new Conversation();
conversation.setAddress(address);
conversation.setSmsId(id);
conversation.setBody(body);
conversation.setSubscriptionId(subscriptionId);
conversation.setReadState(readState);
conversation.setDateTime(time);
conversation.setType(type);
conversation.setPhotoUri(uriPhoto);
conversation.setPhotoThumbnailUri(uriPhotoThumb);
conversation.setContactName(contactName);
conversation.setUnreadCount(unreadCount);
convMap.put(address, conversation);
}
c.close();
dbHelper.close();
log.returning(methodName);
return convMap;
}
use of dev.sagar.smsblocker.tech.datastructures.IndexedHashMap in project SMSBlocker by sagarpawardev.
the class ConversationUnreadFilter method performFiltering.
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
IndexedHashMap<String, Conversation> filteredConvMap = new IndexedHashMap<>();
if (charSequence == null) {
filteredConvMap.update(conversationMap);
} else {
for (int i = 0; i < conversationMap.size(); i++) {
Conversation conv = conversationMap.get(i);
boolean isRead = conv.isRead();
String addr = conv.getAddress();
if (!isRead) {
filteredConvMap.put(addr, conv);
}
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = filteredConvMap;
return filterResults;
}
Aggregations