Search in sources :

Example 61 with Content

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

the class ZypeContentDetailsPlaylistFragment method loadContentContainer.

private void loadContentContainer(ArrayObjectAdapter rowsAdapter) {
    Log.d(TAG, "loadRootContentContainer()");
    rowsAdapter.clear();
    Content video = ContentBrowser.getInstance(getActivity()).getLastSelectedContent();
    if (video != null) {
        String playlistId = video.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID);
        ContentContainer playlist = ContentBrowser.getInstance(getActivity()).getPlayList(playlistId);
        if (playlist == null) {
            isDataLoaded = true;
            mCallback.onItemSelected(video, null, -1, 0);
            Handler handler = new Handler();
            handler.postDelayed(() -> {
                LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent(BROADCAST_DATA_LOADED));
            }, 1000L);
            return;
        }
        CardPresenter cardPresenter = new CardPresenter();
        PosterCardPresenter posterCardPresenter = new PosterCardPresenter();
        HeaderItem header = new HeaderItem(0, playlist.getName());
        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
        if (playlist.getExtraStringValue(ContentContainer.EXTRA_THUMBNAIL_LAYOUT).equals("poster")) {
            listRowAdapter = new ArrayObjectAdapter(posterCardPresenter);
        }
        if (playlist.getContents() != null) {
            try {
                for (Content content : playlist.getContents()) {
                    if (playlist.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0 && playlist.getContents().indexOf(content) == playlist.getContentCount() - 1) {
                        content.setExtraValue(ContentBrowser.NEXT_PAGE, true);
                        content.setExtraValue(Content.EXTRA_PLAYLIST_ID, playlist.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
                    }
                    listRowAdapter.add(content);
                }
            } catch (Exception e) {
            }
        }
        rowsAdapter.add(new ListRow(header, listRowAdapter));
        isDataLoaded = true;
    }
}
Also used : Content(com.amazon.android.model.content.Content) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) ContentContainer(com.amazon.android.model.content.ContentContainer) Handler(android.os.Handler) Intent(android.content.Intent) HeaderItem(androidx.leanback.widget.HeaderItem) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 62 with Content

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

the class ZypePlaylistContentBrowseFragment method loadRootContentContainer.

private void loadRootContentContainer(ArrayObjectAdapter rowsAdapter) {
    Log.d(TAG, "loadRootContentContainer()");
    rowsAdapter.clear();
    ContentContainer rootContentContainer = ContentBrowser.getInstance(getActivity()).getLastSelectedContentContainer();
    boolean isMyLibrary = rootContentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID);
    boolean isFavorites = rootContentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG).equals(ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID);
    CardPresenter cardPresenter = new CardPresenter();
    PosterCardPresenter posterCardPresenter = new PosterCardPresenter();
    for (ContentContainer contentContainer : rootContentContainer.getContentContainers()) {
        if (isMyLibrary && contentContainer.getContents().isEmpty() && isDataLoaded) {
            dialogError = ErrorDialogFragment.newInstance(getActivity(), ErrorUtils.ERROR_CATEGORY.ZYPE_MY_LIBRARY_ERROR_EMPTY, (ErrorDialogFragment.ErrorDialogFragmentListener) getActivity());
            dialogError.show(getFragmentManager(), ErrorDialogFragment.FRAGMENT_TAG_NAME);
            break;
        }
        if (isFavorites) {
            if (contentContainer.getContents().isEmpty() && ContentBrowser.getInstance(getActivity()).isFavoritesLoaded()) {
                showEmptyFavorites();
                break;
            }
        }
        HeaderItem header = new HeaderItem(0, contentContainer.getName());
        ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(cardPresenter);
        if (contentContainer.getExtraStringValue(ContentContainer.EXTRA_THUMBNAIL_LAYOUT).equals("poster")) {
            listRowAdapter = new ArrayObjectAdapter(posterCardPresenter);
        }
        for (ContentContainer innerContentContainer : contentContainer.getContentContainers()) {
            listRowAdapter.add(innerContentContainer);
        }
        for (Content content : contentContainer.getContents()) {
            listRowAdapter.add(content);
        }
        if (isMyLibrary) {
            if (rootContentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
                PlaylistAction action = new PlaylistAction();
                action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
                listRowAdapter.add(action);
            }
        } else if (isFavorites) {
        } else {
            if (contentContainer.getExtraValueAsInt(ExtraKeys.NEXT_PAGE) > 0) {
                PlaylistAction action = new PlaylistAction();
                action.setAction(ContentBrowser.NEXT_PAGE).setIconResourceId(com.amazon.android.contentbrowser.R.drawable.ic_add_white_48dp).setLabel1(getString(R.string.action_load_more));
                action.setExtraValue(PlaylistAction.EXTRA_PLAYLIST_ID, contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG));
                listRowAdapter.add(action);
            }
        }
        rowsAdapter.add(new ListRow(header, listRowAdapter));
    }
    // addSettingsActionsToRowAdapter(rowsAdapter);
    // isDataLoaded = false;
    addStubRow(rowsAdapter);
}
Also used : PlaylistAction(com.amazon.android.model.PlaylistAction) Content(com.amazon.android.model.content.Content) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) CardPresenter(com.amazon.android.tv.tenfoot.presenter.CardPresenter) SettingsCardPresenter(com.amazon.android.tv.tenfoot.presenter.SettingsCardPresenter) PosterCardPresenter(com.amazon.android.tv.tenfoot.presenter.PosterCardPresenter) ContentContainer(com.amazon.android.model.content.ContentContainer) HeaderItem(androidx.leanback.widget.HeaderItem) ArrayObjectAdapter(androidx.leanback.widget.ArrayObjectAdapter) ListRow(androidx.leanback.widget.ListRow)

