Search in sources :

Example 1 with Fee

use of com.odysee.app.model.Fee in project odysee-android by OdyseeTeam.

the class PublishFormFragment method updateFieldsFromCurrentClaim.

private void updateFieldsFromCurrentClaim() {
    if (currentClaim != null && !editFieldsLoaded) {
        Context context = getContext();
        try {
            Claim.StreamMetadata metadata = (Claim.StreamMetadata) currentClaim.getValue();
            if (context != null) {
                uploadedThumbnailUrl = currentClaim.getThumbnailUrl(imageThumbnail.getLayoutParams().width, imageThumbnail.getLayoutParams().height, 85);
            }
            if (context != null && !Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
                Glide.with(context.getApplicationContext()).load(uploadedThumbnailUrl).centerCrop().into(imageThumbnail);
            }
            inputTitle.setText(currentClaim.getTitle());
            inputDescription.setText(currentClaim.getDescription());
            if (addedTagsAdapter != null && currentClaim.getTagObjects() != null) {
                addedTagsAdapter.addTags(currentClaim.getTagObjects());
                updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, true);
            }
            if (metadata.getFee() != null) {
                Fee fee = metadata.getFee();
                switchPrice.setChecked(true);
                inputPrice.setText(fee.getAmount());
                priceCurrencySpinner.setSelection("lbc".equalsIgnoreCase(fee.getCurrency()) ? 0 : 1);
            }
            inputAddress.setText(currentClaim.getName());
            inputDeposit.setText(currentClaim.getAmount());
            if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
                // get the first language
                String langCode = metadata.getLanguages().get(0);
                int langCodePosition = ((LanguageSpinnerAdapter) languageSpinner.getAdapter()).getItemPosition(langCode);
                if (langCodePosition > -1) {
                    languageSpinner.setSelection(langCodePosition);
                }
            }
            if (!Helper.isNullOrEmpty(metadata.getLicense())) {
                LicenseSpinnerAdapter adapter = (LicenseSpinnerAdapter) licenseSpinner.getAdapter();
                int licPosition = adapter.getItemPosition(metadata.getLicense());
                if (licPosition == -1) {
                    licPosition = adapter.getItemPosition(Predefined.LICENSE_OTHER);
                }
                if (licPosition > -1) {
                    licenseSpinner.setSelection(licPosition);
                }
                License selectedLicense = (License) licenseSpinner.getSelectedItem();
                boolean otherLicense = Arrays.asList(Predefined.LICENSE_COPYRIGHTED.toLowerCase(), Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
                inputOtherLicenseDescription.setText(otherLicense ? metadata.getLicense() : null);
            }
            inputAddress.setEnabled(false);
            editMode = true;
            editFieldsLoaded = true;
        } catch (ClassCastException ex) {
            // invalid claim value type
            cancelOnFatalCondition(getString(R.string.publish_invalid_claim_type));
        }
    }
}
Also used : Context(android.content.Context) LicenseSpinnerAdapter(com.odysee.app.adapter.LicenseSpinnerAdapter) Fee(com.odysee.app.model.Fee) License(com.odysee.app.model.License) Claim(com.odysee.app.model.Claim) LanguageSpinnerAdapter(com.odysee.app.adapter.LanguageSpinnerAdapter)

Example 2 with Fee

use of com.odysee.app.model.Fee in project odysee-android by OdyseeTeam.

the class FileViewFragment method confirmPurchaseUrl.

private void confirmPurchaseUrl() {
    Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (actualClaim != null) {
        Fee fee = ((Claim.StreamMetadata) actualClaim.getValue()).getFee();
        double cost = actualClaim.getActualCost(Lbryio.LBCUSDRate).doubleValue();
        String formattedCost = Helper.LBC_CURRENCY_FORMAT.format(cost);
        Context context = getContext();
        if (context != null) {
            try {
                String message = getResources().getQuantityString(R.plurals.confirm_purchase_message, cost == 1 ? 1 : 2, actualClaim.getTitle(), formattedCost.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(cost) : formattedCost);
                AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(R.string.confirm_purchase).setMessage(message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Bundle bundle = new Bundle();
                        bundle.putString("uri", currentUrl);
                        bundle.putString("paid", "true");
                        bundle.putDouble("amount", Helper.parseDouble(fee.getAmount(), 0));
                        bundle.putDouble("lbc_amount", cost);
                        bundle.putString("currency", fee.getCurrency());
                        LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle);
                        View root = getView();
                        if (root != null) {
                            root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
                            root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
                        }
                        handleMainActionForClaim();
                    }
                }).setNegativeButton(R.string.no, null);
                builder.show();
            } catch (IllegalStateException ex) {
            // pass
            }
        }
    }
}
Also used : AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) Fee(com.odysee.app.model.Fee) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) Claim(com.odysee.app.model.Claim)

