mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Added auto fetch more posts in feed at init. But disabled due to some weird list merging.
This commit is contained in:
parent
c9f46a1986
commit
c5d55f3661
@ -22,6 +22,7 @@ import androidx.work.WorkManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -77,8 +78,7 @@ public class PostsRecyclerView extends RecyclerView {
|
||||
if (settingsHelper.getBoolean(Constants.TOGGLE_KEYWORD_FILTER)) {
|
||||
final ArrayList<String> items = new ArrayList<>(settingsHelper.getStringSet(Constants.KEYWORD_FILTERS));
|
||||
modelsCopy.addAll(new KeywordsFilterUtils(items).filter(result));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
modelsCopy.addAll(result);
|
||||
}
|
||||
mediaViewModel.getList().postValue(modelsCopy);
|
||||
@ -194,7 +194,9 @@ public class PostsRecyclerView extends RecyclerView {
|
||||
private void initSelf() {
|
||||
mediaViewModel = new ViewModelProvider(viewModelStoreOwner).get(MediaViewModel.class);
|
||||
mediaViewModel.getList().observe(lifeCycleOwner, list -> {
|
||||
if (list.size() > 0) feedAdapter.submitList(list, () -> {
|
||||
if (list.size() <= 0) return;
|
||||
feedAdapter.submitList(list, () -> {
|
||||
// postDelayed(this::fetchMoreIfPossible, 1000);
|
||||
if (!shouldScrollToTop) return;
|
||||
smoothScrollToPosition(0);
|
||||
shouldScrollToTop = false;
|
||||
@ -217,6 +219,20 @@ public class PostsRecyclerView extends RecyclerView {
|
||||
dispatchFetchStatus();
|
||||
}
|
||||
|
||||
private void fetchMoreIfPossible() {
|
||||
if (!postFetcher.hasMore()) return;
|
||||
if (feedAdapter.getItemCount() == 0) return;
|
||||
final LayoutManager layoutManager = getLayoutManager();
|
||||
if (!(layoutManager instanceof StaggeredGridLayoutManager)) return;
|
||||
final int[] itemPositions = ((StaggeredGridLayoutManager) layoutManager).findLastCompletelyVisibleItemPositions(null);
|
||||
final boolean allNoPosition = Arrays.stream(itemPositions).allMatch(position -> position == RecyclerView.NO_POSITION);
|
||||
if (allNoPosition) return;
|
||||
final boolean match = Arrays.stream(itemPositions).anyMatch(position -> position == feedAdapter.getItemCount() - 1);
|
||||
if (!match) return;
|
||||
postFetcher.fetch();
|
||||
dispatchFetchStatus();
|
||||
}
|
||||
|
||||
private void initDownloadWorkerListener() {
|
||||
WorkManager.getInstance(getContext())
|
||||
.getWorkInfosByTagLiveData("download")
|
||||
|
Loading…
Reference in New Issue
Block a user