Example 63 with Content

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

the class BuyVideoActivity method checkVideoEntitlement.

private void checkVideoEntitlement() {
    if (ZypeConfiguration.isUniversalTVODEnabled(this)) {
        Content content = contentBrowser.getLastSelectedContent();
        ContentContainer playlist = ContentBrowser.getInstance(this).getRootContentContainer().findContentContainerById(content.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID));
        if (content.getExtraValueAsBoolean(Content.EXTRA_PURCHASE_REQUIRED) || (playlist != null && playlist.getExtraValueAsBoolean(ContentContainer.EXTRA_PURCHASE_REQUIRED))) {
            String accessToken = Preferences.getString(ZypeAuthentication.ACCESS_TOKEN);
            HashMap<String, String> params = new HashMap<>();
            params.put(ZypeApi.ACCESS_TOKEN, accessToken);
            ZypeApi.getInstance().getApi().checkVideoEntitlement(content.getId(), params).enqueue(new Callback<ResponseBody>() {

                @Override
                public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                    Log.i(TAG, "checkVideoEntitlement(): code=" + response.code());
                    if (response.isSuccessful()) {
                        content.setExtraValue(Content.EXTRA_ENTITLED, true);
                        closeScreen();
                        contentBrowser.actionTriggered(BuyVideoActivity.this, contentBrowser.getLastSelectedContent(), ContentBrowser.CONTENT_ACTION_WATCH_NOW, null, null);
                    } else {
                        content.setExtraValue(Content.EXTRA_ENTITLED, false);
                    }
                }

                @Override
                public void onFailure(Call<ResponseBody> call, Throwable t) {
                    Log.e(TAG, "checkVideoEntitlement(): failed");
                }
            });
        }
    }
}
Also used : HashMap(java.util.HashMap) Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) ResponseBody(okhttp3.ResponseBody)

Example 64 with Content

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

the class BuyVideoActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_buy_video);
    contentBrowser = ContentBrowser.getInstance(this);
    layoutConfirm = (LinearLayout) findViewById(R.id.layoutConfirm);
    textVideo = (TextView) findViewById(R.id.textVideo);
    layoutLogin = (LinearLayout) findViewById(R.id.layoutLogin);
    buttonLogin = (Button) findViewById(R.id.buttonLogin);
    buttonLogin.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onLogin();
        }
    });
    layoutLoggedIn = (LinearLayout) findViewById(R.id.layoutLoggeIn);
    textConsumerEmail = (TextView) findViewById(R.id.textConsumerEmail);
    buttonConfirm = (Button) findViewById(R.id.buttonConfirm);
    buttonConfirm.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onConfirm();
        }
    });
    buttonRestore = (Button) findViewById(R.id.buttonRestore);
    buttonRestore.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onRestore();
        }
    });
    buttonCancel = (Button) findViewById(R.id.buttonCancel);
    buttonCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onCancel();
        }
    });
    Set<String> skuSet;
    if (getIntent().getExtras() != null && getIntent().getExtras().containsKey(ExtraKeys.PLAYLIST_ID)) {
        // Buy playlist
        mode = MODE_PLAYLIST;
        try {
            Content content = ContentBrowser.getInstance(this).getLastSelectedContent();
            ContentContainer playlist = contentBrowser.getRootContentContainer().findContentContainerById(content.getExtraValueAsString(Content.EXTRA_PLAYLIST_ID));
            skuSet = ContentBrowser.getInstance(this).getPurchaseHelper().getPlaylistSKU(playlist);
            ContentBrowser.getInstance(this).getPurchaseHelper().handleProductsChain(this, skuSet);
        } catch (Exception e) {
        // TODO: Handle error
        }
    } else {
        // Buy video
        mode = MODE_VIDEO;
        // ContentBrowser.getInstance(this).getPurchaseHelper().handleProductsChain(this, skuSet);
        try {
            Content video = ContentBrowser.getInstance(this).getLastSelectedContent();
            skuSet = ContentBrowser.getInstance(this).getPurchaseHelper().getVideoSku(video);
            ContentBrowser.getInstance(this).getPurchaseHelper().handleProductsChain(this, skuSet);
        } catch (Exception e) {
        // TODO: Handle error
        }
    }
    updateViews();
    bindViews();
}
Also used : Content(com.amazon.android.model.content.Content) ContentContainer(com.amazon.android.model.content.ContentContainer) View(android.view.View) TextView(android.widget.TextView)

