Search in sources :

Example 1 with NotificationListAdapter

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);
        }
    });
}
Also used : LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) SpannableString(android.text.SpannableString) LbryNotification(com.odysee.app.model.lbryinc.LbryNotification) NotificationUpdateSupplier(com.odysee.app.supplier.NotificationUpdateSupplier) NotificationListAdapter(com.odysee.app.adapter.NotificationListAdapter) RecyclerView(androidx.recyclerview.widget.RecyclerView) AccountManager(android.accounts.AccountManager) Supplier(java.util.function.Supplier) FetchRewardsSupplier(com.odysee.app.supplier.FetchRewardsSupplier) GetLocalNotificationsSupplier(com.odysee.app.supplier.GetLocalNotificationsSupplier) NotificationListSupplier(com.odysee.app.supplier.NotificationListSupplier) NotificationUpdateSupplier(com.odysee.app.supplier.NotificationUpdateSupplier) UnlockingTipsSupplier(com.odysee.app.supplier.UnlockingTipsSupplier) LbryUri(com.odysee.app.utils.LbryUri) Map(java.util.Map) HashMap(java.util.HashMap) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException)

Aggregations

AccountManager (android.accounts.AccountManager)1 SpannableString (android.text.SpannableString)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 NotificationListAdapter (com.odysee.app.adapter.NotificationListAdapter)1 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)1 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)1 LbryNotification (com.odysee.app.model.lbryinc.LbryNotification)1 FetchRewardsSupplier (com.odysee.app.supplier.FetchRewardsSupplier)1 GetLocalNotificationsSupplier (com.odysee.app.supplier.GetLocalNotificationsSupplier)1 NotificationListSupplier (com.odysee.app.supplier.NotificationListSupplier)1 NotificationUpdateSupplier (com.odysee.app.supplier.NotificationUpdateSupplier)1 UnlockingTipsSupplier (com.odysee.app.supplier.UnlockingTipsSupplier)1 LbryUri (com.odysee.app.utils.LbryUri)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1