Search in sources :

Example 1 with ISearchResult

use of com.amazon.android.search.ISearchResult 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)

Aggregations

Context (android.content.Context)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Content (com.amazon.android.model.content.Content)1 ZypeContentTranslator (com.amazon.android.model.translators.ZypeContentTranslator)1 Recipe (com.amazon.android.recipe.Recipe)1 ISearchResult (com.amazon.android.search.ISearchResult)1 DynamicParser (com.amazon.dynamicparser.DynamicParser)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 VideoData (com.zype.fire.api.Model.VideoData)1 VideosResponse (com.zype.fire.api.Model.VideosResponse)1 ZypeApi (com.zype.fire.api.ZypeApi)1 ZypeConfiguration (com.zype.fire.api.ZypeConfiguration)1 ZypeSettings (com.zype.fire.api.ZypeSettings)1 HashMap (java.util.HashMap)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1 Observable (rx.Observable)1