use of com.zype.fire.api.Model.PlaylistData in project zype-firebuilder by zype.
the class ContentLoader method loadPlayList.
public Observable<ContentContainer> loadPlayList(ContentContainer root, String playListId) {
return Observable.just(playListId).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).flatMap(id -> {
PlaylistData playlistData = ZypeDataDownloaderHelper.loadPlayList(playListId);
if (playlistData != null) {
// need to convert this to a content container
playlistData.parentId = playListId;
HashMap map = new HashMap();
map.put("categories", Arrays.asList(playlistData));
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
String feed = gson.toJson(map);
String[] params = new String[] { playListId };
Recipe recipeDynamicParserContainer = Recipe.newInstance(mContext, "recipes/ZypeCategoriesRecipe.json");
return mDynamicParser.cookRecipeObservable(recipeDynamicParserContainer, feed, null, params).flatMap(o -> {
ContentContainer contentContainer = (ContentContainer) o;
return Observable.just(contentContainer);
});
}
return Observable.error(new Exception("unable to load the playlist"));
});
}
use of com.zype.fire.api.Model.PlaylistData 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.PlaylistData in project zype-firebuilder by zype.
the class ZypeDataDownloader method addMyLibraryPlaylists.
private void addMyLibraryPlaylists(List<PlaylistData> playlists) {
PlaylistData item = new PlaylistData();
item.id = ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID;
item.description = " ";
item.parentId = ZypeConfiguration.getRootPlaylistId(mContext);
item.thumbnailLayout = "landscape";
item.title = ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID;
playlists.add(item);
item = new PlaylistData();
item.id = ZypeSettings.MY_LIBRARY_PLAYLIST_ID;
item.description = " ";
item.parentId = ZypeSettings.ROOT_MY_LIBRARY_PLAYLIST_ID;
item.playlistItemCount = 1;
item.thumbnailLayout = "landscape";
item.title = "Library";
playlists.add(item);
}
use of com.zype.fire.api.Model.PlaylistData in project zype-firebuilder by zype.
the class ZypeDataDownloader method loadPlaylists.
private List<PlaylistData> loadPlaylists() {
List<PlaylistData> result = new ArrayList<>();
int page = 1;
PlaylistsResponse playlistsResponse = ZypeApi.getInstance().getPlaylists(page);
if (playlistsResponse != null && playlistsResponse.response != null) {
result.addAll(playlistsResponse.response);
if (playlistsResponse.pagination != null && playlistsResponse.pagination.pages > 1) {
for (page = playlistsResponse.pagination.next; page <= playlistsResponse.pagination.pages; page++) {
playlistsResponse = ZypeApi.getInstance().getPlaylists(page);
if (playlistsResponse != null && playlistsResponse.response != null) {
result.addAll(playlistsResponse.response);
}
}
}
}
return result;
}
use of com.zype.fire.api.Model.PlaylistData in project zype-firebuilder by zype.
the class ZypeDataDownloader method addFavoritesPlaylist.
private void addFavoritesPlaylist(List<PlaylistData> playlists) {
PlaylistData item = new PlaylistData();
item.id = ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID;
item.description = " ";
item.parentId = ZypeConfiguration.getRootPlaylistId(mContext);
item.thumbnailLayout = "landscape";
item.title = ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID;
playlists.add(item);
item = new PlaylistData();
item.id = ZypeSettings.FAVORITES_PLAYLIST_ID;
// TODO: Use string resources for description and title instead of hardcoded strings
item.description = "Favorites";
item.parentId = ZypeSettings.ROOT_FAVORITES_PLAYLIST_ID;
item.thumbnailLayout = "landscape";
item.title = ZypeSettings.FAVORITES_PLAYLIST_ID;
playlists.add(item);
}
Aggregations