Fix empty home timeline

This commit is contained in:
Thomas 2020-06-06 14:22:51 +02:00
parent 5a02bbf2c5
commit 6346c9cb20
1 changed files with 23 additions and 18 deletions

View File

@ -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<Status> 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<Status> 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) {