diff options
author | Thomas <tschneider.ac@gmail.com> | 2023-01-09 17:37:35 +0100 |
---|---|---|
committer | Thomas <tschneider.ac@gmail.com> | 2023-01-09 17:37:35 +0100 |
commit | 1fe070134249718a9eba24f16e6ef44b6ef50590 (patch) | |
tree | 9875033f2dcf903c93bf47bacf35d7e8cf021187 /app/src | |
parent | 47e43193b834feabfb02c030960e88aca3b02458 (diff) |
Fix issue #737 and #738 - Jumps with timeline
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index b3e2e6b42..00b4cb094 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -161,8 +161,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (toRemove.size() > 0) { for (int i = 0; i < toRemove.size(); i++) { int position = getPosition(toRemove.get(i)); - timelineStatuses.remove(position); - statusAdapter.notifyItemRemoved(position); + if (position >= 0) { + timelineStatuses.remove(position); + statusAdapter.notifyItemRemoved(position); + } } } } else if (refreshAll) { @@ -266,6 +268,29 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. return found ? position : -1; } + + /** + * Return the position of the status in the ArrayList + * + * @param status - Status to fetch + * @return position or -1 if not found + */ + private int getAbsolutePosition(Status status) { + int position = 0; + boolean found = false; + if (status.id == null) { + return -1; + } + for (Status _status : timelineStatuses) { + if (_status.id != null && _status.id.compareTo(status.id) == 0) { + found = true; + break; + } + position++; + } + return found ? position : -1; + } + /** * Returned list of checked status id for reports * @@ -412,7 +437,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.swipeContainer.setRefreshing(false); binding.loadingNextElements.setVisibility(View.GONE); flagLoading = false; - int currentPosition = mLayoutManager.findFirstVisibleItemPosition(); if (timelineStatuses != null && fetched_statuses != null && fetched_statuses.statuses != null && fetched_statuses.statuses.size() > 0) { try { if (statusToUpdate != null) { @@ -475,9 +499,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. update.onUpdate(0, timelineType, slug); } if (direction == DIRECTION.TOP && fetchingMissing) { - int newPosition = currentPosition + fetched_statuses.statuses.size() + 1; - if (newPosition < timelineStatuses.size()) { - binding.recyclerView.scrollToPosition(newPosition); + int position = getAbsolutePosition(fetched_statuses.statuses.get(fetched_statuses.statuses.size() - 1)); + + if (position != -1) { + binding.recyclerView.scrollToPosition(position + 1); } } if (!fetchingMissing) { |