use of com.zype.fire.api.Model.AppData 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.AppData in project zype-firebuilder by zype.
the class ZypeDataDownloader method loadAppConfiguration.
private AppData loadAppConfiguration() {
AppData result = new AppData();
AppResponse appResponse = ZypeApi.getInstance().getApp();
if (appResponse != null && appResponse.data != null) {
result = appResponse.data;
}
// TODO: Delete this for release build
result.universalTVOD = null;
return result;
}
Aggregations