forked from mirrors/Fedilab
Auto fetch messages
This commit is contained in:
parent
3c13bf7199
commit
d61dbb0315
5 changed files with 76 additions and 29 deletions
|
@ -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 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 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 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) {
|
if (compactButtons) {
|
||||||
ConstraintSet set = new ConstraintSet();
|
ConstraintSet set = new ConstraintSet();
|
||||||
|
@ -2095,44 +2097,66 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status.isFetchMore && fetchMoreCallBack != null) {
|
if (status.isFetchMore && fetchMoreCallBack != null) {
|
||||||
DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
|
if (!autofetch) {
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
|
DrawerFetchMoreBinding drawerFetchMoreBinding = DrawerFetchMoreBinding.inflate(LayoutInflater.from(context));
|
||||||
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
|
if (status.positionFetchMore == Status.PositionFetchMore.BOTTOM) {
|
||||||
holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
|
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
|
||||||
holder.binding.fetchMoreContainerTop.removeAllViews();
|
holder.binding.fetchMoreContainerTop.setVisibility(View.VISIBLE);
|
||||||
holder.binding.fetchMoreContainerTop.addView(drawerFetchMoreBinding.getRoot());
|
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 {
|
} else {
|
||||||
holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
|
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
|
||||||
holder.binding.fetchMoreContainerTop.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;
|
status.isFetchMore = false;
|
||||||
int position = holder.getBindingAdapterPosition();
|
int position = holder.getBindingAdapterPosition();
|
||||||
adapter.notifyItemChanged(position);
|
adapter.notifyItemChanged(position);
|
||||||
|
String statusIdMin = null, statusIdMax;
|
||||||
if (position < statusList.size() - 1) {
|
if (position < statusList.size() - 1) {
|
||||||
String fromId;
|
|
||||||
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
||||||
fromId = statusList.get(position + 1).id;
|
statusIdMin = statusList.get(position + 1).id;
|
||||||
} else {
|
} 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) {
|
if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition()).id;
|
statusIdMax = statusList.get(holder.getBindingAdapterPosition()).id;
|
||||||
} else {
|
} else {
|
||||||
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
|
||||||
}
|
}
|
||||||
fetchMoreCallBack.onClickMaxId(fromId, status);
|
fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status);
|
||||||
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
|
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
|
||||||
holder.binding.fetchMoreContainerTop.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 onClickMinId(String min_id, Status statusToUpdate);
|
||||||
|
|
||||||
void onClickMaxId(String max_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 {
|
public static class StatusViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
|
@ -75,7 +75,7 @@ import es.dmoral.toasty.Toasty;
|
||||||
|
|
||||||
public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
|
public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
|
||||||
|
|
||||||
|
private boolean scrollingUp;
|
||||||
private static final int PRELOAD_AHEAD_ITEMS = 10;
|
private static final int PRELOAD_AHEAD_ITEMS = 10;
|
||||||
public UpdateCounters update;
|
public UpdateCounters update;
|
||||||
private FragmentPaginationBinding binding;
|
private FragmentPaginationBinding binding;
|
||||||
|
@ -506,9 +506,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
} else if (update != null && insertedStatus == 0 && direction == DIRECTION.REFRESH) {
|
} else if (update != null && insertedStatus == 0 && direction == DIRECTION.REFRESH) {
|
||||||
update.onUpdate(0, timelineType, slug);
|
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));
|
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);
|
||||||
}
|
}
|
||||||
|
@ -656,7 +657,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;
|
||||||
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);
|
||||||
|
@ -1228,6 +1229,17 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
route(DIRECTION.BOTTOM, true, statusToUpdate);
|
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 {
|
public enum DIRECTION {
|
||||||
TOP,
|
TOP,
|
||||||
BOTTOM,
|
BOTTOM,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
|
@ -1476,6 +1476,7 @@
|
||||||
<string name="SET_INNER_MARKER" translatable="false">SET_INNER_MARKER</string>
|
<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_NOTIF_SILENT" translatable="false">SET_NOTIF_SILENT</string>
|
||||||
<string name="SET_REMEMBER_POSITION" translatable="false">SET_REMEMBER_POSITION</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_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_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>
|
<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="set_fetch_home">Automatically fetch home messages</string>
|
||||||
<string name="home_cache">Home cache</string>
|
<string name="home_cache">Home cache</string>
|
||||||
<string name="fetch_home_messages">Fetch home messages</string>
|
<string name="fetch_home_messages">Fetch home messages</string>
|
||||||
|
<string name="auto_fetch_missing">Automatically fetch missing messages</string>
|
||||||
</resources>
|
</resources>
|
|
@ -7,6 +7,12 @@
|
||||||
app:key="@string/SET_REMEMBER_POSITION"
|
app:key="@string/SET_REMEMBER_POSITION"
|
||||||
app:singleLineTitle="false"
|
app:singleLineTitle="false"
|
||||||
app:title="@string/remember_position" />
|
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
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
|
|
Loading…
Reference in a new issue