mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-02-22 17:09:44 +02:00
Fix issue #1090 - Instant search of Hashtag repeats results
This commit is contained in:
parent
7e78b5da6e
commit
031c842ba7
2 changed files with 17 additions and 16 deletions
|
@ -166,7 +166,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toRemove.size() > 0) {
|
if (!toRemove.isEmpty()) {
|
||||||
for (int i = 0; i < toRemove.size(); i++) {
|
for (int i = 0; i < toRemove.size(); i++) {
|
||||||
int position = getPosition(toRemove.get(i));
|
int position = getPosition(toRemove.get(i));
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
|
@ -215,7 +215,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
//Allow to recreate data when detaching/attaching fragment
|
//Allow to recreate data when detaching/attaching fragment
|
||||||
public void recreate() {
|
public void recreate() {
|
||||||
initialStatuses = null;
|
initialStatuses = null;
|
||||||
if (timelineStatuses != null && timelineStatuses.size() > 0) {
|
if (timelineStatuses != null && !timelineStatuses.isEmpty()) {
|
||||||
int count = timelineStatuses.size();
|
int count = timelineStatuses.size();
|
||||||
timelineStatuses.clear();
|
timelineStatuses.clear();
|
||||||
timelineStatuses = new ArrayList<>();
|
timelineStatuses = new ArrayList<>();
|
||||||
|
@ -264,7 +264,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
router(null);
|
router(null);
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
if (timelineStatuses != null && timelineStatuses.size() > 0) {
|
if (timelineStatuses != null && !timelineStatuses.isEmpty()) {
|
||||||
route(DIRECTION.FETCH_NEW, true);
|
route(DIRECTION.FETCH_NEW, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -531,7 +531,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
binding.swipeContainer.setRefreshing(false);
|
binding.swipeContainer.setRefreshing(false);
|
||||||
binding.loadingNextElements.setVisibility(View.GONE);
|
binding.loadingNextElements.setVisibility(View.GONE);
|
||||||
flagLoading = false;
|
flagLoading = false;
|
||||||
if (timelineStatuses != null && fetched_statuses != null && fetched_statuses.statuses != null && fetched_statuses.statuses.size() > 0) {
|
if (timelineStatuses != null && fetched_statuses != null && fetched_statuses.statuses != null && !fetched_statuses.statuses.isEmpty()) {
|
||||||
flagLoading = fetched_statuses.pagination.max_id == null;
|
flagLoading = fetched_statuses.pagination.max_id == null;
|
||||||
binding.noAction.setVisibility(View.GONE);
|
binding.noAction.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
@ -554,13 +554,13 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mediaStatuses.size() > 0) {
|
if (!mediaStatuses.isEmpty()) {
|
||||||
fetched_statuses.statuses = mediaStatuses;
|
fetched_statuses.statuses = mediaStatuses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Update the timeline with new statuses
|
//Update the timeline with new statuses
|
||||||
int insertedStatus;
|
int insertedStatus;
|
||||||
if (timelineType != Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC && timelineType != Timeline.TimeLineEnum.TREND_MESSAGE && search == null) {
|
if (timelineType != Timeline.TimeLineEnum.TREND_MESSAGE_PUBLIC && timelineType != Timeline.TimeLineEnum.TREND_MESSAGE ) {
|
||||||
insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
insertedStatus = updateStatusListWith(fetched_statuses.statuses);
|
||||||
} else { //Trends cannot be ordered by id
|
} else { //Trends cannot be ordered by id
|
||||||
insertedStatus = fetched_statuses.statuses.size();
|
insertedStatus = fetched_statuses.statuses.size();
|
||||||
|
@ -631,7 +631,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
route(DIRECTION.REFRESH, true);
|
route(DIRECTION.REFRESH, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (initialStatus == null && (statuses == null || statuses.statuses == null || statuses.statuses.size() == 0)) {
|
if (initialStatus == null && (statuses == null || statuses.statuses == null || statuses.statuses.isEmpty())) {
|
||||||
binding.noAction.setVisibility(View.VISIBLE);
|
binding.noAction.setVisibility(View.VISIBLE);
|
||||||
return;
|
return;
|
||||||
} else if (timelineType == Timeline.TimeLineEnum.ART) {
|
} else if (timelineType == Timeline.TimeLineEnum.ART) {
|
||||||
|
@ -652,7 +652,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mediaStatuses.size() > 0) {
|
if (!mediaStatuses.isEmpty()) {
|
||||||
statuses.statuses = mediaStatuses;
|
statuses.statuses = mediaStatuses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,7 +763,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
*/
|
*/
|
||||||
private int updateStatusListWith(List<Status> statusListReceived) {
|
private int updateStatusListWith(List<Status> statusListReceived) {
|
||||||
int insertedStatus = 0;
|
int insertedStatus = 0;
|
||||||
if (statusListReceived != null && statusListReceived.size() > 0) {
|
if (statusListReceived != null && !statusListReceived.isEmpty()) {
|
||||||
for (Status statusReceived : statusListReceived) {
|
for (Status statusReceived : statusListReceived) {
|
||||||
int position = 0;
|
int position = 0;
|
||||||
if (timelineStatuses != null) {
|
if (timelineStatuses != null) {
|
||||||
|
@ -931,7 +931,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
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.isEmpty()) {
|
||||||
getLiveStatus(null, fetchingMissing, timelineParams, true, fetchStatus);
|
getLiveStatus(null, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
initialStatuses = statusesCached;
|
initialStatuses = statusesCached;
|
||||||
|
@ -941,7 +941,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
} else if (direction == DIRECTION.BOTTOM) {
|
} else if (direction == DIRECTION.BOTTOM) {
|
||||||
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.isEmpty()) {
|
||||||
getLiveStatus(DIRECTION.BOTTOM, fetchingMissing, timelineParams, true, fetchStatus);
|
getLiveStatus(DIRECTION.BOTTOM, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
dealWithPagination(statusesCachedBottom, DIRECTION.BOTTOM, fetchingMissing, true, fetchStatus);
|
dealWithPagination(statusesCachedBottom, DIRECTION.BOTTOM, fetchingMissing, true, fetchStatus);
|
||||||
|
@ -954,7 +954,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
} else if (direction == DIRECTION.TOP) {
|
} else if (direction == DIRECTION.TOP) {
|
||||||
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.isEmpty()) {
|
||||||
getLiveStatus(DIRECTION.TOP, fetchingMissing, timelineParams, true, fetchStatus);
|
getLiveStatus(DIRECTION.TOP, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
dealWithPagination(statusesCachedTop, DIRECTION.TOP, fetchingMissing, true, fetchStatus);
|
dealWithPagination(statusesCachedTop, DIRECTION.TOP, fetchingMissing, true, fetchStatus);
|
||||||
|
@ -966,7 +966,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
} else if (direction == DIRECTION.REFRESH) {
|
} else if (direction == DIRECTION.REFRESH) {
|
||||||
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.isEmpty()) {
|
||||||
getLiveStatus(direction, fetchingMissing, timelineParams, true, fetchStatus);
|
getLiveStatus(direction, fetchingMissing, timelineParams, true, fetchStatus);
|
||||||
} else {
|
} else {
|
||||||
if (statusAdapter != null) {
|
if (statusAdapter != null) {
|
||||||
|
@ -985,7 +985,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
timelinesVM.getTimeline(timelineStatuses, timelineParams)
|
||||||
.observe(getViewLifecycleOwner(), statuses -> {
|
.observe(getViewLifecycleOwner(), statuses -> {
|
||||||
initialStatuses = statuses;
|
initialStatuses = statuses;
|
||||||
if (!retry_for_home_done && timelineType == Timeline.TimeLineEnum.HOME && timelineParams.maxId != null && (statuses == null || statuses.statuses == null || statuses.statuses.size() == 0)) {
|
if (!retry_for_home_done && timelineType == Timeline.TimeLineEnum.HOME && timelineParams.maxId != null && (statuses == null || statuses.statuses == null || statuses.statuses.isEmpty())) {
|
||||||
retry_for_home_done = true;
|
retry_for_home_done = true;
|
||||||
timelineParams.maxId = null;
|
timelineParams.maxId = null;
|
||||||
max_id = null;
|
max_id = null;
|
||||||
|
@ -1185,6 +1185,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
|
||||||
displayStatuses(direction, accountId[0], tempInstance[0], tempToken[0], fetchStatus);
|
displayStatuses(direction, accountId[0], tempInstance[0], tempToken[0], fetchStatus);
|
||||||
} else if (search != null) {
|
} else if (search != null) {
|
||||||
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
SearchVM searchVM = new ViewModelProvider(FragmentMastodonTimeline.this).get(viewModelKey, SearchVM.class);
|
||||||
|
|
||||||
if (direction == null) {
|
if (direction == null) {
|
||||||
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.SEARCH_PER_CALL)
|
searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, search.trim(), null, null, false, true, false, 0, null, null, MastodonHelper.SEARCH_PER_CALL)
|
||||||
.observe(getViewLifecycleOwner(), results -> {
|
.observe(getViewLifecycleOwner(), results -> {
|
||||||
|
|
|
@ -523,11 +523,11 @@ public class TimelinesVM extends AndroidViewModel {
|
||||||
List<Status> statusList = timelineResponse.body();
|
List<Status> statusList = timelineResponse.body();
|
||||||
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
statuses.statuses = TimelineHelper.filterStatus(getApplication().getApplicationContext(), statusList, timelineParams.type);
|
||||||
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
statuses.pagination = MastodonHelper.getPagination(timelineResponse.headers());
|
||||||
if (statuses.statuses != null && statuses.statuses.size() > 0) {
|
if (statuses.statuses != null && !statuses.statuses.isEmpty()) {
|
||||||
//Fetch More is added on filtered statuses
|
//Fetch More is added on filtered statuses
|
||||||
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
addFetchMore(statuses.statuses, timelineStatuses, timelineParams);
|
||||||
//All statuses (even filtered will be added to cache)
|
//All statuses (even filtered will be added to cache)
|
||||||
if (statusList != null && statusList.size() > 0) {
|
if (statusList != null && !statusList.isEmpty()) {
|
||||||
for (Status status : statusList) {
|
for (Status status : statusList) {
|
||||||
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
StatusCache statusCacheDAO = new StatusCache(getApplication().getApplicationContext());
|
||||||
StatusCache statusCache = new StatusCache();
|
StatusCache statusCache = new StatusCache();
|
||||||
|
|
Loading…
Reference in a new issue