Add some paging changes

Increase page size and prefetch distance to avoid some updating problems, use DataSource instead of PageKeyedDataSource
This commit is contained in:
Shinokuni 2019-09-28 17:16:53 +02:00
parent a202dcc395
commit 6751e9acca
3 changed files with 12 additions and 6 deletions

View File

@ -122,8 +122,10 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
@Override @Override
public void onBindViewHolder(@NonNull ItemViewHolder viewHolder, int i) { public void onBindViewHolder(@NonNull ItemViewHolder viewHolder, int i) {
ItemWithFeed itemWithFeed = getItem(i); ItemWithFeed itemWithFeed = getItem(i);
viewHolder.bind(itemWithFeed); if (itemWithFeed == null)
return;
viewHolder.bind(itemWithFeed);
viewHolder.setImages(itemWithFeed); viewHolder.setImages(itemWithFeed);
viewHolder.applyColors(itemWithFeed); viewHolder.applyColors(itemWithFeed);
@ -161,8 +163,12 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
} }
public void clearSelection() { public void clearSelection() {
LinkedHashSet<Integer> localSelection = new LinkedHashSet<>(selection);
selection.clear(); selection.clear();
notifyDataSetChanged();
for (int position : localSelection) {
notifyItemChanged(position, getItem(position));
}
} }
public LinkedHashSet<Integer> getSelection() { public LinkedHashSet<Integer> getSelection() {

View File

@ -2,7 +2,7 @@ package com.readrops.app.database.dao;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.paging.PageKeyedDataSource; import androidx.paging.DataSource;
import androidx.room.Dao; import androidx.room.Dao;
import androidx.room.Query; import androidx.room.Query;
import androidx.room.RawQuery; import androidx.room.RawQuery;
@ -21,7 +21,7 @@ import io.reactivex.Completable;
public abstract class ItemDao implements BaseDao<Item> { public abstract class ItemDao implements BaseDao<Item> {
@RawQuery(observedEntities = {Item.class, Folder.class, Feed.class}) @RawQuery(observedEntities = {Item.class, Folder.class, Feed.class})
public abstract PageKeyedDataSource.Factory<Integer, ItemWithFeed> selectAll(SupportSQLiteQuery query); public abstract DataSource.Factory<Integer, ItemWithFeed> selectAll(SupportSQLiteQuery query);
@Query("Select case When :guid In (Select guid From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end") @Query("Select case When :guid In (Select guid From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end")
public abstract boolean itemExists(String guid, int accountId); public abstract boolean itemExists(String guid, int accountId);

View File

@ -70,8 +70,8 @@ public class MainViewModel extends AndroidViewModel {
lastFetch = new LivePagedListBuilder<>(db.itemDao().selectAll(queryBuilder.getQuery()), lastFetch = new LivePagedListBuilder<>(db.itemDao().selectAll(queryBuilder.getQuery()),
new PagedList.Config.Builder() new PagedList.Config.Builder()
.setPageSize(40) .setPageSize(100)
.setPrefetchDistance(80) .setPrefetchDistance(150)
.setEnablePlaceholders(false) .setEnablePlaceholders(false)
.build()) .build())
.build(); .build();