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