Search in sources :

Example 1 with GjxxBean

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

the class MainpageModel method getGjxxData.

@Override
public void getGjxxData(final ValueCallBack<List<GjxxBean>> callBack) {
    gjxxList = new ArrayList<GjxxBean>();
    if (Constants.testData) {
        gjxxList.add(new GjxxBean(1, "已恢复", 11, 0.27f));
        gjxxList.add(new GjxxBean(2, "已处理", 19, 0.46f));
        gjxxList.add(new GjxxBean(0, "告警中", 11, 0.27f));
        callBack.onSuccess(gjxxList);
    } else {
        Request request = new Request.Builder().url(Constants.getAppDeviceAlarmProportion).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("getAppDeviceAlarmProportion:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        gjxxList = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<GjxxBean>>() {
                        }.getType());
                        callBack.onSuccess(gjxxList);
                    } 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) GjxxBean(itor.topnetwork.com.dxditor.bean.GjxxBean)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 GjxxBean (itor.topnetwork.com.dxditor.bean.GjxxBean)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