diff options
5 files changed, 76 insertions, 29 deletions
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<RecyclerView.ViewHolder> 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<RecyclerView.ViewHolder> } 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<RecyclerView.ViewHolder> 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 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + </resources>
\ 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 @@ <string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string> <string name="SET_NOTIF_SILENT" translatable="false">SET_NOTIF_SILENT</string> <string name="SET_REMEMBER_POSITION" translatable="false">SET_REMEMBER_POSITION</string> + <string name="SET_AUTO_FETCH_MISSING_MESSAGES" translatable="false">SET_AUTO_FETCH_MISSING_MESSAGES</string> <string name="SET_EXPAND_CW" translatable="false">SET_EXPAND_CW</string> <string name="SET_DISPLAY_ALL_NOTIFICATIONS_TYPE" translatable="false">SET_DISPLAY_ALL_NOTIFICATIONS_TYPE</string> <string name="SET_EXCLUDED_NOTIFICATIONS_TYPE" translatable="false">SET_EXCLUDED_NOTIFICATIONS_TYPE</string> @@ -2242,4 +2243,5 @@ <string name="set_fetch_home">Automatically fetch home messages</string> <string name="home_cache">Home cache</string> <string name="fetch_home_messages">Fetch home messages</string> + <string name="auto_fetch_missing">Automatically fetch missing messages</string> </resources>
\ 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 @@ -10,6 +10,12 @@ <SwitchPreferenceCompat android:defaultValue="false" app:iconSpaceReserved="false" + app:key="@string/SET_AUTO_FETCH_MISSING_MESSAGES" + app:singleLineTitle="false" + app:title="@string/auto_fetch_missing" /> + <SwitchPreferenceCompat + android:defaultValue="false" + app:iconSpaceReserved="false" app:key="@string/SET_EXPAND_CW" app:singleLineTitle="false" app:title="@string/expand_cw" /> |