use of com.keylesspalace.tusky.util.Either in project Tusky by tuskyapp.
the class TimelineFragment method replacePlaceholderWithStatuses.
private void replacePlaceholderWithStatuses(List<Status> newStatuses, boolean fullFetch, int pos) {
Status status = statuses.get(pos).getAsRightOrNull();
if (status == null) {
statuses.remove(pos);
}
if (ListUtils.isEmpty(newStatuses)) {
adapter.update(statuses.getPairedCopy());
return;
}
List<Either<Placeholder, Status>> liftedNew = listStatusList(newStatuses);
if (fullFetch) {
liftedNew.add(Either.left(Placeholder.getInstance()));
}
statuses.addAll(pos, liftedNew);
adapter.update(statuses.getPairedCopy());
}
use of com.keylesspalace.tusky.util.Either in project Tusky by tuskyapp.
the class TimelineFragment method removeAllByAccountId.
@Override
public void removeAllByAccountId(String accountId) {
// using iterator to safely remove items while iterating
Iterator<Either<Placeholder, Status>> iterator = statuses.iterator();
while (iterator.hasNext()) {
Status status = iterator.next().getAsRightOrNull();
if (status != null && status.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
adapter.update(statuses.getPairedCopy());
}
use of com.keylesspalace.tusky.util.Either in project Tusky by tuskyapp.
the class NotificationsFragment method removeAllByAccountId.
@Override
public void removeAllByAccountId(String accountId) {
// using iterator to safely remove items while iterating
Iterator<Either<Placeholder, Notification>> iterator = notifications.iterator();
while (iterator.hasNext()) {
Either<Placeholder, Notification> notification = iterator.next();
Notification maybeNotification = notification.getAsRightOrNull();
if (maybeNotification != null && maybeNotification.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
adapter.update(notifications.getPairedCopy());
}
use of com.keylesspalace.tusky.util.Either in project Tusky by Vavassor.
the class NotificationsFragment method onLoadMore.
private void onLoadMore() {
if (bottomId == null) {
// already loaded everything
return;
}
// change.
if (notifications.size() > 0) {
Either<Placeholder, Notification> last = notifications.get(notifications.size() - 1);
if (last.isRight()) {
final Placeholder placeholder = newPlaceholder();
notifications.add(new Either.Left<>(placeholder));
NotificationViewData viewData = new NotificationViewData.Placeholder(placeholder.id, true);
notifications.setPairedItem(notifications.size() - 1, viewData);
updateAdapter();
}
}
sendFetchNotificationsRequest(bottomId, null, FetchEnd.BOTTOM, -1);
}
use of com.keylesspalace.tusky.util.Either in project Tusky by Vavassor.
the class NotificationsFragment method removeAllByAccountId.
private void removeAllByAccountId(String accountId) {
// using iterator to safely remove items while iterating
Iterator<Either<Placeholder, Notification>> iterator = notifications.iterator();
while (iterator.hasNext()) {
Either<Placeholder, Notification> notification = iterator.next();
Notification maybeNotification = notification.asRightOrNull();
if (maybeNotification != null && maybeNotification.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
updateAdapter();
}
Aggregations