Fix notifications pagination

This commit is contained in:
M M Arif
2022-03-10 00:49:16 +05:00
parent 976a7acd3f
commit ef6aeffc04
2 changed files with 7 additions and 14 deletions

View File

@@ -36,7 +36,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter<RecyclerView.View
private List<NotificationThread> notificationThreads;
private final OnMoreClickedListener onMoreClickedListener;
private final OnNotificationClickedListener onNotificationClickedListener;
private Runnable loadMoreListener;
private boolean isLoading = false, isMoreDataAvailable = true;
private final TinyDB tinyDb;
@@ -62,9 +61,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter<RecyclerView.View
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading) {
isLoading = true;
loadMoreListener.run();
}
if(getItemViewType(position) == TYPE_LOAD) {
@@ -212,10 +210,6 @@ public class NotificationsAdapter extends RecyclerView.Adapter<RecyclerView.View
isLoading = false;
}
public void setLoadMoreListener(Runnable loadMoreListener) {
this.loadMoreListener = loadMoreListener;
}
public void updateList(List<NotificationThread> list) {
notificationThreads = list;
notifyDataChanged();

View File

@@ -4,8 +4,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -91,15 +89,16 @@ public class NotificationsFragment extends Fragment implements NotificationsAdap
viewBinding.notifications.setAdapter(notificationsAdapter);
viewBinding.notifications.addItemDecoration(dividerItemDecoration);
notificationsAdapter.setLoadMoreListener(() -> {
pageCurrentIndex++;
loadNotifications(true);
});
viewBinding.notifications.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if(!recyclerView.canScrollVertically(1) && dy != 0) {
pageCurrentIndex++;
loadNotifications(true);
}
if(currentFilterMode.equalsIgnoreCase("unread")) {
if(dy > 0 && viewBinding.markAllAsRead.isShown()) {
viewBinding.markAllAsRead.setVisibility(View.GONE);