Search in sources :

Example 1 with Either

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());
}
Also used : Status(com.keylesspalace.tusky.entity.Status) Either(com.keylesspalace.tusky.util.Either)

Example 2 with Either

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());
}
Also used : Status(com.keylesspalace.tusky.entity.Status) Either(com.keylesspalace.tusky.util.Either)

Example 3 with Either

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());
}
Also used : Either(com.keylesspalace.tusky.util.Either) Notification(com.keylesspalace.tusky.entity.Notification)

Example 4 with Either

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);
}
Also used : Either(com.keylesspalace.tusky.util.Either) NotificationViewData(com.keylesspalace.tusky.viewdata.NotificationViewData) Notification(com.keylesspalace.tusky.entity.Notification)

Example 5 with Either

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();
}
Also used : Either(com.keylesspalace.tusky.util.Either) Notification(com.keylesspalace.tusky.entity.Notification)

Aggregations

Either (com.keylesspalace.tusky.util.Either)5 Notification (com.keylesspalace.tusky.entity.Notification)3 Status (com.keylesspalace.tusky.entity.Status)2 NotificationViewData (com.keylesspalace.tusky.viewdata.NotificationViewData)1