Fix in-memory message updates.

We can also switch to using the message-specific update route for
receipts too.
This commit is contained in:
Greyson Parrelli
2022-01-03 18:46:10 -05:00
parent 0dd2397fb4
commit 0d0c74f358
6 changed files with 61 additions and 63 deletions

View File

@@ -195,13 +195,24 @@ class FixedSizePagingController<Key, Data> implements PagingController<Key> {
List<Data> updatedList = new CompressedList<>(data);
updatedList.add(position, item);
keyToPosition.put(dataSource.getKey(item), position);
rebuildKeyToPositionMap(keyToPosition, updatedList, dataSource);
data = updatedList;
liveData.postValue(updatedList);
});
}
private void rebuildKeyToPositionMap(@NonNull Map<Key, Integer> map, @NonNull List<Data> dataList, @NonNull PagedDataSource<Key, Data> dataSource) {
map.clear();
for (int i = 0, len = dataList.size(); i < len; i++) {
Data item = dataList.get(i);
if (item != null) {
map.put(dataSource.getKey(item), i);
}
}
}
private static String buildLog(int aroundIndex, String message) {
return "onDataNeededAroundIndex(" + aroundIndex + ") " + message;
}