use of com.keylesspalace.tusky.viewdata.NotificationViewData 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.viewdata.NotificationViewData in project Tusky by Vavassor.
the class NotificationsAdapter method bindViewHolder.
private void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @Nullable List payloads) {
Object payloadForHolder = payloads != null && !payloads.isEmpty() ? payloads.get(0) : null;
if (position < this.dataSource.getItemCount()) {
NotificationViewData notification = dataSource.getItemAt(position);
if (notification instanceof NotificationViewData.Placeholder) {
if (payloadForHolder == null) {
NotificationViewData.Placeholder placeholder = ((NotificationViewData.Placeholder) notification);
PlaceholderViewHolder holder = (PlaceholderViewHolder) viewHolder;
holder.setup(statusListener, placeholder.isLoading());
}
return;
}
NotificationViewData.Concrete concreteNotificaton = (NotificationViewData.Concrete) notification;
switch(viewHolder.getItemViewType()) {
case VIEW_TYPE_STATUS:
{
StatusViewHolder holder = (StatusViewHolder) viewHolder;
StatusViewData.Concrete status = concreteNotificaton.getStatusViewData();
holder.setupWithStatus(status, statusListener, statusDisplayOptions, payloadForHolder);
if (concreteNotificaton.getType() == Notification.Type.POLL) {
holder.setPollInfo(accountId.equals(concreteNotificaton.getAccount().getId()));
} else {
holder.hideStatusInfo();
}
break;
}
case VIEW_TYPE_STATUS_NOTIFICATION:
{
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
StatusViewData.Concrete statusViewData = concreteNotificaton.getStatusViewData();
if (payloadForHolder == null) {
if (statusViewData == null) {
holder.showNotificationContent(false);
} else {
holder.showNotificationContent(true);
Status status = statusViewData.getActionable();
holder.setDisplayName(status.getAccount().getDisplayName(), status.getAccount().getEmojis());
holder.setUsername(status.getAccount().getUsername());
holder.setCreatedAt(status.getCreatedAt());
if (concreteNotificaton.getType() == Notification.Type.STATUS) {
holder.setAvatar(status.getAccount().getAvatar(), status.getAccount().getBot());
} else {
holder.setAvatars(status.getAccount().getAvatar(), concreteNotificaton.getAccount().getAvatar());
}
}
holder.setMessage(concreteNotificaton, statusListener);
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId(), concreteNotificaton.getId());
} else {
if (payloadForHolder instanceof List)
for (Object item : (List) payloadForHolder) {
if (StatusBaseViewHolder.Key.KEY_CREATED.equals(item) && statusViewData != null) {
holder.setCreatedAt(statusViewData.getStatus().getActionableStatus().getCreatedAt());
}
}
}
break;
}
case VIEW_TYPE_FOLLOW:
{
if (payloadForHolder == null) {
FollowViewHolder holder = (FollowViewHolder) viewHolder;
holder.setMessage(concreteNotificaton.getAccount());
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId());
}
break;
}
case VIEW_TYPE_FOLLOW_REQUEST:
{
if (payloadForHolder == null) {
FollowRequestViewHolder holder = (FollowRequestViewHolder) viewHolder;
holder.setupWithAccount(concreteNotificaton.getAccount(), statusDisplayOptions.animateAvatars(), statusDisplayOptions.animateEmojis());
holder.setupActionListener(accountActionListener, concreteNotificaton.getAccount().getId());
}
break;
}
default:
}
}
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by tuskyapp.
the class NotificationsFragment method onExpandedChange.
@Override
public void onExpandedChange(boolean expanded, int position) {
NotificationViewData.Concrete old = (NotificationViewData.Concrete) notifications.getPairedItem(position);
StatusViewData.Concrete statusViewData = new StatusViewData.Builder(old.getStatusViewData()).setIsExpanded(expanded).createStatusViewData();
NotificationViewData notificationViewData = new NotificationViewData.Concrete(old.getType(), old.getId(), old.getAccount(), statusViewData, expanded);
notifications.setPairedItem(position, notificationViewData);
adapter.updateItemWithNotify(position, notificationViewData, false);
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by tuskyapp.
the class NotificationsFragment method onLoadMore.
@Override
public void onLoadMore(int position) {
// check bounds before accessing list,
if (notifications.size() >= position && position > 0) {
Notification previous = notifications.get(position - 1).getAsRightOrNull();
Notification next = notifications.get(position + 1).getAsRightOrNull();
if (previous == null || next == null) {
Log.e(TAG, "Failed to load more, invalid placeholder position: " + position);
return;
}
sendFetchNotificationsRequest(previous.getId(), next.getId(), FetchEnd.MIDDLE, position);
NotificationViewData notificationViewData = new NotificationViewData.Placeholder(true);
notifications.setPairedItem(position, notificationViewData);
adapter.updateItemWithNotify(position, notificationViewData, false);
} else {
Log.d(TAG, "error loading more");
}
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by Vavassor.
the class NotificationsFragment method updateViewDataAt.
private void updateViewDataAt(int position, Function<StatusViewData.Concrete, StatusViewData.Concrete> mapper) {
if (position < 0 || position >= notifications.size()) {
String message = String.format(Locale.getDefault(), "Tried to access out of bounds status position: %d of %d", position, notifications.size() - 1);
Log.e(TAG, message);
return;
}
NotificationViewData someViewData = this.notifications.getPairedItem(position);
if (!(someViewData instanceof NotificationViewData.Concrete)) {
return;
}
NotificationViewData.Concrete oldViewData = (NotificationViewData.Concrete) someViewData;
StatusViewData.Concrete oldStatusViewData = oldViewData.getStatusViewData();
if (oldStatusViewData == null)
return;
NotificationViewData.Concrete newViewData = oldViewData.copyWithStatus(mapper.apply(oldStatusViewData));
notifications.setPairedItem(position, newViewData);
updateAdapter();
}
Aggregations