Search in sources :

Example 41 with Content

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

the class PlaybackOverlayFragment method addOtherRows.

private void addOtherRows() {
    ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(new CardPresenter());
    for (Content content : mRelatedContentList) {
        // Do not show the selected content under recommendation list.
        if (!StringManipulation.areStringsEqual(content.getId(), mSelectedContent.getId())) {
            listRowAdapter.add(content);
        }
    }
    HeaderItem header = new HeaderItem(0, getString(R.string.related_contents));
    mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
Also used : Content(com.amazon.android.model.content.Content) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) HeaderItem(androidx.leanback.widget.HeaderItem) ListRow(androidx.leanback.widget.ListRow)

Example 42 with Content

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

the class PlaybackOverlayFragment method onCreate.

/**
 * {@inheritDoc}
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mSelectedContent = (Content) getActivity().getIntent().getSerializableExtra(Content.class.getSimpleName());
    isAutoPlay = getActivity().getIntent().getBooleanExtra(SHOW_PLAYLIST_AUTOPLAY, false);
    boolean trailerMode = false;
    if (mSelectedContent == null) {
        mSelectedContent = (Content) getActivity().getIntent().getSerializableExtra("play_trailer");
        trailerMode = true;
        mHideMoreActions = true;
    } else {
        mShowRelatedContent = ContentBrowser.getInstance(getActivity()).isShowRelatedContent();
        mHideMoreActions = true;
    }
    mCurrentItem = -1;
    if (mShowRelatedContent) {
        mRelatedContentList = ContentBrowser.getInstance(getActivity()).getRecommendedListOfAContentAsAContainer(mSelectedContent).getContents();
        // Find the index of the selected content in the related content list only if
        // recommendations are enabled.
        mCurrentItem = getCurrentContentIndex(mSelectedContent);
    } else {
        Log.d(TAG, "Recommendation is turned off");
        // Initializing to empty list to avoid null checks later.
        mRelatedContentList = new ArrayList<>();
    }
    mHandler = new Handler();
    setBackgroundType(BACKGROUND_TYPE);
    setFadingEnabled(false);
    setupRows();
    mRunnable = new Runnable() {

        @Override
        public void run() {
            int updatePeriod = getUpdatePeriod();
            if (!mFadeOutComplete) {
                updateUI();
            }
            mHandler.postDelayed(this, updatePeriod);
        }
    };
    setOnItemViewClickedListener(new ItemViewClickedListener());
    setFadeCompleteListener(new OnFadeCompleteListener() {

        @Override
        public void onFadeOutComplete() {
            mFadeOutComplete = true;
        }

        @Override
        public void onFadeInComplete() {
            mFadeOutComplete = false;
            updateUI();
        }
    });
    if (trailerMode) {
        updateCCButtonState(false, false);
    }
}
Also used : Content(com.amazon.android.model.content.Content) OnItemViewClickedListener(androidx.leanback.widget.OnItemViewClickedListener) Handler(android.os.Handler)

Example 43 with Content

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

the class PlaybackOverlayFragment method updatePlaybackRow.

private void updatePlaybackRow(int index) {
    if (mPlaybackControlsRow.getItem() != null) {
        Content item = (Content) mPlaybackControlsRow.getItem();
        if (!mRelatedContentList.isEmpty() && mCurrentItem >= 0) {
            item.setTitle(mRelatedContentList.get(mCurrentItem).getTitle());
            item.setStudio(mRelatedContentList.get(mCurrentItem).getStudio());
        }
    } else {
        Log.e(TAG, "mPlaybackControlRow.getItem() is null in updatePlaybackRow");
    }
    if (SHOW_IMAGE) {
        if (!mRelatedContentList.isEmpty() && mCurrentItem >= 0) {
            updateVideoImage(mRelatedContentList.get(mCurrentItem).getCardImageUrl());
        }
    }
    mRowsAdapter.notifyArrayItemRangeChanged(0, 1);
    mDuration = mCallback.getDuration();
    mPlaybackControlsRow.setTotalTime(mDuration);
    mPlaybackControlsRow.setCurrentTime(0);
    mPlaybackControlsRow.setBufferedProgress(0);
}
Also used : Content(com.amazon.android.model.content.Content)

Example 44 with Content

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

the class HeroSliderFragment method loadRows.

private void loadRows() {
    CustomListRowPresenter customListRowPresenter = new CustomListRowPresenter();
    customListRowPresenter.setShadowEnabled(false);
    rowsAdapter = new ArrayObjectAdapter(customListRowPresenter);
    cardPresenter = new HeroCardPresenter();
    List<ZobjectTopPlaylist> sliderList = HeroSlider.getInstance().getSliders();
    cardPresenter.setSingleImage(sliderList.size() == 1);
    listRowAdapter = new HeroCardAdapter(cardPresenter);
    List<Slider> sliders = new ArrayList<>();
    for (ZobjectTopPlaylist sliderData : sliderList) {
        for (Image image : sliderData.images) {
            Slider slider = Slider.create(sliderData.id, sliderData.videoid, sliderData.playlistid, image.url, sliderData.friendlyTitle, sliderData.autoplay);
            sliders.add(slider);
        }
    }
    listRowAdapter.addAll(0, sliders);
    final ListRow listRow = new ListRow(listRowAdapter);
    rowsAdapter.add(listRow);
    setAdapter(rowsAdapter);
    setOnItemViewSelectedListener((itemViewHolder, item, rowViewHolder, row) -> {
        if (item != null) {
            int newSelectedIndex = ((HeroCardPresenter.ViewHolder) itemViewHolder).getIndex();
            if (selectedIndex != newSelectedIndex) {
                selectedIndex = newSelectedIndex;
                registerNextScroll();
                listRowAdapter.reset();
                ((HeroCardPresenter.ViewHolder) itemViewHolder).getSlider().setSelected(true);
                listRowAdapter.notifyChanges(selectedIndex);
            }
        }
    });
    setOnItemViewClickedListener((itemViewHolder, item, rowViewHolder, row) -> {
        if (item != null && item instanceof Slider) {
            ContentBrowser contentBrowser = ContentBrowser.getInstance(getActivity());
            Slider slider = (Slider) item;
            if (TextUtils.isEmpty(slider.getVideoId())) {
                if (!TextUtils.isEmpty(slider.getPlayListId())) {
                    // load the playlist
                    ContentContainer contentContainer = contentBrowser.getPlayList(slider.getPlayListId());
                    if (contentContainer != null) {
                        processContentContainer(contentContainer, slider);
                    } else {
                        // load the playlist
                        mCompositeSubscription.add(contentBrowser.getContentLoader().loadPlayList(contentBrowser.getRootContentContainer(), slider.getPlayListId()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(container -> {
                            contentBrowser.rootSliders().addContentContainer(container);
                            processContentContainer(container, slider);
                        }, throwable -> {
                        }));
                    }
                }
            } else {
                // load the videoId
                mCompositeSubscription.add(contentBrowser.getContentById(slider.getVideoId()).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(content -> {
                    openVideo(content, slider);
                }, throwable -> {
                }));
            }
        }
    });
    if (sliderList.size() > 0) {
        // run the timer to toggle the positions
        Handler handler = new Handler(Looper.getMainLooper());
        handler.postDelayed(() -> {
            int initialIndex = listRowAdapter.size() / 2;
            int offset = initialIndex % listRowAdapter.realSize();
            selectedIndex = initialIndex - offset - 1;
            scrollToNextItem(false);
        }, WAIT_BEFORE_FOCUS_REQUEST_MS);
    }
}
Also used : Bundle(android.os.Bundle) ListRow(androidx.leanback.widget.ListRow) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) RowsFragment(androidx.leanback.app.RowsFragment) ArrayList(java.util.ArrayList) ContentLoader(com.amazon.android.contentbrowser.ContentLoader) Handler(android.os.Handler) Looper(android.os.Looper) RowPresenter(androidx.leanback.widget.RowPresenter) Schedulers(rx.schedulers.Schedulers) View(android.view.View) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser) TextUtils(android.text.TextUtils) BaseOnItemViewSelectedListener(androidx.leanback.widget.BaseOnItemViewSelectedListener) Image(com.zype.fire.api.Model.Image) CompositeSubscription(rx.subscriptions.CompositeSubscription) Content(com.amazon.android.model.content.Content) List(java.util.List) ListRowPresenter(androidx.leanback.widget.ListRowPresenter) CustomListRowPresenter(com.amazon.android.tv.tenfoot.presenter.CustomListRowPresenter) ZobjectTopPlaylist(com.zype.fire.api.Model.ZobjectTopPlaylist) Presenter(androidx.leanback.widget.Presenter) VerticalGridView(androidx.leanback.widget.VerticalGridView) ItemBridgeAdapter(androidx.leanback.widget.ItemBridgeAdapter) ContentContainer(com.amazon.android.model.content.ContentContainer) ArrayList(java.util.ArrayList) Handler(android.os.Handler) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) Image(com.zype.fire.api.Model.Image) ListRow(androidx.leanback.widget.ListRow) ZobjectTopPlaylist(com.zype.fire.api.Model.ZobjectTopPlaylist) ContentContainer(com.amazon.android.model.content.ContentContainer) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser) CustomListRowPresenter(com.amazon.android.tv.tenfoot.presenter.CustomListRowPresenter)

Example 45 with Content

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

the class ContentBrowseFragment method onContentUpdateEvent.

@Subscribe
public void onContentUpdateEvent(ContentUpdateEvent event) {
    for (int rowIndex = 0; rowIndex < mRowsAdapter.size(); rowIndex++) {
        ArrayObjectAdapter rowAdapter = (ArrayObjectAdapter) ((ListRow) mRowsAdapter.get(rowIndex)).getAdapter();
        for (int i = 0; i < rowAdapter.size(); i++) {
            Content content = (Content) rowAdapter.get(i);
            if (content.getId().equals(event.videoId)) {
                content.setExtraValue(Content.EXTRA_PLAYBACK_POSITION_PERCENTAGE, ContentBrowser.getInstance(getActivity()).getContentLoader().getContentPlaybackPositionPercentage(content));
            }
            rowAdapter.notifyArrayItemRangeChanged(i, i + 1);
        }
    }
}
Also used : Content(com.amazon.android.model.content.Content) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) Subscribe(org.greenrobot.eventbus.Subscribe)

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