use of com.keylesspalace.tusky.entity.Notification in project Tusky by Vavassor.
the class NotificationsFragment method onViewThread.
@Override
public void onViewThread(int position) {
Notification notification = notifications.get(position).asRight();
Status status = notification.getStatus();
if (status == null)
return;
;
super.viewThread(status.getActionableId(), status.getActionableStatus().getUrl());
}
use of com.keylesspalace.tusky.entity.Notification 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;
}
use of com.keylesspalace.tusky.entity.Notification in project Tusky by Vavassor.
the class NotificationsFragment method onVoteInPoll.
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
final Notification notification = notifications.get(position).asRight();
final Status status = notification.getStatus().getActionableStatus();
timelineCases.voteInPoll(status.getId(), status.getPoll().getId(), choices).observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this))).subscribe((newPoll) -> setVoteForPoll(status, newPoll), (t) -> Log.d(TAG, "Failed to vote in poll: " + status.getId(), t));
}
use of com.keylesspalace.tusky.entity.Notification 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.entity.Notification in project Tusky by Vavassor.
the class NotificationsFragment method saveNewestNotificationId.
private void saveNewestNotificationId(List<Notification> notifications) {
AccountEntity account = accountManager.getActiveAccount();
if (account != null) {
String lastNotificationId = account.getLastNotificationId();
for (Notification noti : notifications) {
if (isLessThan(lastNotificationId, noti.getId())) {
lastNotificationId = noti.getId();
}
}
if (!account.getLastNotificationId().equals(lastNotificationId)) {
Log.d(TAG, "saving newest noti id: " + lastNotificationId);
account.setLastNotificationId(lastNotificationId);
accountManager.saveAccount(account);
}
}
}
Aggregations