Add fetching message

This commit is contained in:
Thomas 2023-03-11 11:12:21 +01:00
parent bc27445103
commit 1b88633887
5 changed files with 124 additions and 40 deletions

View file

@ -114,6 +114,8 @@ public class Status implements Serializable, Cloneable {
public transient boolean isFetchMore = false; public transient boolean isFetchMore = false;
public transient boolean isFetching = false;
public transient PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM; public transient PositionFetchMore positionFetchMore = PositionFetchMore.BOTTOM;
public Attachment art_attachment; public Attachment art_attachment;

View file

@ -120,6 +120,7 @@ import app.fedilab.android.BaseMainActivity;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity; import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.databinding.DrawerFetchMoreBinding; import app.fedilab.android.databinding.DrawerFetchMoreBinding;
import app.fedilab.android.databinding.DrawerMessageFetchingBinding;
import app.fedilab.android.databinding.DrawerStatusArtBinding; import app.fedilab.android.databinding.DrawerStatusArtBinding;
import app.fedilab.android.databinding.DrawerStatusBinding; import app.fedilab.android.databinding.DrawerStatusBinding;
import app.fedilab.android.databinding.DrawerStatusFilteredBinding; import app.fedilab.android.databinding.DrawerStatusFilteredBinding;
@ -1621,12 +1622,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(mediaItem); .createMediaSource(mediaItem);
} }
try {
ExoPlayer player = new ExoPlayer.Builder(context).build(); ExoPlayer player = new ExoPlayer.Builder(context).build();
player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setRepeatMode(Player.REPEAT_MODE_ONE);
layoutMediaBinding.mediaVideo.setPlayer(player); layoutMediaBinding.mediaVideo.setPlayer(player);
player.setMediaSource(videoSource); player.setMediaSource(videoSource);
player.prepare(); player.prepare();
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
} catch (Exception e) {
e.printStackTrace();
}
int finalMediaPosition = mediaPosition; int finalMediaPosition = mediaPosition;
layoutMediaBinding.mediaVideo.setOnClickListener(v -> { layoutMediaBinding.mediaVideo.setOnClickListener(v -> {
@ -1686,12 +1691,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory) videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
.createMediaSource(mediaItem); .createMediaSource(mediaItem);
} }
try {
ExoPlayer player = new ExoPlayer.Builder(context).build(); ExoPlayer player = new ExoPlayer.Builder(context).build();
player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setRepeatMode(Player.REPEAT_MODE_ONE);
layoutMediaBinding.mediaVideo.setPlayer(player); layoutMediaBinding.mediaVideo.setPlayer(player);
player.setMediaSource(videoSource); player.setMediaSource(videoSource);
player.prepare(); player.prepare();
player.setPlayWhenReady(true); player.setPlayWhenReady(true);
} catch (Exception e) {
e.printStackTrace();
}
int finalMediaPosition = mediaPosition; int finalMediaPosition = mediaPosition;
layoutMediaBinding.mediaVideo.setOnClickListener(v -> { layoutMediaBinding.mediaVideo.setOnClickListener(v -> {
final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5); final int timeout = sharedpreferences.getInt(context.getString(R.string.SET_NSFW_TIMEOUT), 5);
@ -2447,6 +2456,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> { drawerFetchMoreBinding.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
int position = holder.getBindingAdapterPosition(); int position = holder.getBindingAdapterPosition();
adapter.notifyItemChanged(position); adapter.notifyItemChanged(position);
if (position < statusList.size() - 1) { if (position < statusList.size() - 1) {
@ -2456,25 +2466,27 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
fromId = status.id; fromId = status.id;
} }
fetchMoreCallBack.onClickMinId(fromId); fetchMoreCallBack.onClickMinId(fromId, status);
} }
}); });
drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> { drawerFetchMoreBinding.fetchMoreMax.setOnClickListener(v -> {
//We hide the button //We hide the button
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
String fromId; String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) { if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id; fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else { } else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
} }
fetchMoreCallBack.onClickMaxId(fromId); fetchMoreCallBack.onClickMaxId(fromId, status);
adapter.notifyItemChanged(holder.getBindingAdapterPosition()); 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);
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
int position = holder.getBindingAdapterPosition(); int position = holder.getBindingAdapterPosition();
String statusIdMin = null, statusIdMax; String statusIdMin = null, statusIdMax;
if (position < statusList.size() - 1) { if (position < statusList.size() - 1) {
@ -2490,6 +2502,23 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id; statusIdMax = statusList.get(holder.getBindingAdapterPosition() - 1).id;
} }
fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status); fetchMoreCallBack.autoFetch(statusIdMin, statusIdMax, status);
adapter.notifyItemChanged(holder.getBindingAdapterPosition());
}
} else if (status.isFetching) {
DrawerMessageFetchingBinding drawerMessageFetchingBinding = DrawerMessageFetchingBinding.inflate(LayoutInflater.from(context));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
drawerMessageFetchingBinding.fetchingContainer.setLayoutParams(lp);
drawerMessageFetchingBinding.fetchingProgress.getIndeterminateDrawable().setColorFilter(ThemeHelper.getAttColor(context, R.attr.colorPrimary), PorterDuff.Mode.SRC_IN);
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(drawerMessageFetchingBinding.getRoot());
} else {
holder.binding.fetchMoreContainerBottom.setVisibility(View.VISIBLE);
holder.binding.fetchMoreContainerTop.setVisibility(View.GONE);
holder.binding.fetchMoreContainerBottom.removeAllViews();
holder.binding.fetchMoreContainerBottom.addView(drawerMessageFetchingBinding.getRoot());
} }
} else { } else {
holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE); holder.binding.fetchMoreContainerBottom.setVisibility(View.GONE);
@ -2996,6 +3025,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); holder.bindingFilteredHide.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { holder.bindingFilteredHide.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
notifyItemChanged(holder.getBindingAdapterPosition()); notifyItemChanged(holder.getBindingAdapterPosition());
if (holder.getBindingAdapterPosition() < statusList.size() - 1) { if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
String fromId; String fromId;
@ -3004,12 +3034,13 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
fromId = status.id; fromId = status.id;
} }
fetchMoreCallBack.onClickMinId(fromId); fetchMoreCallBack.onClickMinId(fromId, status);
} }
}); });
holder.bindingFilteredHide.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { holder.bindingFilteredHide.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> {
//We hide the button //We hide the button
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
notifyItemChanged(holder.getBindingAdapterPosition()); notifyItemChanged(holder.getBindingAdapterPosition());
String fromId; String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) { if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
@ -3017,11 +3048,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
} }
fetchMoreCallBack.onClickMaxId(fromId); fetchMoreCallBack.onClickMaxId(fromId, status);
}); });
} else { } else {
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
String minId = null, maxId; String minId = null, maxId;
if (holder.getBindingAdapterPosition() < statusList.size() - 1) { if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
if (status.positionFetchMore == Status.PositionFetchMore.TOP) { if (status.positionFetchMore == Status.PositionFetchMore.TOP) {
@ -3053,6 +3085,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE); holder.bindingFiltered.layoutFetchMore.fetchMoreContainer.setVisibility(View.VISIBLE);
holder.bindingFiltered.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> { holder.bindingFiltered.layoutFetchMore.fetchMoreMin.setOnClickListener(v -> {
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
notifyItemChanged(holder.getBindingAdapterPosition()); notifyItemChanged(holder.getBindingAdapterPosition());
if (holder.getBindingAdapterPosition() < statusList.size() - 1) { if (holder.getBindingAdapterPosition() < statusList.size() - 1) {
String fromId; String fromId;
@ -3061,19 +3094,20 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} else { } else {
fromId = status.id; fromId = status.id;
} }
fetchMoreCallBack.onClickMinId(fromId); fetchMoreCallBack.onClickMinId(fromId, status);
} }
}); });
holder.bindingFiltered.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> { holder.bindingFiltered.layoutFetchMore.fetchMoreMax.setOnClickListener(v -> {
//We hide the button //We hide the button
status.isFetchMore = false; status.isFetchMore = false;
status.isFetching = true;
String fromId; String fromId;
if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) { if (status.positionFetchMore == Status.PositionFetchMore.TOP || holder.getBindingAdapterPosition() == 0) {
fromId = statusList.get(holder.getBindingAdapterPosition()).id; fromId = statusList.get(holder.getBindingAdapterPosition()).id;
} else { } else {
fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id; fromId = statusList.get(holder.getBindingAdapterPosition() - 1).id;
} }
fetchMoreCallBack.onClickMaxId(fromId); fetchMoreCallBack.onClickMaxId(fromId, status);
notifyItemChanged(holder.getBindingAdapterPosition()); notifyItemChanged(holder.getBindingAdapterPosition());
}); });
} else { } else {
@ -3194,9 +3228,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public interface FetchMoreCallBack { public interface FetchMoreCallBack {
void onClickMinId(String min_id); void onClickMinId(String min_id, Status fetchStatus);
void onClickMaxId(String max_id); void onClickMaxId(String max_id, Status fetchStatus);
void autoFetch(String min_id, String max_id, Status status); void autoFetch(String min_id, String max_id, Status status);
} }

View file

@ -434,10 +434,17 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
* *
* @param fetched_statuses Statuses * @param fetched_statuses Statuses
*/ */
private synchronized void dealWithPagination(Statuses fetched_statuses, DIRECTION direction, boolean fetchingMissing, boolean canScroll) { private synchronized void dealWithPagination(Statuses fetched_statuses, DIRECTION direction, boolean fetchingMissing, boolean canScroll, Status fetchStatus) {
if (binding == null || !isAdded() || getActivity() == null) { if (binding == null || !isAdded() || getActivity() == null) {
return; return;
} }
if (fetchStatus != null) {
int position = getPosition(fetchStatus);
if (position >= 0 && position < timelineStatuses.size()) {
timelineStatuses.get(position).isFetching = false;
statusAdapter.notifyItemChanged(position);
}
}
binding.swipeContainer.setRefreshing(false); binding.swipeContainer.setRefreshing(false);
binding.loadingNextElements.setVisibility(View.GONE); binding.loadingNextElements.setVisibility(View.GONE);
flagLoading = false; flagLoading = false;
@ -509,7 +516,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
if (direction == DIRECTION.SCROLL_TOP) { if (direction == DIRECTION.SCROLL_TOP) {
new Handler().postDelayed(() -> binding.recyclerView.scrollToPosition(0), 200); new Handler().postDelayed(() -> binding.recyclerView.scrollToPosition(0), 200);
} }
}
/**
* Update view and pagination when scrolling down
*
* @param fetched_statuses Statuses
*/
private synchronized void dealWithPagination(Statuses fetched_statuses, DIRECTION direction, boolean fetchingMissing, boolean canScroll) {
dealWithPagination(fetched_statuses, direction, fetchingMissing, canScroll, null);
} }
/** /**
@ -902,13 +917,21 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
} }
/** /**
* Router for timelines * Router for timelines
* *
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll * @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
*/ */
private void route(DIRECTION direction, boolean fetchingMissing) { private void route(DIRECTION direction, boolean fetchingMissing) {
route(direction, fetchingMissing, null);
}
/**
* Router for timelines
*
* @param direction - DIRECTION null if first call, then is set to TOP or BOTTOM depending of scroll
*/
private void route(DIRECTION direction, boolean fetchingMissing, Status fetchStatus) {
if (binding == null || !isAdded() || getActivity() == null) { if (binding == null || !isAdded() || getActivity() == null) {
return; return;
} }
@ -933,14 +956,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
}); });
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id) timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
flagLoading = false; flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { } else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null) timelinesVM.getNitter(pinnedTimeline.remoteInstance.host, null)
.observe(getViewLifecycleOwner(), statusesRefresh -> { .observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) { if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true, true); dealWithPagination(statusesRefresh, direction, true, true, fetchStatus);
} else { } else {
initializeStatusesCommonView(statusesRefresh); initializeStatusesCommonView(statusesRefresh);
} }
@ -956,14 +979,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getMisskey(remoteInstance, max_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getMisskey(remoteInstance, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
flagLoading = false; flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { } else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getMisskey(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> { .observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) { if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true, true); dealWithPagination(statusesRefresh, direction, true, true, fetchStatus);
} else { } else {
initializeStatusesCommonView(statusesRefresh); initializeStatusesCommonView(statusesRefresh);
} }
@ -976,14 +999,14 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPeertube(remoteInstance, String.valueOf(timelineStatuses.size()), MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPeertube(remoteInstance, String.valueOf(timelineStatuses.size()), MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
flagLoading = false; flagLoading = false;
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) { } else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP) {
timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPeertube(remoteInstance, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesRefresh -> { .observe(getViewLifecycleOwner(), statusesRefresh -> {
if (statusAdapter != null) { if (statusAdapter != null) {
dealWithPagination(statusesRefresh, direction, true, true); dealWithPagination(statusesRefresh, direction, true, true, fetchStatus);
} else { } else {
initializeStatusesCommonView(statusesRefresh); initializeStatusesCommonView(statusesRefresh);
} }
@ -1065,7 +1088,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(tempInstance, tempToken, accountId, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -1090,7 +1113,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
Statuses statuses = new Statuses(); Statuses statuses = new Statuses();
statuses.statuses = results.statuses; statuses.statuses = results.statuses;
statuses.pagination = new Pagination(); statuses.pagination = new Pagination();
dealWithPagination(statuses, direction, false, true); dealWithPagination(statuses, direction, false, true, fetchStatus);
} }
}); });
} else { } else {
@ -1115,7 +1138,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id) accountsVM.getFavourites(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), null, max_id)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -1125,7 +1148,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), max_id, null, null) accountsVM.getBookmarks(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, String.valueOf(MastodonHelper.statusesPerCall(requireActivity())), max_id, null, null)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -1135,7 +1158,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, max_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getStatusTrends(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -1145,7 +1168,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getStatusTrends(null, publicTrendsDomain, max_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getStatusTrends(null, publicTrendsDomain, max_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false, true, fetchStatus));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -1163,26 +1186,26 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
@Override @Override
public void onClickMinId(String min_id) { public void onClickMinId(String min_id, Status fetchStatus) {
//Fetch more has been pressed //Fetch more has been pressed
min_id_fetch_more = min_id; min_id_fetch_more = min_id;
route(DIRECTION.TOP, true); route(DIRECTION.TOP, true);
} }
@Override @Override
public void onClickMaxId(String max_id) { public void onClickMaxId(String max_id, Status fetchStatus) {
max_id_fetch_more = max_id; max_id_fetch_more = max_id;
route(DIRECTION.BOTTOM, true); route(DIRECTION.BOTTOM, true, fetchStatus);
} }
@Override @Override
public void autoFetch(String min_id, String max_id, Status statusToUpdate) { public void autoFetch(String min_id, String max_id, Status fetchStatus) {
if (scrollingUp) { if (scrollingUp) {
min_id_fetch_more = min_id; min_id_fetch_more = min_id;
route(DIRECTION.TOP, true); route(DIRECTION.TOP, true, fetchStatus);
} else { } else {
max_id_fetch_more = max_id; max_id_fetch_more = max_id;
route(DIRECTION.BOTTOM, true); route(DIRECTION.BOTTOM, true, fetchStatus);
} }
} }

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fetching_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingHorizontal="6dp">
<ProgressBar
android:id="@+id/fetching_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminate="true" />
<androidx.appcompat.widget.AppCompatTextView
style="@style/TextAppearance.AppCompat.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/fetching_messages"
android:textAlignment="center"
android:textColor="?colorPrimary" />
</androidx.appcompat.widget.LinearLayoutCompat>

View file

@ -1958,4 +1958,5 @@
<string name="load_media_remotely">Load media remotely</string> <string name="load_media_remotely">Load media remotely</string>
<string name="toast_error_media">Media cannot be loaded!</string> <string name="toast_error_media">Media cannot be loaded!</string>
<string name="fetch_remote_media">Automatically fetch remote media when they are not available</string> <string name="fetch_remote_media">Automatically fetch remote media when they are not available</string>
<string name="fetching_messages">Fetching messages</string>
</resources> </resources>