Fix unnecessary reloading of notifications (#984)
This removes topId as it is not needed and just plainly uses status id if needed. During initial loading of notifications topId/bottomId are not set so we ended up reloading everything.
This commit is contained in:
parent
15af80c5a0
commit
fb83d086d1
1 changed files with 12 additions and 10 deletions
|
@ -77,6 +77,7 @@ import java.util.Objects;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
|
import kotlin.collections.CollectionsKt;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import retrofit2.Callback;
|
import retrofit2.Callback;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
@ -134,7 +135,6 @@ public class NotificationsFragment extends SFragment implements
|
||||||
private boolean topLoading;
|
private boolean topLoading;
|
||||||
private boolean bottomLoading;
|
private boolean bottomLoading;
|
||||||
private String bottomId;
|
private String bottomId;
|
||||||
private String topId;
|
|
||||||
private boolean alwaysShowSensitiveMedia;
|
private boolean alwaysShowSensitiveMedia;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,12 +206,11 @@ public class NotificationsFragment extends SFragment implements
|
||||||
topLoading = false;
|
topLoading = false;
|
||||||
bottomLoading = false;
|
bottomLoading = false;
|
||||||
bottomId = null;
|
bottomId = null;
|
||||||
topId = null;
|
|
||||||
|
|
||||||
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
|
||||||
setupNothingView();
|
setupNothingView();
|
||||||
|
|
||||||
sendFetchNotificationsRequest(null, topId, FetchEnd.BOTTOM, -1);
|
sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
@ -333,6 +332,13 @@ public class NotificationsFragment extends SFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
|
Either<Placeholder, Notification> first = CollectionsKt.firstOrNull(this.notifications);
|
||||||
|
String topId;
|
||||||
|
if (first != null && first.isRight()) {
|
||||||
|
topId = first.getAsRight().getId();
|
||||||
|
} else {
|
||||||
|
topId = null;
|
||||||
|
}
|
||||||
sendFetchNotificationsRequest(null, topId, FetchEnd.TOP, -1);
|
sendFetchNotificationsRequest(null, topId, FetchEnd.TOP, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,7 +682,7 @@ public class NotificationsFragment extends SFragment implements
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
uptoId = previous.uri.getQueryParameter("since_id");
|
uptoId = previous.uri.getQueryParameter("since_id");
|
||||||
}
|
}
|
||||||
update(notifications, null, uptoId);
|
update(notifications, null);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MIDDLE: {
|
case MIDDLE: {
|
||||||
|
@ -707,7 +713,7 @@ public class NotificationsFragment extends SFragment implements
|
||||||
if (previous != null) {
|
if (previous != null) {
|
||||||
uptoId = previous.uri.getQueryParameter("since_id");
|
uptoId = previous.uri.getQueryParameter("since_id");
|
||||||
}
|
}
|
||||||
update(notifications, fromId, uptoId);
|
update(notifications, fromId);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -770,17 +776,13 @@ public class NotificationsFragment extends SFragment implements
|
||||||
return lastShownNotificationId.compareTo(newId) < 0;
|
return lastShownNotificationId.compareTo(newId) < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(@Nullable List<Notification> newNotifications, @Nullable String fromId,
|
private void update(@Nullable List<Notification> newNotifications, @Nullable String fromId) {
|
||||||
@Nullable String uptoId) {
|
|
||||||
if (ListUtils.isEmpty(newNotifications)) {
|
if (ListUtils.isEmpty(newNotifications)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fromId != null) {
|
if (fromId != null) {
|
||||||
bottomId = fromId;
|
bottomId = fromId;
|
||||||
}
|
}
|
||||||
if (uptoId != null) {
|
|
||||||
topId = uptoId;
|
|
||||||
}
|
|
||||||
List<Either<Placeholder, Notification>> liftedNew =
|
List<Either<Placeholder, Notification>> liftedNew =
|
||||||
liftNotificationList(newNotifications);
|
liftNotificationList(newNotifications);
|
||||||
if (notifications.isEmpty()) {
|
if (notifications.isEmpty()) {
|
||||||
|
|
Loading…
Reference in a new issue