Search in sources :

Example 1 with SearchBean

use of cn.liuyin.manhua.data.bean.SearchBean in project Manhua by ag2s20150909.

the class SearchActivity method search.

public void search(final String kw) {
    new Thread(new Runnable() {

        @Override
        public void run() {
            Gson gson = new Gson();
            SearchResult data = new SearchResult();
            SearchBean d = gson.fromJson(new API().search_1(kw, 1, 100), SearchBean.class);
            data.add(d);
            mHander.obtainMessage(1, data).sendToTarget();
        // String u = HttpTool.search(getApplicationContext(), kw);
        // getHtml(u);
        }
    }).start();
}
Also used : SearchBean(cn.liuyin.manhua.data.bean.SearchBean) Gson(com.google.gson.Gson) SearchResult(cn.liuyin.manhua.data.bean.SearchResult) API(cn.liuyin.manhua.data.api.API)

Example 2 with SearchBean

use of cn.liuyin.manhua.data.bean.SearchBean in project Manhua by ag2s20150909.

the class API method search.

public static SearchBean search(String kw, int page, int pagesize) {
    Gson gson = new Gson();
    SearchBean result = new SearchBean();
    FormBody.Builder buider = new FormBody.Builder();
    buider.add("pageSize", pagesize + "").add("keyword", kw).add("page", page + "");
    FormBody formBody = APIheper.getFormBuider(buider).build();
    String url = host + "/api/book/search";
    Request request = new Request.Builder().post(formBody).url(url).build();
    try {
        Response response = APP.getOkhttpClient().newCall(request).execute();
        if (response.isSuccessful()) {
            result = gson.fromJson(response.body().string(), SearchBean.class);
            return result;
        } else {
            result.code = 1;
            result.success = false;
            result.message = "nessage:" + response.message() + " \ncode:" + response.code();
            return result;
        // return "error:" + response.message() + " errorcode:" + response.code();
        }
    } catch (Exception e) {
        result.code = 1;
        result.success = false;
        result.message = e.getLocalizedMessage();
        return result;
    }
}
Also used : Response(okhttp3.Response) SearchBean(cn.liuyin.manhua.data.bean.SearchBean) FormBody(okhttp3.FormBody) Request(okhttp3.Request) Gson(com.google.gson.Gson)

Aggregations

SearchBean (cn.liuyin.manhua.data.bean.SearchBean)2 Gson (com.google.gson.Gson)2 API (cn.liuyin.manhua.data.api.API)1 SearchResult (cn.liuyin.manhua.data.bean.SearchResult)1 FormBody (okhttp3.FormBody)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1