use of com.odysee.app.supplier.NotificationUpdateSupplier 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);
}
});
}
use of com.odysee.app.supplier.NotificationUpdateSupplier in project odysee-android by OdyseeTeam.
the class MainActivity method markNotificationsSeen.
private void markNotificationsSeen() {
List<LbryNotification> all = notificationListAdapter != null ? notificationListAdapter.getItems() : null;
if (all != null) {
List<Long> unseenIds = new ArrayList<>();
for (LbryNotification notification : all) {
if (!notification.isSeen() && notification.getRemoteId() > 0) {
unseenIds.add(notification.getRemoteId());
}
}
if (!unseenIds.isEmpty()) {
AccountManager am = AccountManager.get(this);
Map<String, String> options = new HashMap<>();
options.put("notification_ids", Helper.joinL(unseenIds, ","));
options.put("is_seen", "true");
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) {
ExecutorService executorService = Executors.newSingleThreadExecutor();
Supplier<Boolean> task = new NotificationUpdateSupplier(options);
CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(task, executorService);
cf.thenAcceptAsync(result -> {
if (result) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
DatabaseHelper.markNotificationsSeen(db);
loadUnseenNotificationsCount();
}
}, executorService);
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("notification", "edit", options, null);
SQLiteDatabase db = dbHelper.getWritableDatabase();
DatabaseHelper.markNotificationsSeen(db);
db.close();
loadUnseenNotificationsCount();
} catch (LbryioRequestException | LbryioResponseException e) {
e.printStackTrace();
}
}
});
t.start();
}
}
}
}
Aggregations