use of dev.sagar.smsblocker.tech.beans.Conversation in project SMSBlocker by sagarpawardev.
the class HomeActivity method updateSMSinUI.
public void updateSMSinUI(SMS sms) {
final String methodName = "addSMSinUI(SMS)";
log.justEntered(methodName);
String phoneNo = sms.getAddress();
Conversation conversation = new Conversation(getApplicationContext(), sms);
log.error(methodName, "Improvement can be done here");
String formattedPhone = phoneUtils.formatNumber(this, phoneNo);
PositionLog mPositionLog = conversationMap.put(formattedPhone, conversation);
int oldPosition = mPositionLog.getOldPosition();
int newPosition = mPositionLog.getNewPosition();
if (oldPosition == -1) {
// Item Newly Added
// Moved Item to First
adapter.notifyItemInserted(0);
} else {
adapter.notifyItemMoved(oldPosition, newPosition);
adapter.notifyDataSetChanged();
}
// If List is on top
if (listIsAtTop()) {
// Scroll to first
recyclerView.scrollToPosition(0);
} else {
Toast.makeText(this, "New SMS", Toast.LENGTH_SHORT).show();
}
log.returning(methodName);
}
use of dev.sagar.smsblocker.tech.beans.Conversation 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.beans.Conversation in project SMSBlocker by sagarpawardev.
the class RVHomeAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(SMSViewHolder holder, int position) {
final String methodName = "onBindViewHolder()";
log.justEntered(methodName);
Conversation conversation = filteredConvMap.get(position);
String address = conversation.getAddress();
String fromName = conversation.getContactName();
// If SMS is selected in Multiselect mode
boolean isSelected = selectedConversations.contains(fromName);
holder.parent.setSelected(isSelected);
if (position == 0) {
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.bkg_threadoverview__top_rounded);
holder.parent.setBackground(drawable);
} else {
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.selector_threadoverview);
holder.parent.setBackground(drawable);
}
int unreadCount = conversation.getUnreadCount();
log.debug(methodName, "Unread Count of Conversation: " + unreadCount + " for address: " + address);
// If SMS is read
if (unreadCount == 0) {
holder.tvBadge.setVisibility(View.INVISIBLE);
} else {
holder.tvBadge.setVisibility(View.VISIBLE);
String strUnreadCount = String.valueOf(unreadCount);
holder.tvBadge.setText(strUnreadCount);
}
if (fromName == null)
fromName = address;
long tm = conversation.getDateTime();
String socialDate = DateUtilSingleton.getInstance().socialFormat(tm);
holder.tvTime.setText(socialDate);
holder.tvFrom.setText(fromName);
holder.tvBody.setText(conversation.getBody());
holder.tvAddress.setText(conversation.getAddress());
// Setting User Image
Uri dpUri = conversation.getPhotoThumbnailUri();
// Style DisplayPictureView
themeUtil.styleDPView(holder.dpView, dpUri, conversation);
log.returning(methodName);
}
use of dev.sagar.smsblocker.tech.beans.Conversation 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.beans.Conversation 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