Example 65 with Content

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

the class PlaybackActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /* Zype, Evgney Cherkasov */
    if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
        CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
    }
    // flag for onResume to know this is being called at activity creation
    mResumeOnCreation = true;
    // Create video position tracking handler.
    mVideoPositionTrackingHandler = new Handler();
    // Create a runnable for video position tracking.
    mVideoPositionTrackingRunnable = new Runnable() {

        @Override
        public void run() {
            try {
                // If player exists and playing then set video position to ads implementation.
                if (mPlayer != null && isPlaying()) {
                    if (mAdsImplementation != null) {
                        mAdsImplementation.setCurrentVideoPosition(mPlayer.getCurrentPosition());
                    }
                }
            } catch (Exception e) {
                Log.e(TAG, "Video position tracking failed.", e);
            }
            mVideoPositionTrackingHandler.postDelayed(this, VIDEO_POSITION_TRACKING_POLL_TIME_MS);
        }
    };
    // Trigger GC to clean up prev player.
    // In regular Java vm this is not advised but for Android we need this.
    // This will let things going as CC became a must and this code will be handled out of
    // TenFootUI in a different way.
    System.gc();
    setContentView(R.layout.playback_controls);
    mWindow = getWindow();
    mProgressBar = (ProgressBar) findViewById(R.id.playback_progress);
    TextView messageTextView = (TextView) findViewById(R.id.autoplayMessage);
    messageTextView.setText(getString(R.string.autoplay_message));
    CalligraphyUtils.applyFontToTextView(TenFootApp.getInstance(), messageTextView, ConfigurationManager.getInstance(this).getTypefacePath(ConfigurationConstants.BOLD_FONT));
    messageView = findViewById(R.id.messageView);
    mPlaybackOverlayFragment = (PlaybackOverlayFragment) getFragmentManager().findFragmentById(R.id.playback_controls_fragment);
    mSelectedContent = (Content) getIntent().getSerializableExtra(Content.class.getSimpleName());
    isAutoPlay = getIntent().getBooleanExtra(SHOW_PLAYLIST_AUTOPLAY, false);
    if (mSelectedContent == null || TextUtils.isEmpty(mSelectedContent.getUrl())) {
        AnalyticsHelper.trackError(TAG, "Received an Intent to play content without a " + "content object or content URL");
        finish();
    }
    loadViews();
    createPlayerAndInitializeListeners();
    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mCaptioningHelper = new CaptioningHelper(this, mSubtitleLayout);
    mCurrentPlaybackPosition = 0;
    mTransportControlsUpdateHandler = new Handler(Looper.getMainLooper());
    mContinualFwdUpdater = new ContinualFwdUpdater();
    mContinualRewindUpdater = new ContinualRewindUpdater();
    mIsLongPress = false;
    mIsNetworkError = false;
    // Auto-play the selected content.
    mAutoPlay = true;
    // initialize the media session
    initMediaSession();
    mCaptioningHelper = new CaptioningHelper(this, mSubtitleLayout);
    mCaptioningChangeListener = new CaptioningManager.CaptioningChangeListener() {

        @Override
        public void onEnabledChanged(boolean enabled) {
            Log.d(TAG, "onEnabledChanged: " + enabled);
            super.onEnabledChanged(enabled);
            if (mCaptioningHelper.useGlobalSetting()) {
                mIsClosedCaptionEnabled = enabled;
                modifyClosedCaptionState(mIsClosedCaptionEnabled);
            }
        }

        @Override
        public void onUserStyleChanged(@NonNull CaptioningManager.CaptionStyle userStyle) {
            Log.d(TAG, "onUserStyleChanged");
            super.onUserStyleChanged(userStyle);
            mSubtitleLayout.setStyle(CaptionStyleCompat.createFromCaptionStyle(userStyle));
        }

        @Override
        public void onLocaleChanged(Locale locale) {
            Log.d(TAG, "onLocaleChanged");
            super.onLocaleChanged(locale);
        }

        @Override
        public void onFontScaleChanged(float fontScale) {
            Log.d(TAG, "onFontScaleChanged");
            super.onFontScaleChanged(fontScale);
            mSubtitleLayout.setFractionalTextSize(fontScale * SubtitleLayout.DEFAULT_TEXT_SIZE_FRACTION);
        }
    };
    mCaptioningHelper.setCaptioningManagerListener(mCaptioningChangeListener);
}
Also used : Locale(java.util.Locale) Handler(android.os.Handler) CookieHandler(java.net.CookieHandler) CaptioningHelper(com.amazon.android.uamp.helper.CaptioningHelper) CaptioningManager(android.view.accessibility.CaptioningManager) Content(com.amazon.android.model.content.Content) TextView(android.widget.TextView)

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