use of com.odysee.app.adapter.NotificationListAdapter in project odysee-android by OdyseeTeam.
the class MainActivity method updateLocalNotifications.
private void updateLocalNotifications(List<LbryNotification> notifications) {
findViewById(R.id.notification_list_empty_container).setVisibility(notifications.isEmpty() ? View.VISIBLE : View.GONE);
findViewById(R.id.notifications_progress).setVisibility(View.GONE);
loadUnseenNotificationsCount();
if (notificationListAdapter == null) {
notificationListAdapter = new NotificationListAdapter(notifications, MainActivity.this);
notificationListAdapter.setSelectionModeListener(MainActivity.this);
((RecyclerView) findViewById(R.id.notifications_list)).setAdapter(notificationListAdapter);
} else {
notificationListAdapter.addNotifications(notifications);
}
resolveCommentAuthors(notificationListAdapter.getAuthorUrls());
notificationListAdapter.setClickListener(new NotificationListAdapter.NotificationClickListener() {
@Override
public void onNotificationClicked(LbryNotification notification) {
// set as seen and read
Map<String, String> options = new HashMap<>();
options.put("notification_ids", String.valueOf(notification.getRemoteId()));
options.put("is_seen", "true");
// so let's not mark the notification as read
if (!notification.getTargetUrl().equalsIgnoreCase("lbry://?subscriptions")) {
options.put("is_read", "true");
} else {
options.put("is_read", "false");
}
AccountManager am = AccountManager.get(getApplicationContext());
if (am != null) {
String at = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
if (at != null)
options.put("auth_token", at);
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Supplier<Boolean> supplier = new NotificationUpdateSupplier(options);
CompletableFuture.supplyAsync(supplier);
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("notification", "edit", options, null);
} catch (LbryioResponseException | LbryioRequestException e) {
e.printStackTrace();
}
}
});
t.start();
}
if (!notification.getTargetUrl().equalsIgnoreCase("lbry://?subscriptions")) {
markNotificationReadAndSeen(notification.getId());
}
String targetUrl = notification.getTargetUrl();
if (targetUrl.startsWith(SPECIAL_URL_PREFIX)) {
openSpecialUrl(targetUrl, "notification");
} else {
LbryUri target = LbryUri.tryParse(notification.getTargetUrl());
if (target != null) {
if (target.isChannel()) {
openChannelUrl(notification.getTargetUrl(), "notification");
} else {
openFileUrl(notification.getTargetUrl(), "notification");
}
}
}
hideNotifications(false);
}
});
}
Aggregations