Search in sources :

Example 1 with AppData

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());
}
Also used : JSONObject(org.json.JSONObject) AppData(com.zype.fire.api.Model.AppData) PlaylistData(com.zype.fire.api.Model.PlaylistData) GsonBuilder(com.google.gson.GsonBuilder) JSONArray(org.json.JSONArray) VideoData(com.zype.fire.api.Model.VideoData) Gson(com.google.gson.Gson) VideosResponse(com.zype.fire.api.Model.VideosResponse)

Example 2 with AppData

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;
}
Also used : AppData(com.zype.fire.api.Model.AppData) AppResponse(com.zype.fire.api.Model.AppResponse)

Aggregations

AppData (com.zype.fire.api.Model.AppData)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 AppResponse (com.zype.fire.api.Model.AppResponse)1 PlaylistData (com.zype.fire.api.Model.PlaylistData)1 VideoData (com.zype.fire.api.Model.VideoData)1 VideosResponse (com.zype.fire.api.Model.VideosResponse)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1