use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by tuskyapp.
the class NotificationsFragment method onFetchNotificationsFailure.
private void onFetchNotificationsFailure(Exception exception, FetchEnd fetchEnd, int position) {
swipeRefreshLayout.setRefreshing(false);
if (fetchEnd == FetchEnd.MIDDLE && !notifications.get(position).isRight()) {
NotificationViewData placeholderVD = new NotificationViewData.Placeholder(false);
notifications.setPairedItem(position, placeholderVD);
adapter.updateItemWithNotify(position, placeholderVD, true);
}
Log.e(TAG, "Fetch failure: " + exception.getMessage());
fulfillAnyQueuedFetches(fetchEnd);
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by tuskyapp.
the class NotificationsFragment method onContentHiddenChange.
@Override
public void onContentHiddenChange(boolean isShowing, int position) {
NotificationViewData.Concrete old = (NotificationViewData.Concrete) notifications.getPairedItem(position);
StatusViewData.Concrete statusViewData = new StatusViewData.Builder(old.getStatusViewData()).setIsShowingSensitiveContent(isShowing).createStatusViewData();
NotificationViewData notificationViewData = new NotificationViewData.Concrete(old.getType(), old.getId(), old.getAccount(), statusViewData, old.isExpanded());
notifications.setPairedItem(position, notificationViewData);
adapter.updateItemWithNotify(position, notificationViewData, false);
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by tuskyapp.
the class NotificationsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
if (position < notifications.size()) {
NotificationViewData notification = notifications.get(position);
if (notification instanceof NotificationViewData.Placeholder) {
NotificationViewData.Placeholder placeholder = ((NotificationViewData.Placeholder) notification);
PlaceholderViewHolder holder = (PlaceholderViewHolder) viewHolder;
holder.setup(!placeholder.isLoading(), statusListener);
return;
}
NotificationViewData.Concrete concreteNotificaton = (NotificationViewData.Concrete) notification;
Notification.Type type = concreteNotificaton.getType();
switch(type) {
case MENTION:
{
StatusViewHolder holder = (StatusViewHolder) viewHolder;
StatusViewData.Concrete status = concreteNotificaton.getStatusViewData();
holder.setupWithStatus(status, statusListener, mediaPreviewEnabled);
break;
}
case FAVOURITE:
case REBLOG:
{
StatusNotificationViewHolder holder = (StatusNotificationViewHolder) viewHolder;
StatusViewData.Concrete statusViewData = concreteNotificaton.getStatusViewData();
if (statusViewData == null) {
holder.showNotificationContent(false);
} else {
holder.showNotificationContent(true);
holder.setDisplayName(statusViewData.getUserFullName());
holder.setUsername(statusViewData.getNickname());
holder.setCreatedAt(statusViewData.getCreatedAt());
holder.setAvatars(concreteNotificaton.getStatusViewData().getAvatar(), concreteNotificaton.getAccount().getAvatar());
}
holder.setMessage(concreteNotificaton, statusListener);
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId(), concreteNotificaton.getId());
break;
}
case FOLLOW:
{
FollowViewHolder holder = (FollowViewHolder) viewHolder;
holder.setMessage(concreteNotificaton.getAccount().getName(), concreteNotificaton.getAccount().getUsername(), concreteNotificaton.getAccount().getAvatar());
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId());
break;
}
}
} else {
FooterViewHolder holder = (FooterViewHolder) viewHolder;
holder.setState(footerState);
}
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by Vavassor.
the class NotificationsFragment method updateStatus.
private void updateStatus(String statusId, Function<Status, Status> mapper) {
int index = CollectionsKt.indexOfFirst(this.notifications, (s) -> s.isRight() && s.asRight().getStatus() != null && s.asRight().getStatus().getId().equals(statusId));
if (index == -1)
return;
// We have quite some graph here:
//
// Notification --------> Status
// ^
// |
// StatusViewData
// ^
// |
// NotificationViewData -----+
//
// So if we have "new" status we need to update all references to be sure that data is
// up-to-date:
// 1. update status
// 2. update notification
// 3. update statusViewData
// 4. update notificationViewData
Status oldStatus = notifications.get(index).asRight().getStatus();
NotificationViewData.Concrete oldViewData = (NotificationViewData.Concrete) this.notifications.getPairedItem(index);
Status newStatus = mapper.apply(oldStatus);
Notification newNotification = this.notifications.get(index).asRight().copyWithStatus(newStatus);
StatusViewData.Concrete newStatusViewData = Objects.requireNonNull(oldViewData.getStatusViewData()).copyWithStatus(newStatus);
NotificationViewData.Concrete newViewData = oldViewData.copyWithStatus(newStatusViewData);
notifications.set(index, new Either.Right<>(newNotification));
notifications.setPairedItem(index, newViewData);
updateAdapter();
}
use of com.keylesspalace.tusky.viewdata.NotificationViewData in project Tusky by Vavassor.
the class NotificationsFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_timeline_notifications, container, false);
// from inflater to silence warning
@NonNull Context context = inflater.getContext();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
boolean showNotificationsFilterSetting = preferences.getBoolean("showNotificationsFilter", true);
// Clear notifications on filter visibility change to force refresh
if (showNotificationsFilterSetting != showNotificationsFilter)
notifications.clear();
showNotificationsFilter = showNotificationsFilterSetting;
// Setup the SwipeRefreshLayout.
swipeRefreshLayout = rootView.findViewById(R.id.swipeRefreshLayout);
recyclerView = rootView.findViewById(R.id.recyclerView);
progressBar = rootView.findViewById(R.id.progressBar);
statusView = rootView.findViewById(R.id.statusView);
appBarOptions = rootView.findViewById(R.id.appBarOptions);
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setColorSchemeResources(R.color.tusky_blue);
loadNotificationsFilter();
// Setup the RecyclerView.
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAccessibilityDelegateCompat(new ListStatusAccessibilityDelegate(recyclerView, this, (pos) -> {
NotificationViewData notification = notifications.getPairedItemOrNull(pos);
// We support replies only for now
if (notification instanceof NotificationViewData.Concrete) {
return ((NotificationViewData.Concrete) notification).getStatusViewData();
} else {
return null;
}
}));
recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
StatusDisplayOptions statusDisplayOptions = new StatusDisplayOptions(preferences.getBoolean("animateGifAvatars", false), accountManager.getActiveAccount().getMediaPreviewEnabled(), preferences.getBoolean("absoluteTimeView", false), preferences.getBoolean("showBotOverlay", true), preferences.getBoolean("useBlurhash", true), CardViewMode.NONE, preferences.getBoolean("confirmReblogs", true), preferences.getBoolean("confirmFavourites", false), preferences.getBoolean(PrefKeys.WELLBEING_HIDE_STATS_POSTS, false), preferences.getBoolean(PrefKeys.ANIMATE_CUSTOM_EMOJIS, false));
adapter = new NotificationsAdapter(accountManager.getActiveAccount().getAccountId(), dataSource, statusDisplayOptions, this, this, this);
alwaysShowSensitiveMedia = accountManager.getActiveAccount().getAlwaysShowSensitiveMedia();
alwaysOpenSpoiler = accountManager.getActiveAccount().getAlwaysOpenSpoiler();
recyclerView.setAdapter(adapter);
topLoading = false;
bottomLoading = false;
bottomId = null;
updateAdapter();
Button buttonClear = rootView.findViewById(R.id.buttonClear);
buttonClear.setOnClickListener(v -> confirmClearNotifications());
buttonFilter = rootView.findViewById(R.id.buttonFilter);
buttonFilter.setOnClickListener(v -> showFilterMenu());
if (notifications.isEmpty()) {
swipeRefreshLayout.setEnabled(false);
sendFetchNotificationsRequest(null, null, FetchEnd.BOTTOM, -1);
} else {
progressBar.setVisibility(View.GONE);
}
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
updateFilterVisibility();
return rootView;
}
Aggregations