Search in sources :

Example 1 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class WalletFragment method fetchRecentTransactions.

private void fetchRecentTransactions(boolean forceFetch) {
    if (!Helper.isSignedIn(getContext())) {
        return;
    }
    if (hasFetchedRecentTransactions && !forceFetch) {
        return;
    }
    Helper.setViewVisibility(textNoRecentTransactions, View.GONE);
    AccountManager am = AccountManager.get(getContext());
    Account[] accounts = am.getAccounts();
    TransactionListTask task = new TransactionListTask(1, 5, am.peekAuthToken(Helper.getOdyseeAccount(accounts), "auth_token_type"), loadingRecentContainer, new TransactionListTask.TransactionListHandler() {

        @Override
        public void onSuccess(List<Transaction> transactions, boolean hasReachedEnd) {
            hasFetchedRecentTransactions = true;
            recentTransactionsAdapter = new TransactionListAdapter(transactions, getContext());
            recentTransactionsAdapter.setListener(new TransactionListAdapter.TransactionClickListener() {

                @Override
                public void onTransactionClicked(Transaction transaction) {
                }

                @Override
                public void onClaimUrlClicked(LbryUri uri) {
                    Context context = getContext();
                    if (uri != null && context instanceof MainActivity) {
                        MainActivity activity = (MainActivity) context;
                        if (uri.isChannel()) {
                            activity.openChannelUrl(uri.toString());
                        } else {
                            activity.openFileUrl(uri.toString());
                        }
                    }
                }
            });
            recentTransactionsList.setAdapter(recentTransactionsAdapter);
            displayNoRecentTransactions();
        }

        @Override
        public void onError(Exception error) {
            hasFetchedRecentTransactions = true;
            displayNoRecentTransactions();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) Account(android.accounts.Account) TransactionListTask(com.odysee.app.tasks.wallet.TransactionListTask) MainActivity(com.odysee.app.MainActivity) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ApiCallException(com.odysee.app.exceptions.ApiCallException) ExecutionException(java.util.concurrent.ExecutionException) Transaction(com.odysee.app.model.Transaction) AccountManager(android.accounts.AccountManager) LbryUri(com.odysee.app.utils.LbryUri) TransactionListAdapter(com.odysee.app.adapter.TransactionListAdapter)

Example 2 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class MainActivity method checkUrlIntent.

private void checkUrlIntent(Intent intent) {
    if (intent != null) {
        Uri data = intent.getData();
        if (data != null) {
            String url = data.toString();
            // check special urls
            if (url.startsWith(SPECIAL_URL_PREFIX)) {
                String specialPath = url.substring(8).toLowerCase();
                if (specialRouteFragmentClassMap.containsKey(specialPath)) {
                    Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
                    if (fragmentClassNavIdMap.containsKey(fragmentClass)) {
                        Map<String, Object> params = new HashMap<>();
                        String tag = intent.getStringExtra("tag");
                        params.put("singleTag", tag);
                    // openFragment(specialRouteFragmentClassMap.get(specialPath), true, fragmentClassNavIdMap.get(fragmentClass), !Helper.isNullOrEmpty(tag) ? params : null);
                    }
                }
            // unrecognised path will open the following by default
            } else {
                try {
                    LbryUri uri = LbryUri.parse(url);
                    String checkedURL = url.startsWith(LbryUri.PROTO_DEFAULT) ? url : uri.toString();
                    if (uri.isChannel()) {
                        openChannelUrl(checkedURL);
                    } else {
                        openFileUrl(checkedURL);
                    }
                } catch (LbryUriException ex) {
                // pass
                }
            }
            inPictureInPictureMode = false;
            renderFullMode();
        }
    }
}
Also used : LbryUriException(com.odysee.app.exceptions.LbryUriException) HashMap(java.util.HashMap) JSONObject(org.json.JSONObject) SpannableString(android.text.SpannableString) LbryUri(com.odysee.app.utils.LbryUri) LbryUri(com.odysee.app.utils.LbryUri) Uri(android.net.Uri)

Example 3 with LbryUri

use of com.odysee.app.utils.LbryUri 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)

Example 4 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class ClaimListAdapter method onBindViewHolder.

@SuppressLint("UseCompatLoadingForDrawables")
@Override
public void onBindViewHolder(ClaimListAdapter.ViewHolder vh, int position) {
    int type = getItemViewType(position);
    if (style == STYLE_SMALL_LIST) {
        int paddingTop = position == 0 ? 16 : 8;
        int paddingBottom = position == getItemCount() - 1 ? 16 : 8;
        int paddingTopScaled = Helper.getScaledValue(paddingTop, scale);
        int paddingBottomScaled = Helper.getScaledValue(paddingBottom, scale);
        vh.itemView.setPadding(vh.itemView.getPaddingStart(), paddingTopScaled, vh.itemView.getPaddingEnd(), paddingBottomScaled);
    } else if (style == STYLE_SMALL_LIST_HORIZONTAL) {
        int paddingStart = position == 0 ? 16 : 8;
        int paddingEnd = position == getItemCount() - 1 ? 16 : 8;
        int paddingStartScaled = Helper.getScaledValue(paddingStart, scale);
        int paddingEndScaled = Helper.getScaledValue(paddingEnd, scale);
        vh.itemView.setPadding(paddingStartScaled, vh.itemView.getPaddingTop(), paddingEndScaled, vh.itemView.getPaddingBottom());
    }
    Claim original = items.get(position);
    boolean isRepost = Claim.TYPE_REPOST.equalsIgnoreCase(original.getValueType());
    final Claim item = Claim.TYPE_REPOST.equalsIgnoreCase(original.getValueType()) ? (original.getRepostedClaim() != null ? original.getRepostedClaim() : original) : original;
    Claim.GenericMetadata metadata = item.getValue();
    Claim signingChannel = item.getSigningChannel();
    Claim.StreamMetadata streamMetadata = null;
    if (metadata instanceof Claim.StreamMetadata) {
        streamMetadata = (Claim.StreamMetadata) metadata;
    }
    String thumbnailUrl = item.getThumbnailUrl(vh.thumbnailView.getLayoutParams().width, vh.thumbnailView.getLayoutParams().height, 85);
    long publishTime = (streamMetadata != null && streamMetadata.getReleaseTime() > 0) ? streamMetadata.getReleaseTime() * 1000 : item.getTimestamp() * 1000;
    int bgColor = Helper.generateRandomColorForValue(item.getClaimId());
    if (bgColor == 0) {
        bgColor = Helper.generateRandomColorForValue(item.getName());
    }
    boolean isPending = item.getConfirmations() == 0;
    boolean isSelected = isClaimSelected(original);
    vh.itemView.setSelected(isSelected);
    vh.setContextGroupId(contextGroupId);
    vh.selectedOverlayView.setVisibility(isSelected ? View.VISIBLE : View.GONE);
    vh.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (isPending) {
                Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
                TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
                snackbarText.setMaxLines(5);
                snackbar.show();
                return;
            }
            if (inSelectionMode) {
                toggleSelectedClaim(original);
            } else {
                if (listener != null) {
                    listener.onClaimClicked(item, position);
                }
            }
        }
    });
    vh.itemView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            if (!canEnterSelectionMode) {
                return false;
            }
            if (isPending) {
                Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
                TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
                snackbarText.setMaxLines(5);
                snackbar.show();
                return false;
            }
            if (!inSelectionMode) {
                inSelectionMode = true;
                if (selectionModeListener != null) {
                    selectionModeListener.onEnterSelectionMode();
                }
            }
            toggleSelectedClaim(original);
            return true;
        }
    });
    vh.publisherView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null && signingChannel != null) {
                listener.onClaimClicked(signingChannel, position);
            }
        }
    });
    vh.publishTimeView.setVisibility(!isPending && style != STYLE_SMALL_LIST_HORIZONTAL ? View.VISIBLE : View.GONE);
    vh.pendingTextView.setVisibility(isPending && !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    vh.repostInfoView.setVisibility(isRepost && type != VIEW_TYPE_FEATURED ? View.VISIBLE : View.GONE);
    vh.repostChannelView.setText(isRepost && original.getSigningChannel() != null ? original.getSigningChannel().getName() : null);
    vh.repostChannelView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null) {
                listener.onClaimClicked(original.getSigningChannel(), position);
            }
        }
    });
    if (vh.optionsMenuView != null) {
        vh.optionsMenuView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                setPosition(vh.getBindingAdapterPosition());
                view.showContextMenu();
            }
        });
    }
    vh.titleView.setText(Helper.isNullOrEmpty(item.getTitle()) ? item.getName() : item.getTitle());
    if (type == VIEW_TYPE_FEATURED) {
        LbryUri vanityUrl = new LbryUri();
        vanityUrl.setClaimName(item.getName());
        vh.vanityUrlView.setText(vanityUrl.toString());
    }
    vh.feeContainer.setVisibility(item.isUnresolved() || !Claim.TYPE_STREAM.equalsIgnoreCase(item.getValueType()) ? View.GONE : View.VISIBLE);
    vh.noThumbnailView.setVisibility(Helper.isNullOrEmpty(thumbnailUrl) ? View.VISIBLE : View.GONE);
    Helper.setIconViewBackgroundColor(vh.noThumbnailView, bgColor, false, context);
    Helper.setViewVisibility(vh.loadingImagePlaceholder, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    Helper.setViewVisibility(vh.loadingTextPlaceholder1, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    Helper.setViewVisibility(vh.loadingTextPlaceholder2, item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    Helper.setViewVisibility(vh.titleView, !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    Helper.setViewVisibility(vh.publisherView, !item.isLoadingPlaceholder() ? View.VISIBLE : View.GONE);
    Helper.setViewVisibility(vh.publishTimeView, !item.isLoadingPlaceholder() && !isPending && style != STYLE_SMALL_LIST_HORIZONTAL ? View.VISIBLE : View.GONE);
    if (type == VIEW_TYPE_FEATURED && item.isUnresolved()) {
        vh.durationView.setVisibility(View.GONE);
        vh.titleView.setText("Nothing here. Publish something!");
        String name = item.getName();
        if (!Helper.isNullOrEmpty(name)) {
            vh.alphaView.setText(name.substring(0, Math.min(5, name.length() - 1)));
        }
    } else {
        ViewGroup.LayoutParams lp = vh.itemView.getLayoutParams();
        if (Claim.TYPE_STREAM.equalsIgnoreCase(item.getValueType()) || Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
            if ((filterTimeframeFrom == 0 || publishTime >= filterTimeframeFrom) && shouldDisplayClaim(item)) {
                if (!Helper.isNullOrEmpty(thumbnailUrl)) {
                    Glide.with(context.getApplicationContext()).asBitmap().load(thumbnailUrl).placeholder(R.drawable.bg_thumbnail_placeholder).into(vh.thumbnailView);
                    vh.thumbnailView.setVisibility(View.VISIBLE);
                } else {
                    vh.thumbnailView.setVisibility(View.GONE);
                }
                BigDecimal cost = item.getActualCost(Lbryio.LBCUSDRate);
                vh.feeContainer.setVisibility(cost.doubleValue() > 0 && !hideFee ? View.VISIBLE : View.GONE);
                vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.doubleValue()) : "Paid");
                vh.alphaView.setText(item.getName().substring(0, Math.min(5, item.getName().length() - 1)));
                vh.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous));
                vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
                long duration = item.getDuration();
                vh.durationView.setVisibility((duration > 0 || item.isLive() || Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) ? View.VISIBLE : View.GONE);
                if (item.isLive() && !Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
                    vh.durationView.setBackgroundColor(ContextCompat.getColor(context, R.color.colorAccent));
                    vh.durationView.setText(context.getResources().getString(R.string.live).toUpperCase());
                } else {
                    vh.durationView.setBackgroundColor(ContextCompat.getColor(context, android.R.color.black));
                    if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(item.getValueType())) {
                        vh.durationView.setText(Helper.formatDuration(duration));
                        vh.durationView.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
                    } else {
                        List<String> claimIds = item.getClaimIds() == null ? new ArrayList<>() : item.getClaimIds();
                        vh.durationView.setText(String.valueOf(claimIds.size()));
                        vh.durationView.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_list_icon, 0, 0, 0);
                        vh.durationView.setCompoundDrawablePadding(8);
                    }
                    LbryFile claimFile = item.getFile();
                    boolean isDownloading = false;
                    int progress = 0;
                    String fileSizeString = claimFile == null ? null : Helper.formatBytes(claimFile.getTotalBytes(), false);
                    if (claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) && !claimFile.isCompleted() && claimFile.getWrittenBytes() < claimFile.getTotalBytes()) {
                        isDownloading = true;
                        progress = claimFile.getTotalBytes() > 0 ? Double.valueOf(((double) claimFile.getWrittenBytes() / (double) claimFile.getTotalBytes()) * 100.0).intValue() : 0;
                        fileSizeString = String.format("%s / %s", Helper.formatBytes(claimFile.getWrittenBytes(), false), Helper.formatBytes(claimFile.getTotalBytes(), false));
                    }
                    Helper.setViewText(vh.fileSizeView, claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) ? fileSizeString : null);
                    Helper.setViewVisibility(vh.downloadProgressView, isDownloading ? View.VISIBLE : View.INVISIBLE);
                    Helper.setViewProgress(vh.downloadProgressView, progress);
                    Helper.setViewText(vh.deviceView, item.getDevice());
                    lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                    vh.itemView.setLayoutParams(lp);
                    vh.itemView.setVisibility(View.VISIBLE);
                    if (style != STYLE_SMALL_LIST_HORIZONTAL) {
                        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
                    }
                }
            } else {
                vh.itemView.setVisibility(View.GONE);
                lp.height = 0;
                lp.width = 0;
                vh.itemView.setLayoutParams(lp);
            }
        } else if (Claim.TYPE_CHANNEL.equalsIgnoreCase(item.getValueType())) {
            if ((this.filterByChannel || !this.filterByFile) && (filterTimeframeFrom == 0 || publishTime >= filterTimeframeFrom)) {
                if (!Helper.isNullOrEmpty(thumbnailUrl)) {
                    Glide.with(context.getApplicationContext()).load(thumbnailUrl).centerCrop().placeholder(R.drawable.bg_thumbnail_placeholder).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
                }
                vh.alphaView.setText(item.getName().substring(1, 2).toUpperCase());
                vh.publisherView.setText(item.getName());
                vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
                lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
                lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
                vh.itemView.setLayoutParams(lp);
                vh.itemView.setVisibility(View.VISIBLE);
            } else {
                vh.itemView.setVisibility(View.GONE);
                lp.height = 0;
                lp.width = 0;
                vh.itemView.setLayoutParams(lp);
            }
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) BigDecimal(java.math.BigDecimal) LbryFile(com.odysee.app.model.LbryFile) TextView(android.widget.TextView) LbryUri(com.odysee.app.utils.LbryUri) Claim(com.odysee.app.model.Claim) Snackbar(com.google.android.material.snackbar.Snackbar) SuppressLint(android.annotation.SuppressLint)

