fix vanishing toots bug when refreshing (#1343)
This commit is contained in:
parent
ac2e16e08c
commit
56b53c458a
|
@ -284,6 +284,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateCurrent();
|
this.updateCurrent();
|
||||||
|
this.loadAbove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +293,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
if (this.statuses.isEmpty()) {
|
if (this.statuses.isEmpty()) {
|
||||||
topId = null;
|
topId = null;
|
||||||
} else {
|
} else {
|
||||||
topId = CollectionsKt.first(statuses, Either::isRight).asRight().getId();
|
topId = CollectionsKt.first(this.statuses, Either::isRight).asRight().getId();
|
||||||
}
|
}
|
||||||
this.timelineRepo.getStatuses(topId, null, null, LOAD_AT_ONCE,
|
this.timelineRepo.getStatuses(topId, null, null, LOAD_AT_ONCE,
|
||||||
TimelineRequestMode.NETWORK)
|
TimelineRequestMode.NETWORK)
|
||||||
|
@ -305,22 +306,32 @@ public class TimelineFragment extends SFragment implements
|
||||||
if (!statuses.isEmpty()) {
|
if (!statuses.isEmpty()) {
|
||||||
filterStatuses(statuses);
|
filterStatuses(statuses);
|
||||||
|
|
||||||
// Working around a bug when Mastodon API doesn't return the first
|
|
||||||
// status because of string "id < maxId". Hacking with ID doesn't
|
if (!this.statuses.isEmpty() && topId != null) {
|
||||||
// help.
|
// clear old cached statuses
|
||||||
if (!this.statuses.isEmpty()) {
|
Iterator<Either<Placeholder, Status>> iterator = statuses.iterator();
|
||||||
Either<Placeholder, Status> firstOld = this.statuses.get(0);
|
while (iterator.hasNext()) {
|
||||||
this.statuses.clear();
|
Either<Placeholder, Status> item = iterator.next();
|
||||||
this.statuses.add(firstOld);
|
if(item.isRight()) {
|
||||||
} else {
|
Status status = item.asRight();
|
||||||
this.statuses.clear();
|
if (status.getId().length() < topId.length() || status.getId().compareTo(topId) <= 0) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Placeholder placeholder = item.asLeft();
|
||||||
|
if (placeholder.getId().length() < topId.length() || placeholder.getId().compareTo(topId) <= 0) {
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.statuses.addAll(statuses);
|
this.statuses.addAll(statuses);
|
||||||
this.updateAdapter();
|
this.updateAdapter();
|
||||||
}
|
}
|
||||||
this.bottomLoading = false;
|
this.bottomLoading = false;
|
||||||
// Get more statuses so that users know that something is there
|
|
||||||
this.loadAbove();
|
|
||||||
},
|
},
|
||||||
(e) -> {
|
(e) -> {
|
||||||
this.initialUpdateFailed = true;
|
this.initialUpdateFailed = true;
|
||||||
|
@ -557,9 +568,10 @@ public class TimelineFragment extends SFragment implements
|
||||||
isNeedRefresh = false;
|
isNeedRefresh = false;
|
||||||
if (this.initialUpdateFailed) {
|
if (this.initialUpdateFailed) {
|
||||||
updateCurrent();
|
updateCurrent();
|
||||||
} else {
|
|
||||||
this.loadAbove();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.loadAbove();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAbove() {
|
private void loadAbove() {
|
||||||
|
@ -1171,7 +1183,7 @@ public class TimelineFragment extends SFragment implements
|
||||||
|
|
||||||
private void removeConsecutivePlaceholders() {
|
private void removeConsecutivePlaceholders() {
|
||||||
for (int i = 0; i < statuses.size() - 1; i++) {
|
for (int i = 0; i < statuses.size() - 1; i++) {
|
||||||
if (!statuses.get(i).isRight() && !statuses.get(i + 1).isRight()) {
|
if (statuses.get(i).isLeft() && statuses.get(i + 1).isLeft()) {
|
||||||
statuses.remove(i);
|
statuses.remove(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1201,13 +1213,13 @@ public class TimelineFragment extends SFragment implements
|
||||||
* For certain requests we don't want to see placeholders, they will be removed some other way
|
* For certain requests we don't want to see placeholders, they will be removed some other way
|
||||||
*/
|
*/
|
||||||
private void clearPlaceholdersForResponse(List<Either<Placeholder, Status>> statuses) {
|
private void clearPlaceholdersForResponse(List<Either<Placeholder, Status>> statuses) {
|
||||||
CollectionsKt.removeAll(statuses, s -> !s.isRight());
|
CollectionsKt.removeAll(statuses, Either::isLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replacePlaceholderWithStatuses(List<Either<Placeholder, Status>> newStatuses,
|
private void replacePlaceholderWithStatuses(List<Either<Placeholder, Status>> newStatuses,
|
||||||
boolean fullFetch, int pos) {
|
boolean fullFetch, int pos) {
|
||||||
Either<Placeholder, Status> placeholder = statuses.get(pos);
|
Either<Placeholder, Status> placeholder = statuses.get(pos);
|
||||||
if (!placeholder.isRight()) {
|
if (placeholder.isLeft()) {
|
||||||
statuses.remove(pos);
|
statuses.remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue