Search in sources :

Example 1 with ContentBrowser

use of com.amazon.android.contentbrowser.ContentBrowser 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 2 with ContentBrowser

use of com.amazon.android.contentbrowser.ContentBrowser in project zype-firebuilder by zype.

the class SplashActivity method autoPlayContent.

private void autoPlayContent() {
    ContentBrowser contentBrowser = ContentBrowser.getInstance(this);
    loadAutoPlayContent().subscribe(autoPlayList -> {
        boolean found = false;
        for (ZobjectTopPlaylist model : autoPlayList) {
            if (model.active && model.zobjectTypeTitle.equalsIgnoreCase("autoplay_hero")) {
                found = true;
                mCompositeSubscription.add(contentBrowser.getContentById(model.videoid).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(content -> {
                    // move the user to the detail screen
                    contentBrowser.runGlobalRecipes(this, this, content);
                // contentBrowser.switchToRendererScreen(content);
                }, throwable -> {
                    contentBrowser.runGlobalRecipes(this, this);
                }));
                break;
            }
        }
        if (!found) {
            contentBrowser.runGlobalRecipes(this, this);
        }
    }, throwable -> {
        contentBrowser.runGlobalRecipes(this, this);
    });
}
Also used : Bundle(android.os.Bundle) AnalyticsManager(com.amazon.analytics.AnalyticsManager) PackageManager(android.content.pm.PackageManager) ProgressBar(android.widget.ProgressBar) ImageView(android.widget.ImageView) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) PackageInfo(android.content.pm.PackageInfo) Observable(rx.Observable) R(com.amazon.android.tv.tenfoot.R) AdMacrosHelper(com.zype.fire.api.Util.AdMacrosHelper) Calendar(java.util.Calendar) Schedulers(rx.schedulers.Schedulers) ErrorHelper(com.amazon.android.contentbrowser.helper.ErrorHelper) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser) Log(android.util.Log) ErrorUtils(com.amazon.android.utils.ErrorUtils) AsyncTask(android.os.AsyncTask) HeroSlider(com.amazon.android.tv.tenfoot.ui.sliders.HeroSlider) CompositeSubscription(rx.subscriptions.CompositeSubscription) Helpers(com.amazon.android.utils.Helpers) ZypeApi(com.zype.fire.api.ZypeApi) List(java.util.List) TextView(android.widget.TextView) EPGDataManager(com.amazon.android.tv.tenfoot.ui.epg.EPGDataManager) ICancellableLoad(com.amazon.android.interfaces.ICancellableLoad) ZypeSettings(com.zype.fire.api.ZypeSettings) ZobjectTopPlaylist(com.zype.fire.api.Model.ZobjectTopPlaylist) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) Activity(android.app.Activity) Collections(java.util.Collections) BaseActivity(com.amazon.android.tv.tenfoot.base.BaseActivity) Resources(android.content.res.Resources) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser) ZobjectTopPlaylist(com.zype.fire.api.Model.ZobjectTopPlaylist)

Example 3 with ContentBrowser

use of com.amazon.android.contentbrowser.ContentBrowser in project zype-firebuilder by zype.

the class CreateLoginActivity method onLogin.

private void onLogin() {
    ContentBrowser contentBrowser = ContentBrowser.getInstance(this);
    contentBrowser.getAuthHelper().isAuthenticated().subscribe(isAuthenticatedResultBundle -> {
        if (isAuthenticatedResultBundle.getBoolean(AuthHelper.RESULT)) {
            contentBrowser.updateUserSubscribed();
            finish();
        } else {
            contentBrowser.getAuthHelper().authenticateWithActivity().subscribe(resultBundle -> {
                if (resultBundle != null) {
                    if (!resultBundle.getBoolean(AuthHelper.RESULT)) {
                        contentBrowser.getNavigator().runOnUpcomingActivity(() -> contentBrowser.getAuthHelper().handleErrorBundle(resultBundle));
                    } else {
                        contentBrowser.onAuthenticationStatusUpdateEvent(new AuthHelper.AuthenticationStatusUpdateEvent(true, registration));
                        EventBus.getDefault().post(new AuthHelper.AuthenticationStatusUpdateEvent(true));
                        setResult(RESULT_OK);
                        finish();
                    }
                }
            });
        }
    });
}
Also used : ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser) AuthHelper(com.amazon.android.contentbrowser.helper.AuthHelper)

Example 4 with ContentBrowser

use of com.amazon.android.contentbrowser.ContentBrowser in project zype-firebuilder by zype.

the class HeroSliderFragment method processContentContainer.

private void processContentContainer(ContentContainer contentContainer, Slider slider) {
    ContentBrowser contentBrowser = ContentBrowser.getInstance(getActivity());
    if (contentContainer != null) {
        if (contentContainer.getContents().size() > 0) {
            Content content = contentContainer.getContents().get(0);
            openVideo(content, slider);
        } else {
            if (Integer.valueOf(contentContainer.getExtraStringValue(ContentContainer.EXTRA_PLAYLIST_ITEM_COUNT)) > 0) {
                // Playlist has  videos, but they is not loaded yet.
                // Load videos and then open video detail screen of the first video in the playlist
                ContentLoader.ILoadContentForContentContainer listener = () -> {
                    Content content = contentContainer.getContents().get(0);
                    openVideo(content, slider);
                };
                ContentLoader.getInstance(getActivity()).loadContentForContentContainer(contentContainer, getActivity(), listener);
            } else {
                contentBrowser.setLastSelectedContentContainer(contentContainer);
                contentBrowser.switchToScreen(ContentBrowser.CONTENT_SUBMENU_SCREEN);
            }
        }
    }
}
Also used : Content(com.amazon.android.model.content.Content) ContentLoader(com.amazon.android.contentbrowser.ContentLoader) ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser)

Example 5 with ContentBrowser

use of com.amazon.android.contentbrowser.ContentBrowser in project zype-firebuilder by zype.

the class HeroSliderFragment method openVideo.

private void openVideo(Content content, Slider slider) {
    ContentBrowser contentBrowser = ContentBrowser.getInstance(getActivity());
    boolean registrationRequired = content.getExtraValueAsBoolean(Content.EXTRA_REGISTRATION_REQUIRED);
    if (registrationRequired) {
        contentBrowser.setLastSelectedContent(content).switchToScreen(ContentBrowser.CONTENT_DETAILS_SCREEN, content);
    } else if (slider.autoplay != null && slider.autoplay) {
        // Open playback screen when 'autoplay' is set to true
        contentBrowser.handleRendererScreenSwitch(getActivity(), content, contentBrowser.CONTENT_ACTION_WATCH_NOW, true);
    } else {
        // move the user to the detail screen
        contentBrowser.setLastSelectedContent(content).switchToScreen(ContentBrowser.CONTENT_DETAILS_SCREEN, content);
    }
}
Also used : ContentBrowser(com.amazon.android.contentbrowser.ContentBrowser)

Aggregations

ContentBrowser (com.amazon.android.contentbrowser.ContentBrowser)5 Bundle (android.os.Bundle)2 ContentLoader (com.amazon.android.contentbrowser.ContentLoader)2 Content (com.amazon.android.model.content.Content)2 ZobjectTopPlaylist (com.zype.fire.api.Model.ZobjectTopPlaylist)2 List (java.util.List)2 AndroidSchedulers (rx.android.schedulers.AndroidSchedulers)2 Schedulers (rx.schedulers.Schedulers)2 CompositeSubscription (rx.subscriptions.CompositeSubscription)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 AsyncTask (android.os.AsyncTask)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 View (android.view.View)1