Commit d61dbb03 authored by Thomas's avatar Thomas
Browse files

Auto fetch messages

parent 3c13bf71
Loading
Loading
Loading
Loading
+51 −25
Original line number Diff line number Diff line
@@ -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,6 +2097,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
        }

        if (status.isFetchMore && fetchMoreCallBack != null) {
            if (!autofetch) {
                DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
                if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
                    holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
@@ -2133,6 +2136,27 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
                    fetchMoreCallBack.onClickMaxId(fromId, status);
                    adapter.notifyItemChanged(holder.getBindingAdapterPosition());
                });
            } else {
                holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
                holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
                status.isFetchMore = false;
                int position = holder.getBindingAdapterPosition();
                adapter.notifyItemChanged(position);
                String statusIdMin = null, statusIdMax;
                if (position < statusList.size() - 1) {
                    if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                        statusIdMin = statusList.get(position + 1).id;
                    } else {
                        statusIdMin = status.id;
                    }
                }
                if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
                } else {
                    statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
                }
                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 {
+16 −4
Original line number Diff line number Diff line
@@ -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,
+1 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<resources>


</resources>
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
@@ -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
+6 −0
Original line number Diff line number Diff line
@@ -7,6 +7,12 @@
        app:key="@string/SET_REMEMBER_POSITION"
        app:singleLineTitle="false"
        app:title="@string/remember_position" />
    <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"