diff --git a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java index 5c8859b55..1aa301fe5 100644 --- a/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/DisplayStatusFragment.java @@ -1062,7 +1062,6 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter @Override public void onRetrieveFeedsAfterBookmark(APIResponse apiResponse) { - if (statusListAdapter == null && pixelfedListAdapter == null) return; if (apiResponse == null || (apiResponse.getError() != null && apiResponse.getError().getStatusCode() != 404 && apiResponse.getError().getStatusCode() != 501)) { @@ -1078,36 +1077,42 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter return; } List statuses = apiResponse.getStatuses(); - if (statuses == null || statuses.size() == 0 || this.statuses == null) return; //Find the position of toots between those already present int position = 0; - if (position < this.statuses.size() && statuses.get(0).getCreated_at() != null && this.statuses.get(position).getCreated_at() != null) { while (position < this.statuses.size() && statuses.get(0).getCreated_at().before(this.statuses.get(position).getCreated_at())) { position++; } } ArrayList tmpStatuses = new ArrayList<>(); - for (Status tmpStatus : statuses) { - //Put the toot at its place in the list (id desc) - if (!apiResponse.isFetchmore() && this.statuses.size() > 0 && !this.statuses.contains(tmpStatus) && tmpStatus.getCreated_at() != null && this.statuses.get(0).getCreated_at() != null && tmpStatus.getCreated_at().after(this.statuses.get(0).getCreated_at())) { //Element not already added - //Mark status at new ones when their id is greater than the last read toot id - if ((type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate)) { - tmpStatus.setNew(true); - MainActivity.countNewStatus++; + + + if (this.statuses.size() > 0) { + for (Status tmpStatus : statuses) { + //Put the toot at its place in the list (id desc) + if (!apiResponse.isFetchmore() && this.statuses.size() > 0 && !this.statuses.contains(tmpStatus) && tmpStatus.getCreated_at() != null && this.statuses.get(0).getCreated_at() != null && tmpStatus.getCreated_at().after(this.statuses.get(0).getCreated_at())) { //Element not already added + //Mark status at new ones when their id is greater than the last read toot id + if ((type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate)) { + tmpStatus.setNew(true); + MainActivity.countNewStatus++; + } + tmpStatuses.add(tmpStatus); + } else if (apiResponse.isFetchmore() && !this.statuses.contains(tmpStatus)) { //Element not already added + //Mark status at new ones when their id is greater than the last read toot id + if ((type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate)) { + tmpStatus.setNew(true); + MainActivity.countNewStatus++; + } + tmpStatuses.add(tmpStatus); } - tmpStatuses.add(tmpStatus); - } else if (apiResponse.isFetchmore() && !this.statuses.contains(tmpStatus)) { //Element not already added - //Mark status at new ones when their id is greater than the last read toot id - if ((type == RetrieveFeedsAsyncTask.Type.HOME || type == RetrieveFeedsAsyncTask.Type.PF_HOME) && lastReadTootDate != null && tmpStatus.getCreated_at().after(lastReadTootDate)) { - tmpStatus.setNew(true); - MainActivity.countNewStatus++; - } - tmpStatuses.add(tmpStatus); } + } else { + this.statuses.addAll(statuses); + tmpStatuses.addAll(statuses); } + try { ((MainActivity) context).updateHomeCounter(); } catch (Exception ignored) {