Search in sources :

Example 46 with Content

use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.

the class CardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
    ImageCardView cardView = (ImageCardView) viewHolder.view;
    if (item instanceof Content) {
        Content content = (Content) item;
        if (content.getCardImageUrl() != null) {
            if (SHOW_TITLE) {
                String title = ContentHelper.getCardViewSubtitle(mContext, content);
                if (titleText != null) {
                    if (TextUtils.isEmpty(title)) {
                        titleText.setVisibility(View.GONE);
                    } else {
                        titleText.setVisibility(View.VISIBLE);
                    }
                }
                cardView.setTitleText(title);
                cardView.setContentText(content.getTitle());
            } else {
                cardView.setTitleText("");
                cardView.setContentText("");
            }
            cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
            /* Zype, Evgeny Cherkasov */
            double playbackPercentage = content.getExtraValueAsDouble(Content.EXTRA_PLAYBACK_POSITION_PERCENTAGE);
            if (ZypeConfiguration.displayWatchedBarOnVideoThumbnails() && playbackPercentage > 0) {
                SimpleTarget<Bitmap> bitmapTarget = new SimpleTarget<Bitmap>(mCardWidthDp, mCardHeightDp) {

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        // cardView.setInfoAreaBackground(infoFieldWithProgressBarBackground);
                        Bitmap bitmap = Helpers.addProgressToThumbnail((Activity) mContext, resource, playbackPercentage, 0);
                        cardView.getMainImageView().setImageBitmap(bitmap);
                    }
                };
                GlideHelper.loadImageIntoSimpleTargetBitmap(viewHolder.view.getContext(), content.getCardImageUrl(), new GlideHelper.LoggingListener<>(), R.drawable.movie, bitmapTarget);
            } else {
                GlideHelper.loadImageIntoView(cardView.getMainImageView(), viewHolder.view.getContext(), content.getCardImageUrl(), new GlideHelper.LoggingListener<>(), R.drawable.movie);
                cardView.setInfoAreaBackground(sFocusedFadeMask);
            }
            /* Zype, Evgeny Cherkasov */
            // Display lock icon for paywalled video
            ImageView mBadgeImage = (ImageView) cardView.findViewById(R.id.extra_badge);
            if (contentBrowser.getPurchaseHelper().isVideoPaywalled(content)) {
                if (contentBrowser.getPurchaseHelper().isVideoLocked(content)) {
                    mBadgeImage.setVisibility(View.VISIBLE);
                    mBadgeImage.setBackgroundColor(mContext.getResources().getColor(R.color.lock_color));
                    mBadgeImage.setImageResource(R.drawable.locked);
                } else {
                    if (ZypeSettings.UNLOCK_TRANSPARENT) {
                        mBadgeImage.setVisibility(View.GONE);
                    } else {
                        mBadgeImage.setVisibility(View.VISIBLE);
                        mBadgeImage.setBackgroundColor(mContext.getResources().getColor(R.color.unlock_color));
                        mBadgeImage.setImageResource(R.drawable.unlocked);
                    }
                }
            } else {
                mBadgeImage.setVisibility(View.GONE);
            }
        }
    } else if (item instanceof ContentContainer) {
        ContentContainer contentContainer = (ContentContainer) item;
        // }
        if (SHOW_TITLE) {
            String title = "";
            if (titleText != null) {
                if (TextUtils.isEmpty(title)) {
                    titleText.setVisibility(View.GONE);
                } else {
                    titleText.setVisibility(View.VISIBLE);
                }
            }
            cardView.setTitleText(title);
            cardView.setContentText(contentContainer.getName());
        } else {
            cardView.setTitleText("");
            cardView.setContentText("");
        }
        cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
        // Show image for playlist
        if (contentContainer.getExtraStringValue(Content.CARD_IMAGE_URL_FIELD_NAME) != null) {
            GlideHelper.loadImageIntoView(cardView.getMainImageView(), viewHolder.view.getContext(), contentContainer.getExtraStringValue(Content.CARD_IMAGE_URL_FIELD_NAME), new GlideHelper.LoggingListener<>(), R.drawable.movie);
        // Glide.with(viewHolder.view.getContext())
        // .load(contentContainer.getExtraStringValue(Content.CARD_IMAGE_URL_FIELD_NAME))
        // .listener(new GlideHelper.LoggingListener<>())
        // .centerCrop()
        // .error(mDefaultCardImage)
        // .into(cardView.getMainImageView());
        } else {
            cardView.getMainImageView().setImageDrawable(mDefaultCardImage);
        }
        cardView.setInfoAreaBackground(sFocusedFadeMask);
    } else /* Zype, Evgeny CHerkasov */
    if (item instanceof Action) {
        Action action = (Action) item;
        cardView.setContentText(action.getLabel1());
        cardView.setMainImageScaleType(ImageView.ScaleType.CENTER);
        cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
        try {
            Drawable iconDrawable = ContextCompat.getDrawable(TenFootApp.getInstance().getApplicationContext(), action.getIconResourceId());
            DrawableCompat.setTint(iconDrawable, ContextCompat.getColor(mContext, R.color.primary_text));
            cardView.setMainImage(iconDrawable);
        } catch (Resources.NotFoundException e) {
            Log.e(TAG, "Resource not found", e);
            throw e;
        }
    }
}
Also used : ImageCardView(androidx.leanback.widget.ImageCardView) Action(com.amazon.android.model.Action) Drawable(android.graphics.drawable.Drawable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) Content(com.amazon.android.model.content.Content) GlideHelper(com.amazon.android.utils.GlideHelper) ContentContainer(com.amazon.android.model.content.ContentContainer) ImageView(android.widget.ImageView) Resources(android.content.res.Resources)

