Fix an issue with infinite scroll

This commit is contained in:
Thomas 2022-05-20 19:05:14 +02:00
parent 381ece593c
commit 1ea6400c88
4 changed files with 19 additions and 4 deletions

View File

@ -179,6 +179,7 @@ public class FragmentMastodonAccount extends Fragment {
binding.swipeContainer.setRefreshing(false);
binding.swipeContainer.setOnRefreshListener(() -> {
binding.swipeContainer.setRefreshing(true);
flagLoading = false;
max_id = null;
router(true);
});
@ -197,7 +198,7 @@ public class FragmentMastodonAccount extends Fragment {
this.accounts = accounts.accounts;
accountAdapter = new AccountAdapter(this.accounts);
flagLoading = (accounts.accounts.size() < MastodonHelper.accountsPerCall(requireActivity()));
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(accountAdapter);
@ -245,6 +246,7 @@ public class FragmentMastodonAccount extends Fragment {
}
binding.loadingNextElements.setVisibility(View.GONE);
if (accounts != null && fetched_accounts != null && fetched_accounts.accounts != null) {
flagLoading = (fetched_accounts.accounts.size() < MastodonHelper.accountsPerCall(requireActivity()));
int startId = 0;
//There are some statuses present in the timeline
if (accounts.size() > 0) {
@ -256,6 +258,8 @@ public class FragmentMastodonAccount extends Fragment {
fetchRelationShip(fetched_accounts.accounts, position);
max_id = fetched_accounts.pagination.max_id;
accountAdapter.notifyItemRangeInserted(startId, fetched_accounts.accounts.size());
} else {
flagLoading = true;
}
}

View File

@ -126,6 +126,8 @@ public class FragmentMastodonConversation extends Fragment {
currentFragment.conversations.addAll(fetched_conversations.conversations);
max_id = fetched_conversations.pagination.max_id;
conversationAdapter.notifyItemRangeInserted(startId, fetched_conversations.conversations.size());
} else {
flagLoading = true;
}
});
}
@ -140,6 +142,7 @@ public class FragmentMastodonConversation extends Fragment {
if (this.conversations.size() > 0) {
binding.swipeContainer.setRefreshing(true);
max_id = null;
flagLoading = false;
timelinesVM.getConversations(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(FragmentMastodonConversation.this, this::initializeConversationCommonView);
}

View File

@ -189,7 +189,7 @@ public class FragmentMastodonNotification extends Fragment {
}
this.notifications = notifications.notifications;
notificationAdapter = new NotificationAdapter(this.notifications);
flagLoading = notifications.notifications.size() < MastodonHelper.notificationsPerCall(requireActivity());
LinearLayoutManager mLayoutManager = new LinearLayoutManager(requireActivity());
binding.recyclerView.setLayoutManager(mLayoutManager);
binding.recyclerView.setAdapter(notificationAdapter);
@ -219,6 +219,7 @@ public class FragmentMastodonNotification extends Fragment {
if (this.notifications.size() > 0) {
binding.swipeContainer.setRefreshing(true);
max_id = null;
flagLoading = false;
notificationsVM.getNotifications(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, null, MastodonHelper.statusesPerCall(requireActivity()), excludeType, null)
.observe(FragmentMastodonNotification.this, this::initializeNotificationView);
}
@ -239,6 +240,7 @@ public class FragmentMastodonNotification extends Fragment {
flagLoading = false;
binding.loadingNextElements.setVisibility(View.GONE);
if (currentFragment.notifications != null && fetched_notifications != null && fetched_notifications.notifications != null) {
flagLoading = fetched_notifications.notifications.size() < MastodonHelper.notificationsPerCall(requireActivity());
int startId = 0;
//There are some statuses present in the timeline
if (currentFragment.notifications.size() > 0) {
@ -247,6 +249,8 @@ public class FragmentMastodonNotification extends Fragment {
currentFragment.notifications.addAll(fetched_notifications.notifications);
max_id = fetched_notifications.pagination.max_id;
notificationAdapter.notifyItemRangeInserted(startId, fetched_notifications.notifications.size());
} else {
flagLoading = true;
}
}

View File

@ -254,6 +254,7 @@ public class FragmentMastodonTimeline extends Fragment {
binding.swipeContainer.setOnRefreshListener(() -> {
binding.swipeContainer.setRefreshing(true);
max_id = null;
flagLoading = false;
router(null);
});
@ -282,7 +283,7 @@ public class FragmentMastodonTimeline extends Fragment {
statuses.statuses = mediaStatuses;
}
}
flagLoading = (statuses.statuses.size() < MastodonHelper.statusesPerCall(requireActivity()));
binding.recyclerView.setVisibility(View.VISIBLE);
if (statusAdapter != null && this.statuses != null) {
int size = this.statuses.size();
@ -361,8 +362,9 @@ public class FragmentMastodonTimeline extends Fragment {
return;
}
binding.loadingNextElements.setVisibility(View.GONE);
if (statuses != null && fetched_statuses != null && fetched_statuses.statuses != null) {
if (statuses != null && fetched_statuses != null && fetched_statuses.statuses != null && fetched_statuses.statuses.size() > 0) {
flagLoading = (direction == DIRECTION.BOTTOM && fetched_statuses.statuses.size() < MastodonHelper.statusesPerCall(requireActivity()));
if (timelineType == Timeline.TimeLineEnum.ART) {
//We have to split media in different statuses
List<Status> mediaStatuses = new ArrayList<>();
@ -396,6 +398,8 @@ public class FragmentMastodonTimeline extends Fragment {
if (min_id == null || (fetched_statuses.pagination.min_id != null && fetched_statuses.pagination.min_id.compareTo(min_id) > 0)) {
min_id = fetched_statuses.pagination.min_id;
}
} else if (direction == DIRECTION.BOTTOM) {
flagLoading = true;
}
}