Commit 8f83dd17babfc74a53bda27c6a50ae1df6c09486

Authored by wugian
1 parent 825e8f9e

report open door success,update ft root api

... ... @@ -235,6 +235,13 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
235 235 presenter.load(this);
236 236 Intent intent = new Intent(this, SocketService.class);
237 237 startService(intent);
  238 + new Handler().postDelayed(new Runnable() {
  239 + @Override
  240 + public void run() {
  241 + Log.d("room-info", "test open door report");
  242 + openDoor();
  243 + }
  244 + }, 20 * 1000);
238 245 }
239 246
240 247 @Override
... ... @@ -451,8 +458,11 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
451 458 context.startActivity(intentPlayList1);
452 459 }
453 460
  461 + private RoomStatusInfo roomStatusInfo;
  462 +
454 463 @Override
455 464 public void updateOrderInfo(RoomStatusInfo info) {
  465 + roomStatusInfo = info;
456 466 RoomStatusInfo.DataEntity data = info.getData();
457 467 int durationMinutes = data.getEnd_time() - data.getBegin_time();
458 468 Log.d("CountService", "durationMinutes:" + durationMinutes);
... ... @@ -476,12 +486,39 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
476 486
477 487 }
478 488
  489 + @Override
  490 + public void reportResult(boolean b) {
  491 + reportSuccess = b;
  492 + }
  493 +
  494 + private boolean reportSuccess;
  495 + private int reportCount = 0;
  496 +
  497 + private Runnable reportRunnable = new Runnable() {
  498 + @Override
  499 + public void run() {
  500 + if (reportSuccess || reportCount++ > 5) {
  501 + //success or report 5 times reset status and count
  502 + Log.d("room-info", "reportResult:" + reportSuccess + ",reportCount:" + reportCount);
  503 + reportCount = 0;
  504 + reportSuccess = false;
  505 + return;
  506 + }
  507 + Log.d("room-info", "report the open door status");
  508 + if (roomStatusInfo == null || roomStatusInfo.getData() == null) {
  509 + presenter.reportOpenDoorStatus("123456");
  510 + } else {
  511 + presenter.reportOpenDoorStatus(roomStatusInfo.getData().getOrder_sn());
  512 + }
  513 + handler.postDelayed(this, 10 * 1000);
  514 + }
  515 + };
  516 +