Example 47 with Content

use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.

the class DetailsDescriptionPresenter method onBindDescription.

private void onBindDescription(ViewHolder viewHolder, Object item) {
    Log.v(TAG, "onBindDescription called.");
    Content content = (Content) item;
    if (content != null) {
        populateViewHolder(viewHolder, content);
    } else {
        Log.e(TAG, "Content is null in onBindDescription");
    }
}
Also used : Content(com.amazon.android.model.content.Content)

Example 48 with Content

use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.

the class PosterCardPresenter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
    ImageCardView cardView = (ImageCardView) viewHolder.view;
    if (item instanceof Content) {
        Content content = (Content) item;
        if (content.getCardImageUrl() != null) {
            if (SHOW_TITLE) {
                cardView.setContentText(content.getTitle());
                cardView.setTitleText(ContentHelper.getCardViewSubtitle(mContext, content));
            } else {
                cardView.setContentText("");
                cardView.setTitleText("");
            }
            cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
            String url = content.getExtraValueAsString(Content.EXTRA_IMAGE_POSTER_URL);
            if (TextUtils.isEmpty(url) || url.equals("null")) {
                url = content.getExtraValueAsString(Content.EXTRA_THUMBNAIL_POSTER_URL);
            }
            double playbackPercentage = content.getExtraValueAsDouble(Content.EXTRA_PLAYBACK_POSITION_PERCENTAGE);
            if (ZypeConfiguration.displayWatchedBarOnVideoThumbnails() && playbackPercentage > 0) {
                SimpleTarget<Bitmap> bitmapTarget = new SimpleTarget<Bitmap>(mCardWidthDp, mCardHeightDp) {

                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        cardView.setInfoAreaBackground(infoFieldWithProgressBarBackground);
                        Bitmap bitmap = Helpers.addProgressToThumbnail((Activity) mContext, resource, playbackPercentage, 0);
                        cardView.getMainImageView().setImageBitmap(bitmap);
                    }
                };
                GlideHelper.loadImageIntoSimpleTargetBitmap(viewHolder.view.getContext(), url, new GlideHelper.LoggingListener<>(), R.drawable.movie, bitmapTarget);
            } else {
                GlideHelper.loadImageIntoView(cardView.getMainImageView(), viewHolder.view.getContext(), url, new GlideHelper.LoggingListener<>(), R.drawable.movie);
                cardView.setInfoAreaBackground(sFocusedFadeMask);
            }
            // Display lock icon for subscription video
            ImageView mBadgeImage = (ImageView) cardView.findViewById(R.id.extra_badge);
            if (contentBrowser.getPurchaseHelper().isVideoPaywalled(content)) {
                if (contentBrowser.getPurchaseHelper().isVideoLocked(content)) {
                    mBadgeImage.setVisibility(View.VISIBLE);
                    mBadgeImage.setBackgroundColor(mContext.getResources().getColor(R.color.lock_color));
                    mBadgeImage.setImageResource(R.drawable.locked);
                } else {
                    if (ZypeSettings.UNLOCK_TRANSPARENT) {
                        mBadgeImage.setVisibility(View.GONE);
                    } else {
                        mBadgeImage.setVisibility(View.VISIBLE);
                        mBadgeImage.setBackgroundColor(mContext.getResources().getColor(R.color.unlock_color));
                        mBadgeImage.setImageResource(R.drawable.unlocked);
                    }
                }
            } else {
                mBadgeImage.setVisibility(View.GONE);
            }
        }
    } else if (item instanceof ContentContainer) {
        ContentContainer contentContainer = (ContentContainer) item;
        if (SHOW_TITLE) {
            cardView.setContentText(contentContainer.getName());
        } else {
            cardView.setContentText("");
        }
        cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
        // Show image for playlist
        String url = contentContainer.getExtraStringValue(ContentContainer.EXTRA_IMAGE_POSTER_URL);
        if (TextUtils.isEmpty(url) || url.equals("null")) {
            url = contentContainer.getExtraStringValue(ContentContainer.EXTRA_THUMBNAIL_POSTER_URL);
        }
        if (url != null) {
            GlideHelper.loadImageIntoView(cardView.getMainImageView(), viewHolder.view.getContext(), url, new GlideHelper.LoggingListener<>(), R.drawable.movie);
        } else {
            cardView.getMainImageView().setImageDrawable(mDefaultCardImage);
        }
    } else if (item instanceof Action) {
        Action action = (Action) item;
        cardView.setContentText(action.getLabel1());
        cardView.setMainImageScaleType(ImageView.ScaleType.CENTER);
        cardView.setMainImageDimensions(mCardWidthDp, mCardHeightDp);
        try {
            cardView.setMainImage(ContextCompat.getDrawable(TenFootApp.getInstance().getApplicationContext(), action.getIconResourceId()));
        } catch (Resources.NotFoundException e) {
            Log.e(TAG, "Resource not found", e);
            throw e;
        }
    }
}
Also used : ImageCardView(androidx.leanback.widget.ImageCardView) Action(com.amazon.android.model.Action) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Bitmap(android.graphics.Bitmap) Content(com.amazon.android.model.content.Content) GlideHelper(com.amazon.android.utils.GlideHelper) ContentContainer(com.amazon.android.model.content.ContentContainer) ImageView(android.widget.ImageView) Resources(android.content.res.Resources)

