make the ConversationList IDs stable again, fixes #41

This commit is contained in:
B. Petersen
2018-09-21 21:03:14 +02:00
parent 3fe51ceab8
commit 2156236abe
2 changed files with 11 additions and 3 deletions
@@ -118,6 +118,14 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
return dcMsgList.length;
}
@Override
public long getItemId(int position) {
if (position<0 || position>=dcMsgList.length) {
return 0;
}
return dcMsgList[dcMsgList.length-1-position];
}
private @NonNull DcMsg getMsg(int position) {
if(position<0 || position>=dcMsgList.length) {
return new DcMsg(0);
@@ -131,7 +139,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
}
}
final DcMsg fromDb = dcContext.getMsg(dcMsgList[dcMsgList.length-1-position]);
final DcMsg fromDb = dcContext.getMsg((int)getItemId(position));
recordCache.put(position, new SoftReference<>(fromDb));
return fromDb;
}
@@ -183,7 +191,7 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
ConversationAdapter.ViewHolder holder = (ConversationAdapter.ViewHolder)viewHolder;
Optional<DcMsg> previous = position >= dcMsgList.length-1? Optional.absent() : Optional.of(getMsg(position+1));
Optional<DcMsg> next = position <= 0? Optional.absent() : Optional.of(getMsg(position-1));
boolean pulseHighlight = dcMsgList[position] == recordToPulseHighlight;
boolean pulseHighlight = position == recordToPulseHighlight;
holder.getItem().bind(getMsg(position), previous, next, glideRequests, locale, batchSelected, recipient, pulseHighlight);
}
@@ -184,7 +184,7 @@ public class ConversationItem extends LinearLayout
@NonNull Locale locale,
@NonNull Set<DcMsg> batchSelected,
@NonNull Recipient recipients,
boolean pulseHighlight)
boolean pulseHighlight)
{
this.messageRecord = messageRecord;
this.locale = locale;