Fix issue #607 - Fetch more broken

This commit is contained in:
Thomas 2022-12-06 17:50:25 +01:00
parent 03d6c7f911
commit 7ccb1c96b2
3 changed files with 54 additions and 16 deletions

View file

@ -123,6 +123,7 @@ import app.fedilab.android.client.entities.app.BaseAccount;
import app.fedilab.android.client.entities.app.StatusCache; import app.fedilab.android.client.entities.app.StatusCache;
import app.fedilab.android.client.entities.app.StatusDraft; import app.fedilab.android.client.entities.app.StatusDraft;
import app.fedilab.android.client.entities.app.Timeline; 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.DrawerStatusArtBinding;
import app.fedilab.android.databinding.DrawerStatusBinding; import app.fedilab.android.databinding.DrawerStatusBinding;
import app.fedilab.android.databinding.DrawerStatusFilteredBinding; import app.fedilab.android.databinding.DrawerStatusFilteredBinding;
@ -175,6 +176,18 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
this.checkRemotely = checkRemotely; this.checkRemotely = checkRemotely;
} }
public static int getStatusPosition(List<Status> timelineStatuses, Status status) {
int position = 0;
if (timelineStatuses != null && status != null) {
for (Status _s : timelineStatuses) {
if (_s.id.compareTo(status.id) == 0) {
return position;
}
position++;
}
}
return -1;
}
private static boolean isVisible(Timeline.TimeLineEnum timelineType, Status status) { private static boolean isVisible(Timeline.TimeLineEnum timelineType, Status status) {
if (timelineType == Timeline.TimeLineEnum.HOME && !show_boosts && status.reblog != null) { if (timelineType == Timeline.TimeLineEnum.HOME && !show_boosts && status.reblog != null) {
@ -1853,21 +1866,34 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
if (status.isFetchMore && fetchMoreCallBack != null) { if (status.isFetchMore && fetchMoreCallBack != null) {
holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
holder.binding.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
holder.binding.fetchMoreContainerTop.removeAllViews();
holder.binding.fetchMoreContainerTop.addView(drawerFetchMoreBinding.getRoot());
} else {
holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
holder.binding.fetchMoreContainerBottom.removeAllViews();
holder.binding.fetchMoreContainerBottom.addView(drawerFetchMoreBinding.getRoot());
}
drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false; status.isFetchMore = false;
adapter.notifyItemChanged(holder.getBindingAdapterPosition()); int position = holder.getBindingAdapterPosition();
if (holder.getBindingAdapterPosition() < statusList.size() - 1) { int position2 = getStatusPosition(statusList, status);
adapter.notifyItemChanged(position);
if (position < statusList.size() - 1) {
String fromId; String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) { if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
fromId = statusList.get(holder.getBindingAdapterPosition() + 1).id; fromId = statusList.get(position + 1).id;
} else { } else {
fromId = status.id; fromId = status.id;
} }
fetchMoreCallBack.onClickMinId(fromId, status); fetchMoreCallBack.onClickMinId(fromId, status);
} }
}); });
holder.binding.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> {
//We hide the button //We hide the button
status.isFetchMore = false; status.isFetchMore = false;
String fromId; String fromId;
@ -1880,7 +1906,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
adapter.notifyItemChanged(holder.getBindingAdapterPosition()); adapter.notifyItemChanged(holder.getBindingAdapterPosition());
}); });
} else { } else {
holder.binding.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
} }
} }

View file

@ -29,6 +29,7 @@ import androidx.lifecycle.MutableLiveData;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -90,8 +91,14 @@ public class TimelinesVM extends AndroidViewModel {
super(application); super(application);
} }
private static void sortDesc(List<Status> statusList) {
Collections.sort(statusList, (obj1, obj2) -> obj2.id.compareToIgnoreCase(obj1.id));
}
private static void addFetchMore(List<Status> statusList, List<Status> timelineStatuses, TimelineParams timelineParams) throws DBException { private static void addFetchMore(List<Status> statusList, List<Status> timelineStatuses, TimelineParams timelineParams) throws DBException {
if (statusList != null && statusList.size() > 0 && timelineStatuses != null && timelineStatuses.size() > 0) { if (statusList != null && statusList.size() > 0 && timelineStatuses != null && timelineStatuses.size() > 0) {
sortDesc(statusList);
if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) { if (timelineParams.direction == FragmentMastodonTimeline.DIRECTION.REFRESH || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.SCROLL_TOP || timelineParams.direction == FragmentMastodonTimeline.DIRECTION.FETCH_NEW) {
//When refreshing/scrolling to TOP, if last statuses fetched has a greater id from newest in cache, there is potential hole //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) { if (statusList.get(statusList.size() - 1).id.compareToIgnoreCase(timelineStatuses.get(0).id) > 0) {

View file

@ -25,10 +25,6 @@
android:clipToPadding="false" android:clipToPadding="false"
android:clipChildren="false"> android:clipChildren="false">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="?colorOutline" />
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/main_container" android:id="@+id/main_container"
@ -39,6 +35,15 @@
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="vertical"> android:orientation="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/fetch_more_container_top"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="?colorOutline" />
<androidx.appcompat.widget.LinearLayoutCompat <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/status_booster_info" android:id="@+id/status_booster_info"
@ -726,11 +731,10 @@
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
<include <androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/layout_fetch_more" android:id="@+id/fetch_more_container_bottom"
layout="@layout/drawer_fetch_more" android:layout_width="match_parent"
android:visibility="gone" android:layout_height="wrap_content" />
tools:visibility="visible" />
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>