Add indicator
This commit is contained in:
parent
1b88633887
commit
95ad3d687c
|
@ -272,6 +272,23 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private int getDirectPosition(Status status) {
|
||||||
|
int position = 0;
|
||||||
|
boolean found = false;
|
||||||
|
if (status.id == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (Status _status : timelineStatuses) {
|
||||||
|
if (_status.id != null && _status.id.compareTo(status.id) == 0) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
return found ? position : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the position of the status in the ArrayList
|
* Return the position of the status in the ArrayList
|
||||||
*
|
*
|
||||||
|
@ -438,8 +455,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
if (binding == null || !isAdded() || getActivity() == null) {
|
if (binding == null || !isAdded() || getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetchStatus != null) {
|
if (fetchStatus != null) {
|
||||||
int position = getPosition(fetchStatus);
|
int position = getDirectPosition(fetchStatus);
|
||||||
if (position >= 0 && position < timelineStatuses.size()) {
|
if (position >= 0 && position < timelineStatuses.size()) {
|
||||||
timelineStatuses.get(position).isFetching = false;
|
timelineStatuses.get(position).isFetching = false;
|
||||||
statusAdapter.notifyItemChanged(position);
|
statusAdapter.notifyItemChanged(position);
|
||||||
|
@ -518,15 +536,6 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intialize the common view for statuses on different timelines
|
* Intialize the common view for statuses on different timelines
|
||||||
*
|
*
|
||||||
|
@ -714,7 +723,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
*
|
*
|
||||||
* @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 routeCommon(DIRECTION direction, boolean fetchingMissing) {
|
private void routeCommon(DIRECTION direction, boolean fetchingMissing, Status fetchStatus) {
|
||||||
if (binding == null || !isAdded() || getActivity() == null) {
|
if (binding == null || !isAdded() || getActivity() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -777,9 +786,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);
|
boolean useCache = sharedpreferences.getBoolean(getString(R.string.SET_USE_CACHE), true);
|
||||||
if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) {
|
if (useCache && direction != DIRECTION.SCROLL_TOP && direction != DIRECTION.FETCH_NEW) {
|
||||||
getCachedStatus(direction, fetchingMissing, timelineParams);
|
getCachedStatus(direction, fetchingMissing, timelineParams, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
getLiveStatus(direction, fetchingMissing, timelineParams, true);
|
getLiveStatus(direction, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -838,13 +847,13 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getCachedStatus(DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams) {
|
private void getCachedStatus(DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, Status fetchStatus) {
|
||||||
|
|
||||||
if (direction == null) {
|
if (direction == null) {
|
||||||
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesCached -> {
|
.observe(getViewLifecycleOwner(), statusesCached -> {
|
||||||
if (statusesCached == null || statusesCached.statuses == null || statusesCached.statuses.size() == 0) {
|
if (statusesCached == null || statusesCached.statuses == null || statusesCached.statuses.size() == 0) {
|
||||||
getLiveStatus(null, fetchingMissing, timelineParams, true);
|
getLiveStatus(null, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
initialStatuses = statusesCached;
|
initialStatuses = statusesCached;
|
||||||
initializeStatusesCommonView(statusesCached);
|
initializeStatusesCommonView(statusesCached);
|
||||||
|
@ -854,12 +863,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesCachedBottom -> {
|
.observe(getViewLifecycleOwner(), statusesCachedBottom -> {
|
||||||
if (statusesCachedBottom == null || statusesCachedBottom.statuses == null || statusesCachedBottom.statuses.size() == 0) {
|
if (statusesCachedBottom == null || statusesCachedBottom.statuses == null || statusesCachedBottom.statuses.size() == 0) {
|
||||||
getLiveStatus(DIRECTION.BOTTOM, fetchingMissing, timelineParams, true);
|
getLiveStatus(DIRECTION.BOTTOM, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
dealWithPagination(statusesCachedBottom, DIRECTION.BOTTOM, fetchingMissing, true);
|
dealWithPagination(statusesCachedBottom, DIRECTION.BOTTOM, fetchingMissing, true, fetchStatus);
|
||||||
//Also check remotely to detect potential holes
|
//Also check remotely to detect potential holes
|
||||||
if (fetchingMissing) {
|
if (fetchingMissing) {
|
||||||
getLiveStatus(direction, true, timelineParams, false);
|
getLiveStatus(direction, true, timelineParams, false, fetchStatus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -867,11 +876,11 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesCachedTop -> {
|
.observe(getViewLifecycleOwner(), statusesCachedTop -> {
|
||||||
if (statusesCachedTop == null || statusesCachedTop.statuses == null || statusesCachedTop.statuses.size() == 0) {
|
if (statusesCachedTop == null || statusesCachedTop.statuses == null || statusesCachedTop.statuses.size() == 0) {
|
||||||
getLiveStatus(DIRECTION.TOP, fetchingMissing, timelineParams, true);
|
getLiveStatus(DIRECTION.TOP, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
dealWithPagination(statusesCachedTop, DIRECTION.TOP, fetchingMissing, true);
|
dealWithPagination(statusesCachedTop, DIRECTION.TOP, fetchingMissing, true, fetchStatus);
|
||||||
//Also check remotely to detect potential holes
|
//Also check remotely to detect potential holes
|
||||||
getLiveStatus(direction, true, timelineParams, false);
|
getLiveStatus(direction, true, timelineParams, false, fetchStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -879,10 +888,10 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
timelinesVM.getTimelineCache(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesRefresh -> {
|
.observe(getViewLifecycleOwner(), statusesRefresh -> {
|
||||||
if (statusesRefresh == null || statusesRefresh.statuses == null || statusesRefresh.statuses.size() == 0) {
|
if (statusesRefresh == null || statusesRefresh.statuses == null || statusesRefresh.statuses.size() == 0) {
|
||||||
getLiveStatus(direction, fetchingMissing, timelineParams, true);
|
getLiveStatus(direction, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
if (statusAdapter != null) {
|
if (statusAdapter != null) {
|
||||||
dealWithPagination(statusesRefresh, direction, true, true);
|
dealWithPagination(statusesRefresh, direction, true, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
initializeStatusesCommonView(statusesRefresh);
|
initializeStatusesCommonView(statusesRefresh);
|
||||||
}
|
}
|
||||||
|
@ -891,7 +900,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getLiveStatus(DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, boolean canScroll) {
|
private void getLiveStatus(DIRECTION direction, boolean fetchingMissing, TimelinesVM.TimelineParams timelineParams, boolean canScroll, Status fetchStatus) {
|
||||||
|
|
||||||
if (direction == null) {
|
if (direction == null) {
|
||||||
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
||||||
|
@ -901,15 +910,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
});
|
});
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing, canScroll));
|
.observe(getViewLifecycleOwner(), statusesBottom -> dealWithPagination(statusesBottom, DIRECTION.BOTTOM, fetchingMissing, canScroll, fetchStatus));
|
||||||
} else if (direction == DIRECTION.TOP) {
|
} else if (direction == DIRECTION.TOP) {
|
||||||
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP, fetchingMissing, canScroll));
|
.observe(getViewLifecycleOwner(), statusesTop -> dealWithPagination(statusesTop, DIRECTION.TOP, fetchingMissing, canScroll, fetchStatus));
|
||||||
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) {
|
} else if (direction == DIRECTION.REFRESH || direction == DIRECTION.SCROLL_TOP || direction == DIRECTION.FETCH_NEW) {
|
||||||
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statusesRefresh -> {
|
.observe(getViewLifecycleOwner(), statusesRefresh -> {
|
||||||
if (statusAdapter != null) {
|
if (statusAdapter != null) {
|
||||||
dealWithPagination(statusesRefresh, direction, true, canScroll);
|
dealWithPagination(statusesRefresh, direction, true, canScroll, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
initializeStatusesCommonView(statusesRefresh);
|
initializeStatusesCommonView(statusesRefresh);
|
||||||
}
|
}
|
||||||
|
@ -938,13 +947,13 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
// --- 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
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.LOCAL) { //LOCAL TIMELINE
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.PUBLIC) { //PUBLIC TIMELINE
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.BUBBLE) { //BUBBLE TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.BUBBLE) { //BUBBLE TIMELINE
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.REMOTE) { //REMOTE TIMELINE
|
||||||
//NITTER TIMELINES
|
//NITTER TIMELINES
|
||||||
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
|
if (pinnedTimeline != null && pinnedTimeline.remoteInstance.type == RemoteInstance.InstanceType.NITTER) {
|
||||||
|
@ -1013,12 +1022,12 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else { //Other remote timelines
|
} else { //Other remote timelines
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
}
|
}
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.LIST) { //LIST TIMELINE
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
|
} else if (timelineType == Timeline.TimeLineEnum.TAG || timelineType == Timeline.TimeLineEnum.ART) { //TAG TIMELINE
|
||||||
routeCommon(direction, fetchingMissing);
|
routeCommon(direction, fetchingMissing, fetchStatus);
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
|
} else if (timelineType == Timeline.TimeLineEnum.ACCOUNT_TIMELINE) { //PROFILE TIMELINES
|
||||||
String tempToken;
|
String tempToken;
|
||||||
String tempInstance;
|
String tempInstance;
|
||||||
|
@ -1189,7 +1198,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
public void onClickMinId(String min_id, Status fetchStatus) {
|
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, fetchStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue