diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 9ab1f58fa..fc60dbd95 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -414,6 +414,8 @@ public class StatusAdapter extends RecyclerView.Adapter boolean compactButtons = sharedpreferences.getBoolean(context.getString(R.string.SET_DISPLAY_COMPACT_ACTION_BUTTON), false); boolean originalDateForBoost = sharedpreferences.getBoolean(context.getString(R.string.SET_BOOST_ORIGINAL_DATE), true); boolean hideSingleMediaWithCard = sharedpreferences.getBoolean(context.getString(R.string.SET_HIDE_SINGLE_MEDIA_WITH_CARD), false); + boolean autofetch = sharedpreferences.getBoolean(context.getString(R.string.SET_AUTO_FETCH_MISSING_MESSAGES), false); + if (compactButtons) { ConstraintSet set = new ConstraintSet(); @@ -2095,44 +2097,66 @@ public class StatusAdapter extends RecyclerView.Adapter } if (status.isFetchMore && fetchMoreCallBack != null) { - DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context)); - 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()); + if (!autofetch) { + DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context)); + 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; + int position = holder.getBindingAdapterPosition(); + adapter.notifyItemChanged(position); + if (position < statusList.size() - 1) { + String fromId; + if (status.positionFetchMore == Status.PositionFetchMore.TOP) { + fromId = statusList.get(position + 1).id; + } else { + fromId = status.id; + } + fetchMoreCallBack.onClickMinId(fromId, status); + } + }); + drawerFetchMoreBinding.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, status); + adapter.notifyItemChanged(holder.getBindingAdapterPosition()); + }); } else { - holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE); + holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE); holder.binding.fetchMoreContainerTop.setVisibility(View.GONE); - holder.binding.fetchMoreContainerBottom.removeAllViews(); - holder.binding.fetchMoreContainerBottom.addView(drawerFetchMoreBinding.getRoot()); - } - drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> { status.isFetchMore = false; int position = holder.getBindingAdapterPosition(); adapter.notifyItemChanged(position); + String statusIdMin = null, statusIdMax; if (position < statusList.size() - 1) { - String fromId; if (status.positionFetchMore == Status.PositionFetchMore.TOP) { - fromId = statusList.get(position + 1).id; + statusIdMin = statusList.get(position + 1).id; } else { - fromId = status.id; + statusIdMin = status.id; } - fetchMoreCallBack.onClickMinId(fromId, status); } - }); - drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> { - //We hide the button - status.isFetchMore = false; - String fromId; if (status.positionFetchMore == Status.PositionFetchMore.TOP) { - fromId = statusList.get(holder.getBindingAdapterPosition()).id; + statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id; } else { - fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; + statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id; } - fetchMoreCallBack.onClickMaxId(fromId, status); - adapter.notifyItemChanged(holder.getBindingAdapterPosition()); - }); + fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status); + } } else { holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE); holder.binding.fetchMoreContainerTop.setVisibility(View.GONE); @@ -2771,6 +2795,8 @@ public class StatusAdapter extends RecyclerView.Adapter void onClickMinId(String min_id, Status statusToUpdate); void onClickMaxId(String max_id, Status statusToUpdate); + + void autoFetch(String min_id, String max_id, Status status); } public static class StatusViewHolder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java index 5b39387e7..12548023e 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -75,7 +75,7 @@ import es.dmoral.toasty.Toasty; public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack { - + private boolean scrollingUp; private static final int PRELOAD_AHEAD_ITEMS = 10; public UpdateCounters update; private FragmentPaginationBinding binding; @@ -506,9 +506,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. } else if (update != null && insertedStatus == 0 && direction == DIRECTION.REFRESH) { update.onUpdate(0, timelineType, slug); } - if (direction == DIRECTION.TOP && fetchingMissing) { + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + boolean autofetch = sharedpreferences.getBoolean(getString(R.string.SET_AUTO_FETCH_MISSING_MESSAGES), false); + if (direction == DIRECTION.TOP && fetchingMissing && !autofetch) { int position = getAbsolutePosition(fetched_statuses.statuses.get(fetched_statuses.statuses.size() - 1)); - if (position != -1) { binding.recyclerView.scrollToPosition(position + 1); } @@ -656,7 +657,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - + scrollingUp = dy > 0; if (requireActivity() instanceof BaseMainActivity) { if (dy < 0 && !((BaseMainActivity) requireActivity()).getFloatingVisibility()) ((BaseMainActivity) requireActivity()).manageFloatingButton(true); @@ -1228,6 +1229,17 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. route(DIRECTION.BOTTOM, true, statusToUpdate); } + @Override + public void autoFetch(String min_id, String max_id, Status statusToUpdate) { + if (scrollingUp) { + min_id_fetch_more = min_id; + route(DIRECTION.TOP, true, statusToUpdate); + } else { + max_id_fetch_more = max_id; + route(DIRECTION.BOTTOM, true, statusToUpdate); + } + } + public enum DIRECTION { TOP, BOTTOM, diff --git a/app/src/main/res/layouts/mastodon/values/strings.xml b/app/src/main/res/layouts/mastodon/values/strings.xml index 0d2c4cc40..78554f9eb 100644 --- a/app/src/main/res/layouts/mastodon/values/strings.xml +++ b/app/src/main/res/layouts/mastodon/values/strings.xml @@ -1,4 +1,5 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 10af09e32..4b1bbfe4d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1476,6 +1476,7 @@ SET_INNER_MARKER SET_NOTIF_SILENT SET_REMEMBER_POSITION + SET_AUTO_FETCH_MISSING_MESSAGES SET_EXPAND_CW SET_DISPLAY_ALL_NOTIFICATIONS_TYPE SET_EXCLUDED_NOTIFICATIONS_TYPE @@ -2242,4 +2243,5 @@ Automatically fetch home messages Home cache Fetch home messages + Automatically fetch missing messages \ No newline at end of file diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml index f99027d2a..11ff6b3fc 100644 --- a/app/src/main/res/xml/pref_timelines.xml +++ b/app/src/main/res/xml/pref_timelines.xml @@ -7,6 +7,12 @@ app:key="@string/SET_REMEMBER_POSITION" app:singleLineTitle="false" app:title="@string/remember_position" /> +