Search in sources :

Example 1 with BridgeWarning

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

the class BridgeModel method getWarningData.

@Override
public void getWarningData(final ValueCallBack<ArrayList<BridgeWarning>> callBack) {
    if (Constants.testData) {
        ArrayList<BridgeWarning> temp = new ArrayList<BridgeWarning>();
        temp.add(new BridgeWarning("京津线39号桥梁(中间)梁体应力", null, "3.5N", "2.3N", null, "1", null, null));
        temp.add(new BridgeWarning("京张铁路18号桥梁(中间)梁体裂缝宽度", null, "1.2cm", "1.1cm", null, "2", null, null));
        temp.add(new BridgeWarning("京沪线75号桥梁梁体横向位移", null, "0.6cm", "0.9cm", null, "3", null, null));
        bridgeWarnings = temp;
        callBack.onSuccess(bridgeWarnings);
    } else {
        FormBody formBody = new FormBody.Builder().add("bridgeCode", // 设置参数名称和参数值
        Constants.BRIDGECODE).build();
        Request request = new Request.Builder().post(formBody).url(Constants.getAppBridgeNewOneAlarm).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();
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        bridgeWarnings = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<BridgeWarning>>() {
                        }.getType());
                        callBack.onSuccess(bridgeWarnings);
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) BridgeWarning(itor.topnetwork.com.dxditor.bean.BridgeWarning) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) TypeToken(com.google.gson.reflect.TypeToken)

Aggregations

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