diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java index 9484f599b..9dc37661a 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Status.java @@ -98,6 +98,7 @@ public class Status implements Serializable, Cloneable { public boolean isExpended = false; public boolean isTruncated = true; public boolean isFetchMore = false; + public PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM; public boolean isMediaDisplayed = false; public boolean isMediaObfuscated = true; public boolean isChecked = false; @@ -108,6 +109,11 @@ public class Status implements Serializable, Cloneable { public transient int cursorPosition = 0; public transient boolean submitted = false; + public enum PositionFetchMore { + TOP, + BOTTOM + } + @Override public boolean equals(@Nullable Object obj) { boolean same = false; diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java index bd02bb1bd..eec47c3ef 100644 --- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java @@ -113,7 +113,6 @@ import app.fedilab.android.client.entities.app.Account; import app.fedilab.android.client.entities.app.StatusCache; import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.client.entities.app.Timeline; -import app.fedilab.android.databinding.DrawerFetchMoreBinding; import app.fedilab.android.databinding.DrawerStatusArtBinding; import app.fedilab.android.databinding.DrawerStatusBinding; import app.fedilab.android.databinding.DrawerStatusHiddenBinding; @@ -1862,7 +1861,6 @@ public class StatusAdapter extends RecyclerView.Adapter } }); //For reports - if (holder.bindingReport != null) { holder.bindingReport.checkbox.setChecked(status.isChecked); holder.bindingReport.checkbox.setOnClickListener(v -> status.isChecked = !status.isChecked); @@ -1873,25 +1871,40 @@ public class StatusAdapter extends RecyclerView.Adapter holder.binding.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { status.isFetchMore = false; adapter.notifyItemChanged(holder.getBindingAdapterPosition()); - fetchMoreCallBack.onClickMinId(status.id); - if (!remote) { - new Thread(() -> { - StatusCache statusCache = new StatusCache(); - statusCache.instance = BaseMainActivity.currentInstance; - statusCache.user_id = BaseMainActivity.currentUserID; - statusCache.status = status; - statusCache.status_id = status.id; - try { - new StatusCache(context).updateIfExists(statusCache); - } catch (DBException e) { - e.printStackTrace(); - } - }).start(); + if (holder.getBindingAdapterPosition() < statusList.size() - 1) { + String fromId; + if (status.positionFetchMore == Status.PositionFetchMore.TOP) { + fromId = statusList.get(holder.getBindingAdapterPosition() + 1).id; + } else { + fromId = status.id; + } + fetchMoreCallBack.onClickMinId(fromId); + if (!remote) { + new Thread(() -> { + StatusCache statusCache = new StatusCache(); + statusCache.instance = BaseMainActivity.currentInstance; + statusCache.user_id = BaseMainActivity.currentUserID; + statusCache.status = status; + statusCache.status_id = status.id; + try { + new StatusCache(context).updateIfExists(statusCache); + } catch (DBException e) { + e.printStackTrace(); + } + }).start(); + } } }); holder.binding.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { //We hide the button status.isFetchMore = false; + String fromId; + if (status.positionFetchMore == Status.PositionFetchMore.TOP) { + fromId = statusList.get(holder.getBindingAdapterPosition()).id; + } else { + fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; + } + fetchMoreCallBack.onClickMaxId(fromId); adapter.notifyItemChanged(holder.getBindingAdapterPosition()); if (!remote) { new Thread(() -> { @@ -1907,7 +1920,6 @@ public class StatusAdapter extends RecyclerView.Adapter } }).start(); } - fetchMoreCallBack.onClickMaxId(status.id); }); } else { holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); @@ -2070,7 +2082,6 @@ public class StatusAdapter extends RecyclerView.Adapter DrawerStatusBinding binding; DrawerStatusHiddenBinding bindingHidden; DrawerStatusReportBinding bindingReport; - DrawerFetchMoreBinding bindingFetchMore; DrawerStatusNotificationBinding bindingNotification; DrawerStatusArtBinding bindingArt; diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java index 98f96a323..aa16ad7f4 100644 --- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java +++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java @@ -347,14 +347,17 @@ public class TimelinesVM extends AndroidViewModel { //When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole if (statusList.get(statusList.size() - 1).id.compareToIgnoreCase(timelineStatuses.get(0).id) > 0) { statusList.get(statusList.size() - 1).isFetchMore = true; + statusList.get(statusList.size() - 1).positionFetchMore = Status.PositionFetchMore.TOP; } } else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.TOP && timelineParams.fetchingMissing) { if (!timelineStatuses.contains(statusList.get(0))) { statusList.get(0).isFetchMore = true; + statusList.get(0).positionFetchMore = Status.PositionFetchMore.BOTTOM; } } else if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.BOTTOM && timelineParams.fetchingMissing) { if (!timelineStatuses.contains(statusList.get(statusList.size() - 1))) { statusList.get(statusList.size() - 1).isFetchMore = true; + statusList.get(statusList.size() - 1).positionFetchMore = Status.PositionFetchMore.TOP; } } }