Fix incorrectly incrementing IDs before sending to server. (#1026)
* Fix incorrectly incrementing IDs before sending to server. * Add TimelineRepositoryTest, fix adding placeholder, fix String#dec() * Add more TimelineRepository tests, fix bugs * Add tests for adding statuses from DB.
This commit is contained in:
parent
85610a8311
commit
63952813c8
11 changed files with 631 additions and 208 deletions
|
@ -244,14 +244,14 @@ public class TimelineFragment extends SFragment implements
|
|||
if (this.kind == Kind.HOME) {
|
||||
this.tryCache();
|
||||
} else {
|
||||
sendFetchTimelineRequest(null, null, FetchEnd.BOTTOM, -1);
|
||||
sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void tryCache() {
|
||||
// Request timeline from disk to make it quick, then replace it with timeline from
|
||||
// the server to update it
|
||||
this.timelineRepo.getStatuses(null, null, LOAD_AT_ONCE,
|
||||
this.timelineRepo.getStatuses(null, null, null, LOAD_AT_ONCE,
|
||||
TimelineRequestMode.DISK)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||
|
@ -278,7 +278,7 @@ public class TimelineFragment extends SFragment implements
|
|||
} else {
|
||||
topId = CollectionsKt.first(statuses, Either::isRight).asRight().getId();
|
||||
}
|
||||
this.timelineRepo.getStatuses(topId, null, LOAD_AT_ONCE,
|
||||
this.timelineRepo.getStatuses(topId, null, null, LOAD_AT_ONCE,
|
||||
TimelineRequestMode.NETWORK)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||
|
@ -520,12 +520,22 @@ public class TimelineFragment extends SFragment implements
|
|||
}
|
||||
|
||||
private void loadAbove() {
|
||||
Either<Placeholder, Status> firstOrNull =
|
||||
CollectionsKt.firstOrNull(this.statuses, Either::isRight);
|
||||
String firstOrNull = null;
|
||||
String secondOrNull = null;
|
||||
for (int i = 0; i < this.statuses.size(); i++) {
|
||||
Either<Placeholder, Status> status = this.statuses.get(i);
|
||||
if (status.isRight()) {
|
||||
firstOrNull = status.asRight().getId();
|
||||
if (i + 1 < statuses.size() && statuses.get(i + 1).isRight()) {
|
||||
secondOrNull = statuses.get(i + 1).asRight().getId();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (firstOrNull != null) {
|
||||
this.sendFetchTimelineRequest(null, firstOrNull.asRight().getId(), FetchEnd.TOP, -1);
|
||||
this.sendFetchTimelineRequest(null, firstOrNull, secondOrNull, FetchEnd.TOP, -1);
|
||||
} else {
|
||||
this.sendFetchTimelineRequest(null, null, FetchEnd.BOTTOM, -1);
|
||||
this.sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -631,11 +641,16 @@ public class TimelineFragment extends SFragment implements
|
|||
if (statuses.size() >= position && position > 0) {
|
||||
Status fromStatus = statuses.get(position - 1).asRightOrNull();
|
||||
Status toStatus = statuses.get(position + 1).asRightOrNull();
|
||||
String maxMinusOne =
|
||||
statuses.size() > position + 1 && statuses.get(position + 2).isRight()
|
||||
? statuses.get(position + 1).asRight().getId()
|
||||
: null;
|
||||
if (fromStatus == null || toStatus == null) {
|
||||
Log.e(TAG, "Failed to load more at " + position + ", wrong placeholder position");
|
||||
return;
|
||||
}
|
||||
sendFetchTimelineRequest(fromStatus.getId(), toStatus.getId(), FetchEnd.MIDDLE, position);
|
||||
sendFetchTimelineRequest(fromStatus.getId(), toStatus.getId(), maxMinusOne,
|
||||
FetchEnd.MIDDLE, position);
|
||||
|
||||
Placeholder placeholder = statuses.get(position).asLeft();
|
||||
StatusViewData newViewData = new StatusViewData.Placeholder(placeholder.getId(), true);
|
||||
|
@ -810,14 +825,14 @@ public class TimelineFragment extends SFragment implements
|
|||
break;
|
||||
}
|
||||
}
|
||||
sendFetchTimelineRequest(bottomId, null, FetchEnd.BOTTOM, -1);
|
||||
sendFetchTimelineRequest(bottomId, null, null, FetchEnd.BOTTOM, -1);
|
||||
}
|
||||
|
||||
private void fullyRefresh() {
|
||||
statuses.clear();
|
||||
updateAdapter();
|
||||
bottomLoading = true;
|
||||
sendFetchTimelineRequest(null, null, FetchEnd.BOTTOM, -1);
|
||||
sendFetchTimelineRequest(null, null, null, FetchEnd.BOTTOM, -1);
|
||||
}
|
||||
|
||||
private boolean jumpToTopAllowed() {
|
||||
|
@ -861,7 +876,8 @@ public class TimelineFragment extends SFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
private void sendFetchTimelineRequest(@Nullable String fromId, @Nullable String uptoId,
|
||||
private void sendFetchTimelineRequest(@Nullable String maxId, @Nullable String sinceId,
|
||||
@Nullable String sinceIdMinusOne,
|
||||
final FetchEnd fetchEnd, final int pos) {
|
||||
if (kind == Kind.HOME) {
|
||||
TimelineRequestMode mode;
|
||||
|
@ -871,7 +887,7 @@ public class TimelineFragment extends SFragment implements
|
|||
} else {
|
||||
mode = TimelineRequestMode.NETWORK;
|
||||
}
|
||||
timelineRepo.getStatuses(fromId, uptoId, LOAD_AT_ONCE, mode)
|
||||
timelineRepo.getStatuses(maxId, sinceId, sinceIdMinusOne, LOAD_AT_ONCE, mode)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.as(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY)))
|
||||
.subscribe(
|
||||
|
@ -895,7 +911,7 @@ public class TimelineFragment extends SFragment implements
|
|||
}
|
||||
};
|
||||
|
||||
Call<List<Status>> listCall = getFetchCallByTimelineType(kind, hashtagOrId, fromId, uptoId);
|
||||
Call<List<Status>> listCall = getFetchCallByTimelineType(kind, hashtagOrId, maxId, sinceId);
|
||||
callList.add(listCall);
|
||||
listCall.enqueue(callback);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue