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);
}
});
}
Aggregations