Search in sources :

Example 1 with VideosResponse

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);
        }
    });
}
Also used : Context(android.content.Context) Recipe(com.amazon.android.recipe.Recipe) ZypeContentTranslator(com.amazon.android.model.translators.ZypeContentTranslator) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) TextUtils(android.text.TextUtils) HashMap(java.util.HashMap) Response(retrofit2.Response) GsonBuilder(com.google.gson.GsonBuilder) VideoData(com.zype.fire.api.Model.VideoData) Observable(rx.Observable) Content(com.amazon.android.model.content.Content) DynamicParser(com.amazon.dynamicparser.DynamicParser) ZypeApi(com.zype.fire.api.ZypeApi) ZypeConfiguration(com.zype.fire.api.ZypeConfiguration) Callback(retrofit2.Callback) Gson(com.google.gson.Gson) VideosResponse(com.zype.fire.api.Model.VideosResponse) ZypeSettings(com.zype.fire.api.ZypeSettings) Schedulers(rx.schedulers.Schedulers) ISearchResult(com.amazon.android.search.ISearchResult) Call(retrofit2.Call) Subscription(rx.Subscription) Log(android.util.Log) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) VideoData(com.zype.fire.api.Model.VideoData) VideosResponse(com.zype.fire.api.Model.VideosResponse) Subscription(rx.Subscription)

Example 2 with VideosResponse

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
        }
    });
}
Also used : Arrays(java.util.Arrays) ZypeDataDownloaderHelper(com.amazon.dataloader.datadownloader.ZypeDataDownloaderHelper) VideoFavoriteResponse(com.zype.fire.api.Model.VideoFavoriteResponse) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) GsonBuilder(com.google.gson.GsonBuilder) NavigatorModel(com.amazon.android.navigator.NavigatorModel) PlaylistData(com.zype.fire.api.Model.PlaylistData) Gson(com.google.gson.Gson) VideosResponse(com.zype.fire.api.Model.VideosResponse) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) ExtraKeys(com.amazon.android.model.content.constants.ExtraKeys) ContentContainerTranslator(com.amazon.android.model.translators.ContentContainerTranslator) Log(android.util.Log) ResponseBody(okhttp3.ResponseBody) Preferences(com.amazon.android.utils.Preferences) List(java.util.List) ZypeConfiguration(com.zype.fire.api.ZypeConfiguration) NavigatorModelParser(com.amazon.android.navigator.NavigatorModelParser) Data(com.amazon.utils.model.Data) ZypeSettings(com.zype.fire.api.ZypeSettings) BROADCAST_VIDEO_DETAIL_DATA_LOADED(com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_VIDEO_DETAIL_DATA_LOADED) ZypeContentContainerTranslator(com.amazon.android.model.translators.ZypeContentContainerTranslator) Call(retrofit2.Call) Subscription(rx.Subscription) Context(android.content.Context) Recipe(com.amazon.android.recipe.Recipe) VideoFavoritesHelper(com.amazon.android.contentbrowser.database.helpers.VideoFavoritesHelper) Pair(android.util.Pair) ZypeContentTranslator(com.amazon.android.model.translators.ZypeContentTranslator) Intent(android.content.Intent) LocalBroadcastManager(androidx.localbroadcastmanager.content.LocalBroadcastManager) HashMap(java.util.HashMap) Response(retrofit2.Response) RecentRecord(com.amazon.android.contentbrowser.database.records.RecentRecord) ArrayList(java.util.ArrayList) Observable(rx.Observable) ZypeAuthentication(com.zype.fire.auth.ZypeAuthentication) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) BROADCAST_DATA_LOADED(com.amazon.android.contentbrowser.ContentBrowser.BROADCAST_DATA_LOADED) TextUtils(android.text.TextUtils) VideoData(com.zype.fire.api.Model.VideoData) Content(com.amazon.android.model.content.Content) DynamicParser(com.amazon.dynamicparser.DynamicParser) ZypeApi(com.zype.fire.api.ZypeApi) Callback(retrofit2.Callback) VideoEntitlementData(com.zype.fire.api.Model.VideoEntitlementData) RecentDatabaseHelper(com.amazon.android.contentbrowser.database.helpers.RecentDatabaseHelper) ContentTranslator(com.amazon.android.model.translators.ContentTranslator) DataLoadManager(com.amazon.dataloader.dataloadmanager.DataLoadManager) Navigator(com.amazon.android.navigator.Navigator) ContentContainer(com.amazon.android.model.content.ContentContainer) HashMap(java.util.HashMap) GsonBuilder(com.google.gson.GsonBuilder) Recipe(com.amazon.android.recipe.Recipe) Gson(com.google.gson.Gson) VideoData(com.zype.fire.api.Model.VideoData) VideosResponse(com.zype.fire.api.Model.VideosResponse) Subscription(rx.Subscription)

Example 3 with VideosResponse

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());
}
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 4 with VideosResponse

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

Example 5 with VideosResponse

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;
    }
}
Also used : Response(retrofit2.Response) VideoFavoritesResponse(com.zype.fire.api.Model.VideoFavoritesResponse) ChannelResponse(com.zype.fire.api.Model.ChannelResponse) DevicePinResponse(com.zype.fire.api.Model.DevicePinResponse) VideosResponse(com.zype.fire.api.Model.VideosResponse) AppResponse(com.zype.fire.api.Model.AppResponse) VideoResponse(com.zype.fire.api.Model.VideoResponse) VideoEntitlementsResponse(com.zype.fire.api.Model.VideoEntitlementsResponse) PlaylistsResponse(com.zype.fire.api.Model.PlaylistsResponse) ProgramResponse(com.zype.fire.api.Model.ProgramResponse) AccessTokenResponse(com.zype.fire.api.Model.AccessTokenResponse) ZobjectContentResponse(com.zype.fire.api.Model.ZobjectContentResponse) PlanResponse(com.zype.fire.api.Model.PlanResponse) PlaylistResponse(com.zype.fire.api.Model.PlaylistResponse) AccessTokenInfoResponse(com.zype.fire.api.Model.AccessTokenInfoResponse) ZobjectTopPlaylistResponse(com.zype.fire.api.Model.ZobjectTopPlaylistResponse) ConsumerResponse(com.zype.fire.api.Model.ConsumerResponse) HashMap(java.util.HashMap) IOException(java.io.IOException) VideosResponse(com.zype.fire.api.Model.VideosResponse)

Aggregations

VideosResponse (com.zype.fire.api.Model.VideosResponse)7 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 VideoData (com.zype.fire.api.Model.VideoData)4 HashMap (java.util.HashMap)4 Response (retrofit2.Response)4 Context (android.content.Context)2 TextUtils (android.text.TextUtils)2 Log (android.util.Log)2 Content (com.amazon.android.model.content.Content)2 ContentContainer (com.amazon.android.model.content.ContentContainer)2 ZypeContentTranslator (com.amazon.android.model.translators.ZypeContentTranslator)2 Recipe (com.amazon.android.recipe.Recipe)2 DynamicParser (com.amazon.dynamicparser.DynamicParser)2 AccessTokenInfoResponse (com.zype.fire.api.Model.AccessTokenInfoResponse)2 AccessTokenResponse (com.zype.fire.api.Model.AccessTokenResponse)2 AppResponse (com.zype.fire.api.Model.AppResponse)2 ChannelResponse (com.zype.fire.api.Model.ChannelResponse)2 ConsumerResponse (com.zype.fire.api.Model.ConsumerResponse)2 DevicePinResponse (com.zype.fire.api.Model.DevicePinResponse)2