Example 5 with LbryUri

use of com.odysee.app.utils.LbryUri in project odysee-android by OdyseeTeam.

the class CommentListAdapter method filterBlockedChannels.

public void filterBlockedChannels(List<LbryUri> blockedChannels) {
    if (blockedChannels.size() == 0) {
        return;
    }
    List<Comment> commentsToRemove = new ArrayList<>();
    List<String> blockedChannelClaimIds = new ArrayList<>();
    for (LbryUri uri : blockedChannels) {
        blockedChannelClaimIds.add(uri.getClaimId());
    }
    for (Comment comment : items) {
        if (comment.getPoster() != null && blockedChannelClaimIds.contains(comment.getPoster().getClaimId())) {
            commentsToRemove.add(comment);
        }
    }
    items.removeAll(commentsToRemove);
    notifyDataSetChanged();
}
Also used : Comment(com.odysee.app.model.Comment) ArrayList(java.util.ArrayList) LbryUri(com.odysee.app.utils.LbryUri)

Aggregations

LbryUri (com.odysee.app.utils.LbryUri)30 LbryUriException (com.odysee.app.exceptions.LbryUriException)10 ArrayList (java.util.ArrayList)10 JSONException (org.json.JSONException)9 Subscription (com.odysee.app.model.lbryinc.Subscription)8 ApiCallException (com.odysee.app.exceptions.ApiCallException)7 Claim (com.odysee.app.model.Claim)7 JSONObject (org.json.JSONObject)7 SQLiteException (android.database.sqlite.SQLiteException)6 MainActivity (com.odysee.app.MainActivity)6 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)6 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)6 ExecutionException (java.util.concurrent.ExecutionException)6 SuppressLint (android.annotation.SuppressLint)4 Context (android.content.Context)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Tag (com.odysee.app.model.Tag)4 HashMap (java.util.HashMap)4 AccountManager (android.accounts.AccountManager)3 View (android.view.View)3