Comment #48 - Adding code for supporting the new adapter

This commit is contained in:
Thomas 2022-06-02 07:40:49 +02:00
parent 6a9c7c13a9
commit b9efa41750
3 changed files with 62 additions and 42 deletions

View file

@ -94,6 +94,7 @@ public class Status implements Serializable, Cloneable {
public transient Spannable span_translate; public transient Spannable span_translate;
public boolean isExpended = false; public boolean isExpended = false;
public boolean isTruncated = true; public boolean isTruncated = true;
public boolean isFetchMore = false;
public boolean isMediaDisplayed = false; public boolean isMediaDisplayed = false;
public boolean isMediaObfuscated = true; public boolean isMediaObfuscated = true;
public boolean isChecked = false; public boolean isChecked = false;

View file

@ -131,10 +131,12 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public static final int STATUS_HIDDEN = 0; public static final int STATUS_HIDDEN = 0;
public static final int STATUS_VISIBLE = 1; public static final int STATUS_VISIBLE = 1;
public static final int STATUS_ART = 2; public static final int STATUS_ART = 2;
public static final int STATUS_FETCH_MORE = 3;
private final List<Status> statusList; private final List<Status> statusList;
private final boolean minified; private final boolean minified;
private final Timeline.TimeLineEnum timelineType; private final Timeline.TimeLineEnum timelineType;
private Context context; private Context context;
public FetchMoreCallBack fetchMoreCallBack;
public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) { public StatusAdapter(List<Status> statuses, Timeline.TimeLineEnum timelineType, boolean minified) {
this.statusList = statuses; this.statusList = statuses;
@ -1615,6 +1617,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (timelineType == Timeline.TimeLineEnum.ART) { if (timelineType == Timeline.TimeLineEnum.ART) {
return STATUS_ART; return STATUS_ART;
} else if (statusList.get(position).isFetchMore) {
return STATUS_FETCH_MORE;
} else { } else {
return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN; return isVisible(timelineType, statusList.get(position)) ? STATUS_VISIBLE : STATUS_HIDDEN;
} }
@ -1717,9 +1721,16 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
intent.putExtra(Helper.ARG_STATUS, status); intent.putExtra(Helper.ARG_STATUS, status);
context.startActivity(intent); context.startActivity(intent);
}); });
} else if (viewHolder.getItemViewType() == STATUS_FETCH_MORE) {
StatusViewHolder holder = (StatusViewHolder) viewHolder;
holder.bindingFetchMore.fetchMore.setOnClickListener(v -> fetchMoreCallBack.onClick(status.id));
} }
} }
public interface FetchMoreCallBack {
void onClick(String min_id);
}
@Override @Override
public int getItemCount() { public int getItemCount() {
return statusList.size(); return statusList.size();

View file

@ -62,7 +62,7 @@ import app.fedilab.android.viewmodel.mastodon.SearchVM;
import app.fedilab.android.viewmodel.mastodon.TimelinesVM; import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
public class FragmentMastodonTimeline extends Fragment { public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.FetchMoreCallBack {
private FragmentPaginationBinding binding; private FragmentPaginationBinding binding;
@ -72,7 +72,7 @@ public class FragmentMastodonTimeline extends Fragment {
private List<Status> statuses; private List<Status> statuses;
private String search, searchCache; private String search, searchCache;
private Status statusReport; private Status statusReport;
private String max_id, min_id; private String max_id, min_id, min_id_fetch_more;
private StatusAdapter statusAdapter; private StatusAdapter statusAdapter;
private Timeline.TimeLineEnum timelineType; private Timeline.TimeLineEnum timelineType;
//Handle actions that can be done in other fragments //Handle actions that can be done in other fragments
@ -234,7 +234,7 @@ public class FragmentMastodonTimeline extends Fragment {
markers = new ArrayList<>(); markers = new ArrayList<>();
max_id = statusReport != null ? statusReport.id : null; max_id = statusReport != null ? statusReport.id : null;
flagLoading = false; flagLoading = false;
router(null); router(null, false);
return binding.getRoot(); return binding.getRoot();
} }
@ -261,7 +261,7 @@ public class FragmentMastodonTimeline extends Fragment {
binding.swipeContainer.setRefreshing(true); binding.swipeContainer.setRefreshing(true);
max_id = null; max_id = null;
flagLoading = false; flagLoading = false;
router(null); router(null, false);
}); });
if (statuses == null || statuses.statuses == null || statuses.statuses.size() == 0) { if (statuses == null || statuses.statuses == null || statuses.statuses.size() == 0) {
@ -340,7 +340,7 @@ public class FragmentMastodonTimeline extends Fragment {
if (!flagLoading) { if (!flagLoading) {
flagLoading = true; flagLoading = true;
binding.loadingNextElements.setVisibility(View.VISIBLE); binding.loadingNextElements.setVisibility(View.VISIBLE);
router(DIRECTION.BOTTOM); router(DIRECTION.BOTTOM, false);
} }
} else { } else {
binding.loadingNextElements.setVisibility(View.GONE); binding.loadingNextElements.setVisibility(View.GONE);
@ -349,7 +349,7 @@ public class FragmentMastodonTimeline extends Fragment {
if (!flagLoading) { if (!flagLoading) {
flagLoading = true; flagLoading = true;
binding.loadingNextElements.setVisibility(View.VISIBLE); binding.loadingNextElements.setVisibility(View.VISIBLE);
router(DIRECTION.TOP); router(DIRECTION.TOP, false);
} }
} }
} }
@ -357,12 +357,13 @@ public class FragmentMastodonTimeline extends Fragment {
} }
} }
/** /**
* Update view and pagination when scrolling down * Update view and pagination when scrolling down
* *
* @param fetched_statuses Statuses * @param fetched_statuses Statuses
*/ */
private void dealWithPagination(Statuses fetched_statuses, DIRECTION direction) { private void dealWithPagination(Statuses fetched_statuses, DIRECTION direction, boolean fetchingMissing) {
if (binding == null) { if (binding == null) {
return; return;
} }
@ -459,18 +460,18 @@ public class FragmentMastodonTimeline extends Fragment {
} }
} }
private void router(DIRECTION direction) { private void router(DIRECTION direction, boolean fetchingMissing) {
if (networkAvailable == BaseMainActivity.status.UNKNOWN) { if (networkAvailable == BaseMainActivity.status.UNKNOWN) {
new Thread(() -> { new Thread(() -> {
if (networkAvailable == BaseMainActivity.status.UNKNOWN) { if (networkAvailable == BaseMainActivity.status.UNKNOWN) {
networkAvailable = Helper.isConnectedToInternet(requireActivity(), BaseMainActivity.currentInstance); networkAvailable = Helper.isConnectedToInternet(requireActivity(), BaseMainActivity.currentInstance);
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> route(direction); Runnable myRunnable = () -> route(direction, fetchingMissing);
mainHandler.post(myRunnable); mainHandler.post(myRunnable);
}).start(); }).start();
} else { } else {
route(direction); route(direction, fetchingMissing);
} }
} }
@ -479,14 +480,14 @@ public class FragmentMastodonTimeline extends Fragment {
* *
* @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) { private void route(DIRECTION direction, boolean fetchingMissing) {
new Thread(() -> { new Thread(() -> {
QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident); QuickLoad quickLoad = new QuickLoad(requireActivity()).getSavedValue(MainActivity.currentUserID, MainActivity.currentInstance, timelineType, ident);
if (binding == null) { if (binding == null) {
return; return;
} }
if (!binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) { if (!fetchingMissing && !binding.swipeContainer.isRefreshing() && direction == null && quickLoad != null && quickLoad.statuses != null && quickLoad.statuses.size() > 0) {
Statuses statuses = new Statuses(); Statuses statuses = new Statuses();
statuses.statuses = quickLoad.statuses; statuses.statuses = quickLoad.statuses;
statuses.pagination = new Pagination(); statuses.pagination = new Pagination();
@ -501,17 +502,17 @@ public class FragmentMastodonTimeline extends Fragment {
// --- HOME TIMELINE --- // --- HOME TIMELINE ---
if (timelineType == Timeline.TimeLineEnum.HOME) { if (timelineType == Timeline.TimeLineEnum.HOME) {
//for more visibility it's done through loadHomeStrategy method //for more visibility it's done through loadHomeStrategy method
loadHomeStrategy(direction); loadHomeStrategy(direction, fetchingMissing);
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE } else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
if (direction == null) { if (direction == null) {
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, true, false, false, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
} }
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE } else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
if (direction == null) { if (direction == null) {
@ -519,10 +520,10 @@ public class FragmentMastodonTimeline extends Fragment {
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
} }
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE } else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
if (direction == null) { if (direction == null) {
@ -530,10 +531,10 @@ public class FragmentMastodonTimeline extends Fragment {
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getPublic(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
} }
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE } else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
if (direction == null) { if (direction == null) {
@ -541,10 +542,10 @@ public class FragmentMastodonTimeline extends Fragment {
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
} }
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE } else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
if (tagTimeline == null) { if (tagTimeline == null) {
@ -556,10 +557,10 @@ public class FragmentMastodonTimeline extends Fragment {
.observe(getViewLifecycleOwner(), this::initializeStatusesCommonView); .observe(getViewLifecycleOwner(), this::initializeStatusesCommonView);
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity())) timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
} }
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES } else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
if (direction == null) { if (direction == null) {
@ -579,7 +580,7 @@ public class FragmentMastodonTimeline extends Fragment {
} }
} else if (direction == DIRECTION.BOTTOM) { } else if (direction == DIRECTION.BOTTOM) {
accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity())) accountsVM.getAccountStatuses(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, accountTimeline.id, max_id, null, null, exclude_replies, exclude_reblogs, media_only, false, MastodonHelper.statusesPerCall(requireActivity()))
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -607,7 +608,7 @@ public class FragmentMastodonTimeline extends Fragment {
.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)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -617,7 +618,7 @@ public class FragmentMastodonTimeline extends Fragment {
.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)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} else { } else {
flagLoading = false; flagLoading = false;
} }
@ -635,9 +636,9 @@ public class FragmentMastodonTimeline extends Fragment {
* *
* @param direction - DIRECTION enum * @param direction - DIRECTION enum
*/ */
private void loadHomeStrategy(DIRECTION direction) { private void loadHomeStrategy(DIRECTION direction, boolean fetchingMissing) {
//When no direction is provided, it means it's the first call //When no direction is provided, it means it's the first call
if (direction == null) { if (direction == null && !fetchingMissing) {
//Two ways, depending of the Internet connection //Two ways, depending of the Internet connection
//Connection is available toots are loaded remotely //Connection is available toots are loaded remotely
if (networkAvailable == BaseMainActivity.status.CONNECTED) { if (networkAvailable == BaseMainActivity.status.CONNECTED) {
@ -684,31 +685,31 @@ public class FragmentMastodonTimeline extends Fragment {
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null) timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null)
.observe(getViewLifecycleOwner(), statusesBottomCache -> { .observe(getViewLifecycleOwner(), statusesBottomCache -> {
if (statusesBottomCache != null && statusesBottomCache.statuses != null && statusesBottomCache.statuses.size() > 0) { if (statusesBottomCache != null && statusesBottomCache.statuses != null && statusesBottomCache.statuses.size() > 0) {
dealWithPagination(statusesBottomCache, DIRECTION.BOTTOM); dealWithPagination(statusesBottomCache, DIRECTION.BOTTOM, fetchingMissing);
} else { // If not, we fetch remotely } else { // If not, we fetch remotely
timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), false) timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), false)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} }
}); });
} else { } else {
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null) timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null)
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM)); .observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing));
} }
} else if (direction == DIRECTION.TOP) { } else if (direction == DIRECTION.TOP) {
if (networkAvailable == BaseMainActivity.status.CONNECTED) { if (networkAvailable == BaseMainActivity.status.CONNECTED) {
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, null, min_id) timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, null, fetchingMissing ? min_id_fetch_more : min_id)
.observe(getViewLifecycleOwner(), statusesTopCache -> { .observe(getViewLifecycleOwner(), statusesTopCache -> {
if (statusesTopCache != null && statusesTopCache.statuses != null && statusesTopCache.statuses.size() > 0) { if (statusesTopCache != null && statusesTopCache.statuses != null && statusesTopCache.statuses.size() > 0) {
dealWithPagination(statusesTopCache, DIRECTION.TOP); dealWithPagination(statusesTopCache, DIRECTION.TOP, fetchingMissing);
} else { } else {
timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, min_id, MastodonHelper.statusesPerCall(requireActivity()), false) timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, null, null, fetchingMissing ? min_id_fetch_more : min_id, MastodonHelper.statusesPerCall(requireActivity()), false)
.observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP, fetchingMissing));
} }
}); });
} else { } else {
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, null, min_id) timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, null, fetchingMissing ? min_id_fetch_more : min_id)
.observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP)); .observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP, fetchingMissing));
} }
} }
} }
@ -723,6 +724,13 @@ public class FragmentMastodonTimeline extends Fragment {
} }
} }
@Override
public void onClick(String min_id) {
//Fetch more has been pressed
min_id_fetch_more = min_id;
route(DIRECTION.TOP, true);
}
public enum DIRECTION { public enum DIRECTION {
TOP, TOP,
BOTTOM BOTTOM