Search in sources :

Example 1 with VideoEntitlementData

use of com.zype.fire.api.Model.VideoEntitlementData in project zype-firebuilder by zype.

the class EntitlementsManager method loadEntitlementsSubscription.

Subscription loadEntitlementsSubscription(int page, CompositeSubscription compositeSubscription) {
    return Observable.just(true).subscribeOn(Schedulers.io()).observeOn(Schedulers.newThread()).subscribe(result -> {
        String accessToken = Preferences.getString(ZypeAuthentication.ACCESS_TOKEN);
        VideoEntitlementsResponse response = ZypeApi.getInstance().getVideoEntitlements(accessToken, page, ZypeApi.PER_PAGE_DEFAULT);
        if (response != null) {
            Log.d(TAG, "loadVideoEntitlements(): size=" + response.videoEntitlements.size());
            for (VideoEntitlementData data : response.videoEntitlements) {
                VideoEntitlementsHelper.getInstance().addVideoEntitlement(context, data.videoId, data.createdAt);
            }
            if (response.pagination.current < response.pagination.pages) {
                compositeSubscription.add(loadEntitlementsSubscription(response.pagination.next, compositeSubscription));
            }
        }
    }, throwable -> {
    }, () -> {
    });
}
Also used : VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) VideoEntitlementData(com.zype.fire.api.Model.VideoEntitlementData)

Example 2 with VideoEntitlementData

use of com.zype.fire.api.Model.VideoEntitlementData in project zype-firebuilder by zype.

the class ContentLoader method getMyLibraryVideosObservable.

public Observable<Pair> getMyLibraryVideosObservable(Object contentContainerAsObject) {
    ContentContainer contentContainer = (ContentContainer) contentContainerAsObject;
    ContentContainer rootMyLibrary = getRootContentContainer().findContentContainerByName(ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID);
    int nextPage = rootMyLibrary.getExtraValueAsInt(ExtraKeys.NEXT_PAGE);
    if (nextPage <= 0) {
        Log.e(TAG, "getMyLibraryVideosObservable(): incorrect page: " + nextPage);
        return Observable.just(Pair.create(contentContainerAsObject, ""));
    }
    String accessToken = Preferences.getString(ZypeAuthentication.ACCESS_TOKEN);
    VideoEntitlementsResponse response = ZypeApi.getInstance().getVideoEntitlements(accessToken, nextPage, ZypeApi.PER_PAGE_DEFAULT);
    if (response != null) {
        if (response.pagination.current == response.pagination.pages) {
            rootMyLibrary.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
        } else {
            rootMyLibrary.setExtraValue(ExtraKeys.NEXT_PAGE, response.pagination.next);
        }
        Log.d(TAG, "getMyLibraryVideosObservable(): size=" + response.videoEntitlements.size());
        List<VideoData> videos = new ArrayList<>();
        for (VideoEntitlementData data : response.videoEntitlements) {
            VideoResponse responseVideo = ZypeApi.getInstance().getVideo(data.videoId);
            if (responseVideo != null) {
                VideoData videoData = responseVideo.videoData;
                if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
                    videoData.description = " ";
                }
                videoData.playlistId = contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG);
                videoData.playerUrl = "null";
                videos.add(videoData);
            } else {
                Log.e(TAG, "getMyLibraryVideosObservable(): error loading video, id=" + data.videoId);
            }
        }
        GsonBuilder builder = new GsonBuilder();
        Gson gson = builder.create();
        String feed = gson.toJson(videos);
        return Observable.just(Pair.create(contentContainerAsObject, feed));
    } else {
        Log.e(TAG, "getMyLibraryVideosObservable(): no videos found");
        return Observable.just(Pair.create(contentContainerAsObject, ""));
    }
}
Also used : VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) GsonBuilder(com.google.gson.GsonBuilder) VideoData(com.zype.fire.api.Model.VideoData) ArrayList(java.util.ArrayList) ContentContainer(com.amazon.android.model.content.ContentContainer) Gson(com.google.gson.Gson) VideoEntitlementData(com.zype.fire.api.Model.VideoEntitlementData)

Aggregations

VideoEntitlementData (com.zype.fire.api.Model.VideoEntitlementData)2 VideoEntitlementsResponse (com.zype.fire.api.Model.VideoEntitlementsResponse)2 ContentContainer (com.amazon.android.model.content.ContentContainer)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 VideoData (com.zype.fire.api.Model.VideoData)1 VideoResponse (com.zype.fire.api.Model.VideoResponse)1 ArrayList (java.util.ArrayList)1