use of com.zype.fire.api.Model.VideoData in project zype-firebuilder by zype.
the class ZypeSearchManager method onSearchRequested.
@Override
public void onSearchRequested(String query, ISearchResult iSearchResult) {
HashMap<String, String> params = new HashMap<>();
params.put(ZypeApi.APP_KEY, ZypeSettings.APP_KEY);
params.put(ZypeApi.PER_PAGE, String.valueOf(ZypeApi.PER_PAGE_DEFAULT));
params.put(ZypeApi.PLAYLIST_ID_INCLUSIVE, ZypeConfiguration.getRootPlaylistId(context));
params.put(ZypeApi.QUERY, query);
ZypeApi.getInstance().getApi().getVideos(1, params).enqueue(new Callback<VideosResponse>() {
@Override
public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
if (response.isSuccessful()) {
if (!response.body().videoData.isEmpty()) {
Log.d(TAG, "onResponse(): size=" + response.body().videoData.size());
for (VideoData videoData : response.body().videoData) {
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = "";
videoData.playerUrl = "null";
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String feed = gson.toJson(response.body().videoData);
Subscription subscription = getSearchContentsObservable(feed, iSearchResult).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
}, throwable -> {
}, () -> {
iSearchResult.onSearchResult(null, true);
});
} else {
Log.d(TAG, "onResponse(): No videos found");
iSearchResult.onSearchResult(null, true);
}
} else {
Log.d(TAG, "onResponse(): Error: " + response.message());
iSearchResult.onSearchResult(null, true);
}
}
@Override
public void onFailure(Call<VideosResponse> call, Throwable t) {
iSearchResult.onSearchResult(null, true);
}
});
}
use of com.zype.fire.api.Model.VideoData in project zype-firebuilder by zype.
the class ContentLoader method loadContentForContentContainer.
// TODO: Move 'loadPlaylistVideos()' from 'ContentBrowser' to here,
// - update definition of 'loadPlaylistVideos' to use listener
// - update all calls of 'loadPlaylistVideos' with listeners instead of listening to broadcast receivers
// for updating content with result of this function
// - replace all calls of 'loadContentForContentContainer' function with 'loadPlaylistVideos'
public void loadContentForContentContainer(ContentContainer contentContainer, Context context, ILoadContentForContentContainer callback) {
// NavigatorModel.GlobalRecipes recipe = mNavigator.getNavigatorModel().getGlobalRecipes().get(0);
// Recipe dataLoaderRecipeForContents = recipe.getContents().dataLoaderRecipe;
// Recipe dynamicParserRecipeForContents = recipe.getContents().dynamicParserRecipe;
//
HashMap<String, String> params = new HashMap<>();
params.put(ZypeApi.APP_KEY, ZypeSettings.APP_KEY);
params.put(ZypeApi.PER_PAGE, String.valueOf(ZypeApi.PER_PAGE_DEFAULT));
ZypeApi.getInstance().getApi().getPlaylistVideos(contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG), 1, params).enqueue(new Callback<VideosResponse>() {
@Override
public void onResponse(Call<VideosResponse> call, Response<VideosResponse> response) {
if (response.isSuccessful()) {
if (response.body().pagination.current == response.body().pagination.pages) {
contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, -1);
} else {
contentContainer.setExtraValue(ExtraKeys.NEXT_PAGE, response.body().pagination.next);
}
if (!response.body().videoData.isEmpty()) {
Log.d(TAG, "loadContentForContentContainer(): onResponse(): size=" + response.body().videoData.size());
for (VideoData videoData : response.body().videoData) {
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = (String) contentContainer.getExtraStringValue(Recipe.KEY_DATA_TYPE_TAG);
videoData.playerUrl = "null";
}
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String feed = gson.toJson(response.body().videoData);
// TODO: Rename the recipe file
Recipe recipe = Recipe.newInstance(context, "recipes/ZypeSearchContentsRecipe.json");
Subscription subscription = getContentsForContentContainerObservable(feed, recipe, contentContainer).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
}, throwable -> {
if (contentContainer.getContentCount() > 0) {
callback.onContentsLoaded();
}
}, () -> {
callback.onContentsLoaded();
});
// mCompositeSubscription.add(subscription);
}
} else {
// TODO: Handle error
}
}
@Override
public void onFailure(Call<VideosResponse> call, Throwable t) {
// TODO: Handle exception
}
});
}
use of com.zype.fire.api.Model.VideoData in project zype-firebuilder by zype.
the class ZypeDataDownloader method fetchData.
/**
* Fetches the {@link Data} for this data downloader.
*
* @param dataLoadRecipe The data load recipe.
* @return The downloaded {@link Data}.
* @throws Exception if there was an error while fetching the data.
*/
@Override
protected Data fetchData(Recipe dataLoadRecipe) throws Exception {
Log.d(TAG, "fetchData(): Started");
AppData appData = loadAppConfiguration();
Log.d(TAG, "fetchData(): App configuration loaded");
ZypeConfiguration.update(appData, mContext);
loadZobjectContents();
List<PlaylistData> playlists = loadPlaylists();
Log.d(TAG, "fetchData(): Playlists loaded");
addFavoritesPlaylist(playlists);
if (ZypeSettings.LIBRARY_ENABLED) {
addMyLibraryPlaylists(playlists);
}
// Result data
JSONArray jsonCategories = new JSONArray();
JSONArray jsonContents = new JSONArray();
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
for (PlaylistData playlistData : playlists) {
if (TextUtils.isEmpty(playlistData.description)) {
playlistData.description = " ";
}
// Skip playlist that are not direct child of the root playlist
if (TextUtils.isEmpty(playlistData.parentId) || !playlistData.parentId.equals(ZypeConfiguration.getRootPlaylistId(mContext))) {
continue;
}
if (playlistData.playlistItemCount > 0) {
Log.d(TAG, "fetchData(): Loading videos for " + playlistData.title);
VideosResponse videosResponse = ZypeDataDownloaderHelper.loadPlaylistVideos(playlistData.id, 1);
if (videosResponse != null) {
for (VideoData videoData : videosResponse.videoData) {
jsonContents.put(new JSONObject(gson.toJson(videoData)));
}
}
}
}
Log.d(TAG, "fetchData(): Videos loaded");
Collections.sort(playlists, (a, b) -> {
Integer valA;
Integer valB;
try {
valA = a.priority;
valB = b.priority;
} catch (Exception e) {
return 0;
}
return valA.compareTo(valB);
});
for (PlaylistData playlistData : playlists) {
String playlistId = playlistData.id;
if (playlistId.equals(ZypeConfiguration.getRootPlaylistId(mContext)) || TextUtils.isEmpty(playlistData.parentId)) {
continue;
}
jsonCategories.put(new JSONObject(gson.toJson(playlistData)));
}
JSONObject jsonResult = new JSONObject();
jsonResult.put("categories", jsonCategories);
jsonResult.put("contents", jsonContents);
Log.d(TAG, "fetchData(): finished");
return Data.createDataForPayload(jsonResult.toString());
}
use of com.zype.fire.api.Model.VideoData in project zype-firebuilder by zype.
the class ZypeDataDownloaderHelper method loadFavoriteVideos.
public static VideosResult loadFavoriteVideos(String favoritesPlaylistId, String consumerId, String accessToken, int page) {
Log.d(TAG, "loadFavoriteVideos(): consumerId=" + consumerId);
VideosResult result = new VideosResult();
result.nextPage = page;
boolean loadNext = true;
while (loadNext) {
VideoFavoritesResponse response = ZypeApi.getInstance().getVideoFavorites(consumerId, accessToken, result.nextPage);
if (response != null) {
Log.d(TAG, "loadFavoriteVideos(): size=" + response.videoFavorites.size());
if (result.videos == null) {
result.videos = new ArrayList<>();
}
if (response.pagination.current >= response.pagination.pages) {
result.nextPage = -1;
} else {
result.nextPage = response.pagination.next;
}
for (VideoFavoriteData data : response.videoFavorites) {
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 = favoritesPlaylistId;
videoData.playerUrl = "null";
videoData.videoFavoriteId = data.id;
result.videos.add(videoData);
} else {
Log.e(TAG, "loadFavoriteVideos(): error loading video, id=" + data.videoId);
}
}
} else {
Log.e(TAG, "loadFavoriteVideos(): failed");
return null;
}
// Load all favorites
loadNext = !(result.nextPage == -1);
}
return result;
}
use of com.zype.fire.api.Model.VideoData in project zype-firebuilder by zype.
the class ZypeDataDownloaderHelper method loadVideos.
public static VideosResult loadVideos(List<String> videoIds, String playlistId) {
Log.d(TAG, "loadVideos(): ");
VideosResult result = new VideosResult();
result.videos = new ArrayList<>();
result.nextPage = -1;
for (String videoId : videoIds) {
VideoResponse responseVideo = ZypeApi.getInstance().getVideo(videoId);
if (responseVideo != null) {
VideoData videoData = responseVideo.videoData;
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
videoData.playlistId = playlistId;
videoData.playerUrl = "null";
videoData.videoFavoriteId = null;
result.videos.add(videoData);
} else {
Log.e(TAG, "loadFavoriteVideos(): error loading video, id=" + videoId);
return null;
}
}
return result;
}
Aggregations