Search in sources :

Example 1 with Conversation

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);
}
Also used : PositionLog(dev.sagar.smsblocker.tech.datastructures.PositionLog) Conversation(dev.sagar.smsblocker.tech.beans.Conversation)

Example 2 with Conversation

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;
}
Also used : IndexedHashMap(dev.sagar.smsblocker.tech.datastructures.IndexedHashMap) Conversation(dev.sagar.smsblocker.tech.beans.Conversation)

Example 3 with Conversation

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);
}
Also used : Drawable(android.graphics.drawable.Drawable) Conversation(dev.sagar.smsblocker.tech.beans.Conversation) Uri(android.net.Uri)

Example 4 with Conversation

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;
}
Also used : Context(android.content.Context) IndexedHashMap(dev.sagar.smsblocker.tech.datastructures.IndexedHashMap) DBHelper(dev.sagar.smsblocker.tech.service.helper.DBHelper) Conversation(dev.sagar.smsblocker.tech.beans.Conversation) Cursor(android.database.Cursor) Uri(android.net.Uri) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 5 with Conversation

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;
}
Also used : IndexedHashMap(dev.sagar.smsblocker.tech.datastructures.IndexedHashMap) Conversation(dev.sagar.smsblocker.tech.beans.Conversation)

Aggregations

Conversation (dev.sagar.smsblocker.tech.beans.Conversation)5 IndexedHashMap (dev.sagar.smsblocker.tech.datastructures.IndexedHashMap)3 Uri (android.net.Uri)2 Context (android.content.Context)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Drawable (android.graphics.drawable.Drawable)1 PositionLog (dev.sagar.smsblocker.tech.datastructures.PositionLog)1 DBHelper (dev.sagar.smsblocker.tech.service.helper.DBHelper)1