Auto fetch messages

This commit is contained in:
Thomas 2023-02-01 18:52:55 +01:00
parent d61dbb0315
commit 4ae8011eff
2 changed files with 43 additions and 24 deletions

View file

@ -2141,7 +2141,6 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.fetchMoreContainerTop.setVisibility(View.GONE); holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
status.isFetchMore = false; status.isFetchMore = false;
int position = holder.getBindingAdapterPosition(); int position = holder.getBindingAdapterPosition();
adapter.notifyItemChanged(position);
String statusIdMin = null, statusIdMax; String statusIdMin = null, statusIdMax;
if (position < statusList.size() - 1) { if (position < statusList.size() - 1) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP) { if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
@ -2614,32 +2613,53 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.bindingFilteredHide.dividerCard.setVisibility(View.GONE); holder.bindingFilteredHide.dividerCard.setVisibility(View.GONE);
} }
if (status.isFetchMore && fetchMoreCallBack != null) { if (status.isFetchMore && fetchMoreCallBack != null) {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); boolean autofetch = sharedpreferences.getBoolean(context.getString(R.string.SET_AUTO_FETCH_MISSING_MESSAGES), false);
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { if (!autofetch) {
status.isFetchMore = false; holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
notifyItemChanged(holder.getBindingAdapterPosition()); holder.bindingFilteredHide.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> {
if (holder.getBindingAdapterPosition() < statusList.size() - 1) { status.isFetchMore = false;
notifyItemChanged(holder.getBindingAdapterPosition());
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, status);
}
});
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> {
//We hide the button
status.isFetchMore = false;
notifyItemChanged(holder.getBindingAdapterPosition());
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(holder.getBindingAdapterPosition()).id;
} else { } else {
fromId = status.id; fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
} }
fetchMoreCallBack.onClickMinId(fromId, status); fetchMoreCallBack.onClickMaxId(fromId, status);
}
}); });
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { } else {
//We hide the button
status.isFetchMore = false; status.isFetchMore = false;
String fromId; String minId = null, maxId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP) { if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id; if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
} else { minId = statusList.get(holder.getBindingAdapterPosition() + 1).id;
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; } else {
minId = status.id;
}
} }
fetchMoreCallBack.onClickMaxId(fromId, status); if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
notifyItemChanged(holder.getBindingAdapterPosition()); maxId = statusList.get(holder.getBindingAdapterPosition()).id;
}); } else {
maxId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
}
fetchMoreCallBack.autoFetch(minId, maxId, status);
}
} else { } else {
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE); holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.GONE);
} }

View file

@ -507,8 +507,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
update.onUpdate(0, timelineType, slug); update.onUpdate(0, timelineType, slug);
} }
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
boolean autofetch = sharedpreferences.getBoolean(getString(R.string.SET_AUTO_FETCH_MISSING_MESSAGES), false); if (direction == DIRECTION.TOP && fetchingMissing) {
if (direction == DIRECTION.TOP && fetchingMissing && !autofetch) {
int position = getAbsolutePosition(fetched_statuses.statuses.get(fetched_statuses.statuses.size() - 1)); int position = getAbsolutePosition(fetched_statuses.statuses.get(fetched_statuses.statuses.size() - 1));
if (position != -1) { if (position != -1) {
binding.recyclerView.scrollToPosition(position + 1); binding.recyclerView.scrollToPosition(position + 1);
@ -657,7 +656,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
scrollingUp = dy > 0; scrollingUp = dy < 0;
if (requireActivity() instanceof BaseMainActivity) { if (requireActivity() instanceof BaseMainActivity) {
if (dy < 0 && !((BaseMainActivity) requireActivity()).getFloatingVisibility()) if (dy < 0 && !((BaseMainActivity) requireActivity()).getFloatingVisibility())
((BaseMainActivity) requireActivity()).manageFloatingButton(true); ((BaseMainActivity) requireActivity()).manageFloatingButton(true);