Browse Source

Keep follow requests at top in notification viewer

renovate/org.robolectric-robolectric-4.x
Ammar Githam 4 years ago
parent
commit
e89cf7af46
  1. 36
      app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java

36
app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java

@ -4,13 +4,19 @@ import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import awais.instagrabber.adapters.viewholder.NotificationViewHolder;
import awais.instagrabber.databinding.ItemNotificationBinding;
import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.NotificationModel;
import awais.instagrabber.models.enums.NotificationType;
public final class NotificationsAdapter extends ListAdapter<NotificationModel, NotificationViewHolder> {
private final OnNotificationClickListener notificationClickListener;
@ -49,6 +55,36 @@ public final class NotificationsAdapter extends ListAdapter<NotificationModel, N
holder.bind(notificationModel, notificationClickListener);
}
@Override
public void submitList(@Nullable final List<NotificationModel> list, @Nullable final Runnable commitCallback) {
if (list == null) {
super.submitList(null, commitCallback);
return;
}
super.submitList(sort(list), commitCallback);
}
@Override
public void submitList(@Nullable final List<NotificationModel> list) {
if (list == null) {
super.submitList(null);
return;
}
super.submitList(sort(list));
}
private List<NotificationModel> sort(final List<NotificationModel> list) {
final List<NotificationModel> listCopy = new ArrayList<>(list);
Collections.sort(listCopy, (o1, o2) -> {
if (o1.getType() == o2.getType()) return 0;
// keep requests at top
if (o1.getType() == NotificationType.REQUEST) return -1;
if (o2.getType() == NotificationType.REQUEST) return 1;
return 0;
});
return listCopy;
}
public interface OnNotificationClickListener {
void onNotificationClick(final NotificationModel model);
}
Loading…
Cancel
Save