Search in sources :

Example 1 with VideoEntitlementsResponse

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

the class ZypeApi method getVideoEntitlements.

public VideoEntitlementsResponse getVideoEntitlements(String accessToken, int page, int perPage) {
    try {
        HashMap<String, String> params = new HashMap<>();
        params.put(ACCESS_TOKEN, accessToken);
        params.put(PER_PAGE, String.valueOf(perPage));
        params.put("sort", "created_at");
        params.put("order", "desc");
        Response response = apiImpl.getVideoEntitlements(page, params).execute();
        if (response.isSuccessful()) {
            return (VideoEntitlementsResponse) response.body();
        } else {
            return null;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : Response(retrofit2.Response) VideoFavoritesResponse(com.zype.fire.api.Model.VideoFavoritesResponse) ChannelResponse(com.zype.fire.api.Model.ChannelResponse) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) VideosResponse(com.zype.fire.api.Model.VideosResponse) AppResponse(com.zype.fire.api.Model.AppResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) PlaylistsResponse(com.zype.fire.api.Model.PlaylistsResponse) ProgramResponse(com.zype.fire.api.Model.ProgramResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse) ZobjectContentResponse(com.zype.fire.api.Model.ZobjectContentResponse) PlanResponse(com.zype.fire.api.Model.PlanResponse) PlaylistResponse(com.zype.fire.api.Model.PlaylistResponse) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 2 with VideoEntitlementsResponse

use of com.zype.fire.api.Model.VideoEntitlementsResponse 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 3 with VideoEntitlementsResponse

use of com.zype.fire.api.Model.VideoEntitlementsResponse 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

VideoEntitlementsResponse (com.zype.fire.api.Model.VideoEntitlementsResponse)3 VideoEntitlementData (com.zype.fire.api.Model.VideoEntitlementData)2 VideoResponse (com.zype.fire.api.Model.VideoResponse)2 ContentContainer (com.amazon.android.model.content.ContentContainer)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AccessTokenInfoResponse (com.zype.fire.api.Model.AccessTokenInfoResponse)1 AccessTokenResponse (com.zype.fire.api.Model.AccessTokenResponse)1 AppResponse (com.zype.fire.api.Model.AppResponse)1 ChannelResponse (com.zype.fire.api.Model.ChannelResponse)1 ConsumerResponse (com.zype.fire.api.Model.ConsumerResponse)1 DevicePinResponse (com.zype.fire.api.Model.DevicePinResponse)1 PlanResponse (com.zype.fire.api.Model.PlanResponse)1 PlaylistResponse (com.zype.fire.api.Model.PlaylistResponse)1 PlaylistsResponse (com.zype.fire.api.Model.PlaylistsResponse)1 ProgramResponse (com.zype.fire.api.Model.ProgramResponse)1 VideoData (com.zype.fire.api.Model.VideoData)1 VideoFavoritesResponse (com.zype.fire.api.Model.VideoFavoritesResponse)1 VideosResponse (com.zype.fire.api.Model.VideosResponse)1 ZobjectContentResponse (com.zype.fire.api.Model.ZobjectContentResponse)1