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);
}
}
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);
});
}
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();
}
}
});
}
});
}
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);
}
}
}
}
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);
}
}
Aggregations