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