Fix issue #737 and #738 - Jumps with timeline

This commit is contained in:
Thomas 2023-01-09 17:37:35 +01:00
parent 47e43193b8
commit 1fe0701342

View file

@ -161,10 +161,12 @@ 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));
if (position >= 0) {
timelineStatuses.remove(position);
statusAdapter.notifyItemRemoved(position);
}
}
}
} else if (refreshAll) {
refreshAllAdapters();
}
@ -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) {