|
|
@ -77,7 +77,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
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, min_id_fetch_more;
|
|
|
|
private String max_id, min_id, min_id_fetch_more, max_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
|
|
|
@ -471,7 +471,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
statusFetchMore.isFetchMore = true;
|
|
|
|
statusFetchMore.isFetchMore = true;
|
|
|
|
statusFetchMore.id = Helper.generateString();
|
|
|
|
statusFetchMore.id = Helper.generateString();
|
|
|
|
int insertAt;
|
|
|
|
int insertAt;
|
|
|
|
if (direction == DIRECTION.REFRESH) {
|
|
|
|
if (direction == DIRECTION.REFRESH || direction == DIRECTION.BOTTOM) {
|
|
|
|
insertAt = lastInsertedPosition;
|
|
|
|
insertAt = lastInsertedPosition;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
insertAt = initialInsertedPosition;
|
|
|
|
insertAt = initialInsertedPosition;
|
|
|
@ -620,8 +620,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
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, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.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, fetchingMissing ? min_id_fetch_more : 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, fetchingMissing));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
|
|
|
@ -640,8 +640,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, 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, false, true, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getPublic(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, false, true, false, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.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, fetchingMissing ? min_id_fetch_more : 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, fetchingMissing));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
|
|
|
@ -726,8 +726,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
timelinesVM.getPublic(null, remoteInstance, true, false, false, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getPublic(null, remoteInstance, 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(null, remoteInstance, true, false, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getPublic(null, remoteInstance, true, false, false, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.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, fetchingMissing ? min_id_fetch_more : 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, fetchingMissing));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
|
|
|
@ -747,8 +747,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, 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.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getList(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, list_id, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.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, fetchingMissing ? min_id_fetch_more : 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, fetchingMissing));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
|
|
|
@ -771,8 +771,8 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, null, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
timelinesVM.getHashTag(BaseMainActivity.currentToken, BaseMainActivity.currentInstance, tagTimeline.name, false, tagTimeline.isART, tagTimeline.all, tagTimeline.any, tagTimeline.none, 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.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, fetchingMissing ? max_id_fetch_more : max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()))
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.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, fetchingMissing ? min_id_fetch_more : 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, fetchingMissing));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.TOP, fetchingMissing));
|
|
|
@ -907,21 +907,26 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (direction == DIRECTION.BOTTOM) {
|
|
|
|
} else if (direction == DIRECTION.BOTTOM) {
|
|
|
|
if (networkAvailable == BaseMainActivity.status.CONNECTED) {
|
|
|
|
if (!fetchingMissing) {
|
|
|
|
//We first if we get results from cache
|
|
|
|
if (networkAvailable == BaseMainActivity.status.CONNECTED) {
|
|
|
|
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null, null)
|
|
|
|
//We first if we get results from cache
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottomCache -> {
|
|
|
|
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null, null)
|
|
|
|
if (statusesBottomCache != null && statusesBottomCache.statuses != null && statusesBottomCache.statuses.size() > 0) {
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottomCache -> {
|
|
|
|
dealWithPagination(statusesBottomCache, DIRECTION.BOTTOM, false);
|
|
|
|
if (statusesBottomCache != null && statusesBottomCache.statuses != null && statusesBottomCache.statuses.size() > 0) {
|
|
|
|
} else { // If not, we fetch remotely
|
|
|
|
dealWithPagination(statusesBottomCache, DIRECTION.BOTTOM, false);
|
|
|
|
timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), false)
|
|
|
|
} else { // If not, we fetch remotely
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
timelinesVM.getHome(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, false, max_id, null, null, MastodonHelper.statusesPerCall(requireActivity()), false)
|
|
|
|
}
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null, null)
|
|
|
|
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id, null, null)
|
|
|
|
timelinesVM.getHomeCache(BaseMainActivity.currentInstance, BaseMainActivity.currentUserID, max_id_fetch_more, null, null)
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, false));
|
|
|
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, true));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (direction == DIRECTION.TOP) {
|
|
|
|
} else if (direction == DIRECTION.TOP) {
|
|
|
|
if (!fetchingMissing) {
|
|
|
|
if (!fetchingMissing) {
|
|
|
@ -968,7 +973,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onClick(String min_id, String id) {
|
|
|
|
public void onClickMinId(String min_id, String id) {
|
|
|
|
//Fetch more has been pressed
|
|
|
|
//Fetch more has been pressed
|
|
|
|
min_id_fetch_more = min_id;
|
|
|
|
min_id_fetch_more = min_id;
|
|
|
|
Status status = null;
|
|
|
|
Status status = null;
|
|
|
@ -987,6 +992,25 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
|
|
|
route(DIRECTION.TOP, true);
|
|
|
|
route(DIRECTION.TOP, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onClickMaxId(String max_id, String id) {
|
|
|
|
|
|
|
|
max_id_fetch_more = max_id;
|
|
|
|
|
|
|
|
Status status = null;
|
|
|
|
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
for (Status currentStatus : this.statuses) {
|
|
|
|
|
|
|
|
if (currentStatus.id.compareTo(id) == 0) {
|
|
|
|
|
|
|
|
status = currentStatus;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
position++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != null) {
|
|
|
|
|
|
|
|
this.statuses.remove(position);
|
|
|
|
|
|
|
|
statusAdapter.notifyItemRemoved(position);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
route(DIRECTION.BOTTOM, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public enum DIRECTION {
|
|
|
|
public enum DIRECTION {
|
|
|
|
TOP,
|
|
|
|
TOP,
|
|
|
|
BOTTOM,
|
|
|
|
BOTTOM,
|
|
|
|