479 517 private RoomQrCodeInfo info;
480 518
481 519 @Override
482 520 public void prepareRoomQrCodeInfo(RoomQrCodeInfo info) {
483 521 this.info = info;
484   -
485 522 }
486 523
487 524 @Override
... ... @@ -967,6 +1004,8 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
967 1004 }
968 1005
969 1006 private void openDoor() {
  1007 + handler.post(reportRunnable);
  1008 +
970 1009 bleBroadcastReceiver.setResponseObj(new GREENCITYBLEProtocolFactory.GREENCITYBleDataWritten() {
971 1010
972 1011 @Override
... ... @@ -981,10 +1020,13 @@ public class MainActivity extends BaseActivity implements IMainView, EventListen
981 1020 intent.setAction(GREENBluetoothLeService.ACTION_OPEN_SUCCESS);
982 1021 intent.putExtra("openrecord", bleOpenRecord);
983 1022 sendBroadcast(intent);
  1023 + Log.d("room-info", "open success");
  1024 + handler.post(reportRunnable);
984 1025 }
985 1026
986 1027 @Override
987 1028 public void writeFailure(String error) {
  1029 + Log.d("room-info", "open failure");
988 1030 bleBroadcastReceiver.setResponseObj(null);
989 1031 Toast.makeText(MainActivity.this, "开门失败," + error, Toast.LENGTH_SHORT).show();
990 1032 }
... ...
... ... @@ -9,4 +9,6 @@ public interface IRoomInfoModel {
9 9 void getRoomStatus(String roomSn, RoomInfoModelImpl.GetRoomStatusListener listener);
10 10
11 11 void getRoomQrCode(String orderSn, RoomInfoModelImpl.GetRoomQrCodeListener listener);
  12 +
  13 + void reportOpenDoorStatus(String orderSn, RoomInfoModelImpl.OpenDoorStatusListener listener);
12 14 }
... ...
... ... @@ -17,10 +17,11 @@ import com.xgimi.gimicinema.application.FangTangApplication;
17 17 * Created by wugian on 2017/4/7
18 18 */
19 19 public class RoomInfoModelImpl implements IRoomInfoModel {
20   - private static final String ROOT_URL = "https://ft.qnbar.cn/develop/";
  20 + private static final String ROOT_URL = "https://ft.qnbar.cn/develop/api/";
21 21 private static final String ROOM_INFO_BY_IMEI_URL = ROOT_URL + "tcp/getRoomInfoByimei?imei=";
22 22 private static final String ROOM_STATUS_BY_ROOM_SN_URL = ROOT_URL + "tcp/getRoomStatus?room_sn=";
23 23 private static final String ROOM_QRCODE_BY_ORDER_SN = ROOT_URL + "tcp/getEndQRCode?order_sn=";
  24 + private static final String ROOM_REPORT_ROOM_STATUS = ROOT_URL + "tcp/tcp/reportRoomStatus?order_sn=";
24 25
25 26 @Override
26 27 public void getRoomInfo(String imei, boolean needUpdate, final GetRoomInfoListener listener) {
... ... @@ -127,6 +128,22 @@ public class RoomInfoModelImpl implements IRoomInfoModel {
127 128 }
128 129
129 130
  131 + @Override
  132 + public void reportOpenDoorStatus(String orderSn, final OpenDoorStatusListener listener) {
  133 + OkHttpClientManager.getAsyn(ROOM_REPORT_ROOM_STATUS + orderSn,
  134 + new OkHttpClientManager.ResultCallback<String>() {
  135 + @Override
  136 + public void onError(Request request, Exception e) {
  137 + listener.onOpenDoorFailure();
  138 + }
  139 +
  140 + @Override
  141 + public void onResponse(String response) {
  142 + listener.onOpenDoorSuccess();
  143 + }
  144 + });
  145 + }
  146 +
130 147 public interface GetRoomInfoListener {
131 148 void onGetRoomInfoSuccess(RoomInfo info);
132 149
... ... @@ -146,4 +163,10 @@ public class RoomInfoModelImpl implements IRoomInfoModel {
146 163
147 164 void onGetRoomQrCodeFailure(WrongMsg wrongMsg);
148 165 }
  166 +
  167 + public interface OpenDoorStatusListener {
  168 + void onOpenDoorSuccess();
  169 +
  170 + void onOpenDoorFailure();
  171 + }
149 172 }
... ...
... ... @@ -64,4 +64,6 @@ public interface IMainView {
64 64 void notifyGetRoomInfo(RoomInfo info);
65 65
66 66 void notifyUpdateRoomInfo(RoomInfo info);
  67 +
  68 + void reportResult(boolean b);
67 69 }
... ...
... ... @@ -231,6 +231,22 @@ public class MainPresenter extends BasePresenter
231 231 });
232 232 }
233 233
  234 + public void reportOpenDoorStatus(String orderSn) {
  235 + roomInfoModel.reportOpenDoorStatus(orderSn, new RoomInfoModelImpl.OpenDoorStatusListener() {
  236 + @Override
  237 + public void onOpenDoorSuccess() {
  238 + mainView.reportResult(true);
  239 + Log.d("room-info", "report success");
  240 + }
  241 +
  242 + @Override
  243 + public void onOpenDoorFailure() {
  244 + mainView.reportResult(false);
  245 + Log.d("room-info", "report failure");
  246 + }
  247 + });
  248 + }
  249 +
234 250 public void getOrderInfo() {
235 251 String imei = SystemUtils.getPid(context, BuildConfig.BUILD_TYPE);
236 252 roomInfoModel.getRoomInfo(imei, false, new RoomInfoModelImpl.GetRoomInfoListener() {
... ...
Please register or login to post a comment