Search in sources :

Example 1 with PositionLog

use of dev.sagar.smsblocker.tech.datastructures.PositionLog 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)

Aggregations

Conversation (dev.sagar.smsblocker.tech.beans.Conversation)1 PositionLog (dev.sagar.smsblocker.tech.datastructures.PositionLog)1