Search in sources :

Example 1 with SbxxBean

use of itor.topnetwork.com.dxditor.bean.SbxxBean in project Dxditor by kimi2009.

the class MainpageModel method getTestData.

@Override
public void getTestData(final ValueCallBack<List<SbxxBean>> callBack) {
    list = new ArrayList<SbxxBean>();
    if (Constants.testData) {
        list.add(new SbxxBean(0, "", "3"));
        list.add(new SbxxBean(1, "", "57"));
        list.add(new SbxxBean(2, "", "31"));
        callBack.onSuccess(list);
    } else {
        Request request = new Request.Builder().url(Constants.getAppDeviceStausCount).build();
        okHttpClient.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                System.out.println("getAppDeviceStausCount:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        list = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SbxxBean>>() {
                        }.getType());
                        callBack.onSuccess(list);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken) SbxxBean(itor.topnetwork.com.dxditor.bean.SbxxBean)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 SbxxBean (itor.topnetwork.com.dxditor.bean.SbxxBean)1 IOException (java.io.IOException)1 Call (okhttp3.Call)1 Callback (okhttp3.Callback)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 JSONObject (org.json.JSONObject)1