Example 3 with Fee

use of com.odysee.app.model.Fee in project odysee-android by OdyseeTeam.

the class FileViewFragment method renderClaim.

private void renderClaim() {
    Claim claimToRender = collectionClaimItem != null ? collectionClaimItem : fileClaim;
    if (claimToRender == null) {
        return;
    }
    if (!claimToRender.hasSource()) {
    // TODO See if the "publisher is not live yet" UI must be shown
    }
    if (claimToRender.isPlayable() && MainActivity.appPlayer != null) {
        MainActivity.appPlayer.setPlayWhenReady(isPlaying);
    }
    Helper.setViewVisibility(layoutLoadingState, View.GONE);
    Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
    /*
        if (claim.getTags().contains("disable-support") || claim.getSigningChannel().getTags().contains("disable-support"))
            Helper.setViewVisibility(tipButton, View.GONE);
        else
            Helper.setViewVisibility(tipButton, View.VISIBLE);
*/
    loadViewCount();
    loadReactions(claimToRender);
    checkIsFollowing();
    View root = getView();
    if (root != null) {
        Context context = getContext();
        root.findViewById(R.id.file_view_scroll_view).scrollTo(0, 0);
        Helper.setViewVisibility(layoutDisplayArea, View.VISIBLE);
        ImageView descIndicator = root.findViewById(R.id.file_view_desc_toggle_arrow);
        descIndicator.setImageResource(R.drawable.ic_arrow_dropdown);
        boolean hasDescription = !Helper.isNullOrEmpty(claimToRender.getDescription());
        boolean hasTags = claimToRender.getTags() != null && claimToRender.getTags().size() > 0;
        root.findViewById(R.id.file_view_description).setVisibility(hasDescription ? View.VISIBLE : View.GONE);
        root.findViewById(R.id.file_view_tag_area).setVisibility(hasTags ? View.VISIBLE : View.GONE);
        if (hasTags && !hasDescription) {
            root.findViewById(R.id.file_view_tag_area).setPadding(0, 0, 0, 0);
        }
        root.findViewById(R.id.file_view_description_area).setVisibility(View.GONE);
        ((TextView) root.findViewById(R.id.file_view_title)).setText(claimToRender.getTitle());
        ((TextView) root.findViewById(R.id.file_view_description)).setText(claimToRender.getDescription());
        ((TextView) root.findViewById(R.id.file_view_publisher_name)).setText(Helper.isNullOrEmpty(claimToRender.getPublisherName()) ? getString(R.string.anonymous) : claimToRender.getPublisherName());
        Claim signingChannel = claimToRender.getSigningChannel();
        boolean hasPublisher = signingChannel != null;
        boolean hasPublisherThumbnail = hasPublisher && !Helper.isNullOrEmpty(signingChannel.getThumbnailUrl());
        root.findViewById(R.id.file_view_publisher_avatar).setVisibility(hasPublisher ? View.VISIBLE : View.GONE);
        root.findViewById(R.id.file_view_publisher_thumbnail).setVisibility(hasPublisherThumbnail ? View.VISIBLE : View.INVISIBLE);
        root.findViewById(R.id.file_view_publisher_no_thumbnail).setVisibility(!hasPublisherThumbnail ? View.VISIBLE : View.INVISIBLE);
        if (hasPublisher) {
            int bgColor = Helper.generateRandomColorForValue(signingChannel.getClaimId());
            Helper.setIconViewBackgroundColor(root.findViewById(R.id.file_view_publisher_no_thumbnail), bgColor, false, context);
            if (hasPublisherThumbnail && context != null) {
                ViewGroup.LayoutParams lp = root.findViewById(R.id.file_view_publisher_thumbnail).getLayoutParams();
                Glide.with(context.getApplicationContext()).load(signingChannel.getThumbnailUrl(lp.width, lp.height, 85)).apply(RequestOptions.circleCropTransform()).into((ImageView) root.findViewById(R.id.file_view_publisher_thumbnail));
            }
            ((TextView) root.findViewById(R.id.file_view_publisher_thumbnail_alpha)).setText(signingChannel.getName() != null ? signingChannel.getName().substring(1, 2).toUpperCase() : null);
        }
        String publisherTitle = signingChannel != null ? signingChannel.getTitle() : null;
        TextView textPublisherTitle = root.findViewById(R.id.file_view_publisher_title);
        textPublisherTitle.setVisibility(Helper.isNullOrEmpty(publisherTitle) ? View.GONE : View.VISIBLE);
        textPublisherTitle.setText(publisherTitle);
        RecyclerView descTagsList = root.findViewById(R.id.file_view_tag_list);
        FlexboxLayoutManager flm = new FlexboxLayoutManager(context);
        descTagsList.setLayoutManager(flm);
        List<Tag> tags = claimToRender.getTagObjects();
        TagListAdapter tagListAdapter = new TagListAdapter(tags, context);
        tagListAdapter.setClickListener(new TagListAdapter.TagClickListener() {

            @Override
            public void onTagClicked(Tag tag, int customizeMode) {
                if (customizeMode == TagListAdapter.CUSTOMIZE_MODE_NONE) {
                    Context ctx = getContext();
                    if (ctx instanceof MainActivity) {
                        ((MainActivity) ctx).openAllContentFragmentWithTag(tag.getName());
                    }
                }
            }
        });
        descTagsList.setAdapter(tagListAdapter);
        root.findViewById(R.id.file_view_tag_area).setVisibility(tags.size() > 0 ? View.VISIBLE : View.GONE);
        root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE);
        root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.GONE);
        root.findViewById(R.id.file_view_media_meta_container).setVisibility(View.VISIBLE);
        Claim.GenericMetadata metadata = claimToRender.getValue();
        if (!Helper.isNullOrEmpty(claimToRender.getThumbnailUrl())) {
            ImageView thumbnailView = root.findViewById(R.id.file_view_thumbnail);
            Glide.with(context.getApplicationContext()).asBitmap().load(claimToRender.getThumbnailUrl(context.getResources().getDisplayMetrics().widthPixels, thumbnailView.getLayoutParams().height, 85)).centerCrop().into(thumbnailView);
        } else {
        // display first x letters of claim name, with random background
        }
        root.findViewById(R.id.file_view_main_action_button).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                onMainActionButtonClicked();
            }
        });
        root.findViewById(R.id.file_view_media_meta_container).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                onMainActionButtonClicked();
            }
        });
        root.findViewById(R.id.file_view_open_external_button).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                openClaimExternally(claimToRender, claimToRender.getMediaType());
            }
        });
        if (metadata instanceof Claim.StreamMetadata) {
            Claim.StreamMetadata streamMetadata = (Claim.StreamMetadata) metadata;
            long publishTime = streamMetadata.getReleaseTime() > 0 ? streamMetadata.getReleaseTime() * 1000 : claimToRender.getTimestamp() * 1000;
            ((TextView) root.findViewById(R.id.file_view_publish_time)).setText(DateUtils.getRelativeTimeSpanString(publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
            Fee fee = streamMetadata.getFee();
            if (fee != null && Helper.parseDouble(fee.getAmount(), 0) > 0) {
                root.findViewById(R.id.file_view_fee_container).setVisibility(View.VISIBLE);
                ((TextView) root.findViewById(R.id.file_view_fee)).setText(Helper.shortCurrencyFormat(claimToRender.getActualCost(Lbryio.LBCUSDRate).doubleValue()));
            }
        }
        boolean isAnonymous = claimToRender.getSigningChannel() == null;
        View iconFollow = root.findViewById(R.id.file_view_icon_follow);
        View iconUnfollow = root.findViewById(R.id.file_view_icon_unfollow);
        if (isAnonymous) {
            if (iconFollow.getVisibility() == View.VISIBLE) {
                iconFollow.setVisibility(View.INVISIBLE);
            }
            if (iconUnfollow.getVisibility() == View.VISIBLE) {
                iconUnfollow.setVisibility(View.INVISIBLE);
            }
        }
        MaterialButton mainActionButton = root.findViewById(R.id.file_view_main_action_button);
        if (claimToRender.isPlayable()) {
            mainActionButton.setText(R.string.play);
        } else if (claimToRender.isViewable()) {
            mainActionButton.setText(R.string.view);
        } else {
            mainActionButton.setText(R.string.download);
        }
    }
    if (claimToRender.isFree() && Helper.isNullOrEmpty(commentHash)) {
        if (claimToRender.isPlayable() || (!Lbry.SDK_READY && Lbryio.isSignedIn())) {
            if (MainActivity.nowPlayingClaim != null && MainActivity.nowPlayingClaim.getClaimId().equalsIgnoreCase(claimToRender.getClaimId())) {
                // claim already playing
                showExoplayerView();
                playMedia();
            } else {
                onMainActionButtonClicked();
            }
        } else if (claimToRender.isViewable() && Lbry.SDK_READY) {
            onMainActionButtonClicked();
        } else if (!Lbry.SDK_READY) {
            restoreMainActionButton();
        }
    } else {
        restoreMainActionButton();
    }
    /*if (Lbry.SDK_READY && !claimToRender.isPlayable() && !claimToRender.isViewable() && Helper.isNullOrEmpty(commentHash)) {
            if (claimToRender.getFile() == null) {
                loadFile();
            } else {
                // file already loaded, but it's unsupported
                showUnsupportedView();
            }
        }*/
    checkRewardsDriver();
    checkOwnClaim();
}
Also used : FlexboxLayoutManager(com.google.android.flexbox.FlexboxLayoutManager) MainActivity(com.odysee.app.MainActivity) MaterialButton(com.google.android.material.button.MaterialButton) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) AttributeProviderContext(org.commonmark.renderer.html.AttributeProviderContext) Context(android.content.Context) TagListAdapter(com.odysee.app.adapter.TagListAdapter) ViewGroup(android.view.ViewGroup) Fee(com.odysee.app.model.Fee) SolidIconView(com.odysee.app.ui.controls.SolidIconView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) NestedScrollView(androidx.core.widget.NestedScrollView) AdapterView(android.widget.AdapterView) RecyclerView(androidx.recyclerview.widget.RecyclerView) PhotoView(com.github.chrisbanes.photoview.PhotoView) ImageView(android.widget.ImageView) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) Tag(com.odysee.app.model.Tag) Claim(com.odysee.app.model.Claim)