Example 49 with Content

use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.

the class AuthHelper method isAuthorized.

/**
 * Is authorized Observable.
 *
 * @return RX Observable.
 */
public Observable<Bundle> isAuthorized() {
    // get the requested content
    Content content = mContentBrowser.getLastSelectedContent();
    AnalyticsHelper.trackAuthorizationRequest(content);
    return Observable.create(subscriber -> {
        // Check if user is logged in. If not, show authentication activity.
        mIAuthentication.isResourceAuthorized(mAppContext, "", new IAuthentication.ResponseHandler() {

            @Override
            public void onSuccess(Bundle extras) {
                Log.d(TAG, "Resource Authorization " + "success");
                AnalyticsHelper.trackAuthorizationResultSuccess(content);
                handleSuccessCase(subscriber, extras);
            }

            @Override
            public void onFailure(Bundle extras) {
                Log.e(TAG, "Resource Authorization " + "failed");
                AnalyticsHelper.trackAuthorizationResultFailure(content, retrieveErrorCategory(extras));
                handleFailureCase(subscriber, extras);
            }
        });
    });
}
Also used : Content(com.amazon.android.model.content.Content) Bundle(android.os.Bundle) IAuthentication(com.amazon.auth.IAuthentication)

Example 50 with Content

use of com.amazon.android.model.content.Content in project zype-firebuilder by zype.

the class RecommendationSender method getContentFromRoot.

/**
 * Finds the content within the root content container.
 *
 * @param contentId The id of the content to find.
 * @return The content, or null if it was not found.
 */
Content getContentFromRoot(String contentId) {
    Content content;
    if (mRootContentContainer == null) {
        Log.e(TAG, "Cannot find content from empty root.");
        return null;
    }
    content = mRootContentContainer.findContentById(contentId);
    return content;
}
Also used : Content(com.amazon.android.model.content.Content)

Aggregations

Content (com.amazon.android.model.content.Content)76 ContentContainer (com.amazon.android.model.content.ContentContainer)28 Test (org.junit.Test)26 ArrayObjectAdapter (androidx.leanback.widget.ArrayObjectAdapter)13 ListRow (androidx.leanback.widget.ListRow)13 ArrayList (java.util.ArrayList)11 Recipe (com.amazon.android.recipe.Recipe)10 Intent (android.content.Intent)8 RecentDatabaseHelper (com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper)7 TextUtils (android.text.TextUtils)6 RecentRecord (com.amazon.android.contentbrowser.database.records.RecentRecord)6 CardPresenter (com.amazon.android.tv.tenfoot.presenter.CardPresenter)6 List (java.util.List)6 Context (android.content.Context)5 HeaderItem (androidx.leanback.widget.HeaderItem)5 Action (com.amazon.android.model.Action)5 NavigatorModel (com.amazon.android.navigator.NavigatorModel)5 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)5 Bundle (android.os.Bundle)4 Log (android.util.Log)4