use of com.zype.fire.api.Model.VideosResponse 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.VideosResponse 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.VideosResponse 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.VideosResponse in project zype-firebuilder by zype.
the class ZypeDataDownloaderHelper method loadPlaylistVideos.
public static VideosResponse loadPlaylistVideos(String playlistId, int page) {
Log.d(TAG, "loadPlaylistVideos(): id=" + playlistId);
VideosResponse response = ZypeApi.getInstance().getPlaylistVideos(playlistId, page);
if (response != null) {
Log.d(TAG, "loadPlaylistVideos(): size=" + response.videoData.size());
for (VideoData videoData : response.videoData) {
// because 'description' is mandatory field in the Content model
if (TextUtils.isEmpty(videoData.description) || videoData.description.equals("null")) {
videoData.description = " ";
}
// Add reference to playlist
videoData.playlistId = playlistId;
// Set dummy player url. We get real url before switch to renderer screen
videoData.playerUrl = "null";
}
} else {
Log.e(TAG, "loadPlaylistVideos(): failed");
}
return response;
}
use of com.zype.fire.api.Model.VideosResponse in project zype-firebuilder by zype.
the class ZypeApi method getPlaylistVideos.
public VideosResponse getPlaylistVideos(String playlistId, int page) {
try {
HashMap<String, String> params = new HashMap<>();
params.put(APP_KEY, ZypeSettings.APP_KEY);
params.put(PER_PAGE, String.valueOf(PER_PAGE_DEFAULT));
Response response = apiImpl.getPlaylistVideos(playlistId, page, params).execute();
if (response.isSuccessful()) {
return (VideosResponse) response.body();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Aggregations