Example 4 with Fee

use of com.odysee.app.model.Fee in project odysee-android by OdyseeTeam.

the class PublishFormFragment method buildPublishClaim.

private Claim buildPublishClaim() {
    Claim claim = new Claim();
    claim.setName(Helper.getValue(inputAddress.getText()));
    claim.setAmount(Helper.getValue(inputDeposit.getText()));
    Claim.StreamMetadata metadata = new Claim.StreamMetadata();
    metadata.setTitle(Helper.getValue(inputTitle.getText()));
    metadata.setDescription(Helper.getValue(inputDescription.getText()));
    metadata.setTags(Helper.getTagsForTagObjects(addedTagsAdapter.getTags()));
    Claim selectedChannel = (Claim) channelSpinner.getSelectedItem();
    if (selectedChannel != null && !selectedChannel.isPlaceholder() && !selectedChannel.isPlaceholderAnonymous()) {
        claim.setSigningChannel(selectedChannel);
    }
    if (switchPrice.isChecked()) {
        Fee fee = new Fee();
        fee.setCurrency((String) priceCurrencySpinner.getSelectedItem());
        fee.setAmount(Helper.getValue(inputPrice.getText()));
        metadata.setFee(fee);
    }
    if (!Helper.isNullOrEmpty(uploadedThumbnailUrl)) {
        Claim.Resource thumbnail = new Claim.Resource();
        thumbnail.setUrl(uploadedThumbnailUrl);
        metadata.setThumbnail(thumbnail);
    }
    Language selectedLanguage = (Language) languageSpinner.getSelectedItem();
    if (selectedLanguage != null) {
        metadata.setLanguages(Arrays.asList(selectedLanguage.getCode()));
    }
    License selectedLicense = (License) licenseSpinner.getSelectedItem();
    if (selectedLicense != null) {
        boolean otherLicense = Arrays.asList(Predefined.LICENSE_COPYRIGHTED.toLowerCase(), Predefined.LICENSE_OTHER.toLowerCase()).contains(selectedLicense.getName().toLowerCase());
        metadata.setLicense(otherLicense ? Helper.getValue(inputOtherLicenseDescription.getText()) : selectedLicense.getName());
        metadata.setLicenseUrl(selectedLicense.getUrl());
    }
    // set release time from current claim (on edit)
    if (currentClaim != null) {
        Claim.StreamMetadata currentMetadata = (Claim.StreamMetadata) currentClaim.getValue();
        metadata.setReleaseTime(currentMetadata.getReleaseTime());
        if (metadata.getReleaseTime() == 0) {
            metadata.setReleaseTime(currentClaim.getTimestamp());
        }
        claim.setTimestamp(currentClaim.getTimestamp());
    }
    claim.setValueType(Claim.TYPE_STREAM);
    claim.setValue(metadata);
    return claim;
}
Also used : Language(com.odysee.app.model.Language) Fee(com.odysee.app.model.Fee) License(com.odysee.app.model.License) Claim(com.odysee.app.model.Claim)

Aggregations

Claim (com.odysee.app.model.Claim)4 Fee (com.odysee.app.model.Fee)4 Context (android.content.Context)3 View (android.view.View)2 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 NestedScrollView (androidx.core.widget.NestedScrollView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 PhotoView (com.github.chrisbanes.photoview.PhotoView)2 PlayerView (com.google.android.exoplayer2.ui.PlayerView)2 License (com.odysee.app.model.License)2 SolidIconView (com.odysee.app.ui.controls.SolidIconView)2 AttributeProviderContext (org.commonmark.renderer.html.AttributeProviderContext)2 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 ViewGroup (android.view.ViewGroup)1 AlertDialog (androidx.appcompat.app.AlertDialog)1