RoomInfoModelImpl.java
6.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.xgimi.gimicinema.model;
import android.content.Context;
import android.text.TextUtils;
import com.gimi.common.cinema.model.RoomInfo;
import com.gimi.common.cinema.model.RoomQrCodeInfo;
import com.gimi.common.cinema.model.RoomStatusInfo;
import com.gimi.common.cinema.model.WrongMsg;
import com.gimi.common.cinema.utils.OkHttpClientManager;
import com.gimi.common.cinema.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.squareup.okhttp.Request;
import com.xgimi.gimicinema.application.FangTangApplication;
/**
* Created by wugian on 2017/4/7
*/
public class RoomInfoModelImpl implements IRoomInfoModel {
private static final String ROOT_URL = "https:/hulong.nat123.net/";
private static final String ROOM_INFO_BY_IMEI_URL = ROOT_URL + "tcp/getRoomInfoByimei?imei=";
private static final String ROOM_STATUS_BY_ROOM_SN_URL = ROOT_URL + "tcp/getRoomStatus?room_sn=";
private static final String ROOM_QRCODE_BY_ORDER_SN = ROOT_URL + "tcp/getEndQRCode?order_sn=";
@Override
public void getRoomInfo(String imei, boolean needUpdate, final GetRoomInfoListener listener) {
final Context applicationContext = FangTangApplication.getInstance().getApplicationContext();
final String roomInfoStr = Utils.getString(applicationContext, "room-info");
if (!TextUtils.isEmpty(roomInfoStr)) {
RoomInfo roomInfo1 = new Gson().fromJson(roomInfoStr, RoomInfo.class);
if (roomInfo1 != null) {
listener.onGetRoomInfoSuccess(roomInfo1);
if (!needUpdate) {
return;
}
}
}
OkHttpClientManager.getAsyn(ROOM_INFO_BY_IMEI_URL + imei,
new OkHttpClientManager.ResultCallback<String>() {
@Override
public void onError(Request request, Exception e) {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg(e.getMessage());
listener.onGetRoomInfoFailure(wrongMsg);
}
@Override
public void onResponse(String response) {
RoomInfo roomInfo1 = null;
try {
roomInfo1 = new Gson().fromJson(response, RoomInfo.class);
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
boolean equals = roomInfoStr.equals(response);
if (roomInfo1 != null && !equals) {
Utils.saveString(applicationContext, "room-info", response);
listener.onGetRoomInfoUpdate(roomInfo1);
} else {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg("update-info equal with old:" + equals + "," + response);
listener.onGetRoomInfoFailure(wrongMsg);
}
}
});
}
@Override
public void getRoomStatus(String roomSn, final GetRoomStatusListener listener) {
OkHttpClientManager.getAsyn(ROOM_STATUS_BY_ROOM_SN_URL + roomSn,
new OkHttpClientManager.ResultCallback<String>() {
@Override
public void onError(Request request, Exception e) {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg(e.getMessage());
listener.onGetRoomStatusFailure(wrongMsg);
}
@Override
public void onResponse(String response) {
RoomStatusInfo roomInfo1 = null;
try {
roomInfo1 = new Gson().fromJson(response, RoomStatusInfo.class);
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
if (roomInfo1 != null) {
listener.onGetRoomStatusSuccess(roomInfo1);
} else {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg(response);
listener.onGetRoomStatusFailure(wrongMsg);
}
}
});
}
@Override
public void getRoomQrCode(String orderSn, final GetRoomQrCodeListener listener) {
OkHttpClientManager.getAsyn(ROOM_QRCODE_BY_ORDER_SN + orderSn,
new OkHttpClientManager.ResultCallback<String>() {
@Override
public void onError(Request request, Exception e) {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg(e.getMessage());
listener.onGetRoomQrCodeFailure(wrongMsg);
}
@Override
public void onResponse(String response) {
RoomQrCodeInfo roomInfo1 = null;
try {
roomInfo1 = new Gson().fromJson(response, RoomQrCodeInfo.class);
} catch (JsonSyntaxException e) {
e.printStackTrace();
}
if (roomInfo1 != null) {
listener.onGetRoomQrCodeSuccess(roomInfo1);
} else {
WrongMsg wrongMsg = new WrongMsg();
wrongMsg.setMsg(response);
listener.onGetRoomQrCodeFailure(wrongMsg);
}
}
});
}
public interface GetRoomInfoListener {
void onGetRoomInfoSuccess(RoomInfo info);
void onGetRoomInfoUpdate(RoomInfo info);
void onGetRoomInfoFailure(WrongMsg wrongMsg);
}
public interface GetRoomStatusListener {
void onGetRoomStatusSuccess(RoomStatusInfo info);
void onGetRoomStatusFailure(WrongMsg wrongMsg);
}
public interface GetRoomQrCodeListener {
void onGetRoomQrCodeSuccess(RoomQrCodeInfo info);
void onGetRoomQrCodeFailure(WrongMsg wrongMsg);
}
}