Commit 41669ad6 by pye52

Merge branch 'new_master' into new_for_phone

# Conflicts:
#	app/src/main/java/com/bgycc/smartcanteen/MainActivity.java
parents 9dea0b3b 48844894
...@@ -8,7 +8,7 @@ android { ...@@ -8,7 +8,7 @@ android {
minSdkVersion 22 minSdkVersion 22
targetSdkVersion 22 targetSdkVersion 22
versionCode 13 versionCode 13
versionName "1.3.2" versionName "1.3.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk { ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips" abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
......
...@@ -140,7 +140,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -140,7 +140,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
msg = String.format(getString(R.string.connect_connecting), networkType); msg = String.format(getString(R.string.connect_connecting), networkType);
break; break;
case ConnectState.CONNECTED: case ConnectState.CONNECTED:
msg = String.format(getString(R.string.connect_connected), networkType); msg = String.format(getString(R.string.connect_connected), event.getHost(), networkType);
// socket链接成功后刷新wifi及eth的ip地址信息 // socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo(); refreshEthInfo();
refreshWifiInfo(); refreshWifiInfo();
...@@ -149,7 +149,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -149,7 +149,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
msg = String.format(getString(R.string.connect_reconnecting), networkType); msg = String.format(getString(R.string.connect_reconnecting), networkType);
break; break;
case ConnectState.CHANGE_NETWORK: case ConnectState.CHANGE_NETWORK:
msg = String.format(getString(R.string.connect_change_network), networkType); msg = String.format(getString(R.string.connect_change_network), event.getHost(), networkType);
break; break;
default: default:
msg = ""; msg = "";
...@@ -213,20 +213,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -213,20 +213,23 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
case QRCodeState.SUCCESS: case QRCodeState.SUCCESS:
TTSHelper.speak("beep"); TTSHelper.speak("beep");
PayData data = event.getData(); PayData data = event.getData();
if (data == null) { if (data != null) {
LogUtils.w(TAG, "扫码成功,但任务创建失败"); if (SCWebSocketClient.getInstance().isOpen()) {
return; payOnlineViewModel.exec(data);
} } else {
if (SCWebSocketClient.getInstance().isOpen()) { payOfflineViewModel.exec(data);
payOnlineViewModel.exec(data); }
} else {
payOfflineViewModel.exec(data);
} }
if (debugVs != null) return; if (debugVs != null) return;
String msg = String.format(Locale.getDefault(), getString(R.string.qrcode_text), data.getPayCode()); String msg;
if (data.getTerminalType() != null) { if (data != null) {
msg += String.format(Locale.getDefault(), getString(R.string.terminal_type_text), data.getTerminalType()); msg = String.format(Locale.getDefault(), getString(R.string.qrcode_text), data.getPayCode());
if (data.getTerminalType() != null) {
msg += String.format(Locale.getDefault(), getString(R.string.terminal_type_text), data.getTerminalType());
}
} else {
msg = String.format(Locale.getDefault(), getString(R.string.qrcode_text), event.getMessage());
} }
qrCodeText.setText(msg); qrCodeText.setText(msg);
break; break;
......
...@@ -49,6 +49,7 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -49,6 +49,7 @@ public class SCWebSocketClient extends WebSocketClient {
private Gson gson; private Gson gson;
private String deviceSN; private String deviceSN;
private URI host;
private ScheduledFuture<?> heartbeatFuture; private ScheduledFuture<?> heartbeatFuture;
private ScheduledFuture<?> reconnectFuture; private ScheduledFuture<?> reconnectFuture;
private boolean forceStop = false; private boolean forceStop = false;
...@@ -85,6 +86,7 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -85,6 +86,7 @@ public class SCWebSocketClient extends WebSocketClient {
private SCWebSocketClient(URI serverUri, String deviceSN, Gson gson) { private SCWebSocketClient(URI serverUri, String deviceSN, Gson gson) {
super(serverUri); super(serverUri);
this.host = serverUri;
this.gson = gson; this.gson = gson;
this.deviceSN = deviceSN; this.deviceSN = deviceSN;
LogUtils.d(TAG, "WebSocket初始化, 服务器地址: " + serverUri.toString() + ", 设备SN号: " + deviceSN); LogUtils.d(TAG, "WebSocket初始化, 服务器地址: " + serverUri.toString() + ", 设备SN号: " + deviceSN);
...@@ -136,7 +138,7 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -136,7 +138,7 @@ public class SCWebSocketClient extends WebSocketClient {
@Override @Override
public void onOpen(ServerHandshake data) { public void onOpen(ServerHandshake data) {
connectState.postValue(new ConnectState(ConnectState.CONNECTED)); connectState.postValue(new ConnectState(ConnectState.CONNECTED, host.toString()));
LogUtils.d(TAG, "已链接服务器, \n" + LogUtils.d(TAG, "已链接服务器, \n" +
"http状态: " + data.getHttpStatus() + "\n" + "http状态: " + data.getHttpStatus() + "\n" +
"http状态消息:" + data.getHttpStatusMessage()); "http状态消息:" + data.getHttpStatusMessage());
...@@ -219,7 +221,7 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -219,7 +221,7 @@ public class SCWebSocketClient extends WebSocketClient {
} }
lastSwitchTime = currentTime; lastSwitchTime = currentTime;
connectState.postValue(new ConnectState(ConnectState.CHANGE_NETWORK)); connectState.postValue(new ConnectState(ConnectState.CHANGE_NETWORK, host.toString()));
NetworkUtils.switchNetwork(callback); NetworkUtils.switchNetwork(callback);
} }
...@@ -242,7 +244,7 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -242,7 +244,7 @@ public class SCWebSocketClient extends WebSocketClient {
private Runnable reconnectRunnable = () -> { private Runnable reconnectRunnable = () -> {
LogUtils.d(TAG, "开始尝试重连"); LogUtils.d(TAG, "开始尝试重连");
connectState.postValue(new ConnectState(ConnectState.RECONNECTING)); connectState.postValue(new ConnectState(ConnectState.RECONNECTING, host.toString()));
for (SCWebSocketListener l : listener) { for (SCWebSocketListener l : listener) {
l.onReconnect(); l.onReconnect();
} }
......
...@@ -18,11 +18,17 @@ public class ConnectState { ...@@ -18,11 +18,17 @@ public class ConnectState {
} }
private @CONNECT_STATE int state; private @CONNECT_STATE int state;
private String host;
public ConnectState(@CONNECT_STATE int state) { public ConnectState(@CONNECT_STATE int state) {
this.state = state; this.state = state;
} }
public ConnectState(@CONNECT_STATE int state, String host) {
this.state = state;
this.host = host;
}
public int getState() { public int getState() {
return state; return state;
} }
...@@ -31,23 +37,33 @@ public class ConnectState { ...@@ -31,23 +37,33 @@ public class ConnectState {
this.state = state; this.state = state;
} }
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
ConnectState that = (ConnectState) o; ConnectState that = (ConnectState) o;
return state == that.state; return state == that.state &&
Objects.equals(host, that.host);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(state); return Objects.hash(state, host);
} }
@Override @Override
public String toString() { public String toString() {
return "ConnectState{" + return "ConnectState{" +
"state=" + state + "state=" + state +
", host='" + host + '\'' +
'}'; '}';
} }
} }
...@@ -17,17 +17,22 @@ public class QRCodeState { ...@@ -17,17 +17,22 @@ public class QRCodeState {
public @interface QRCODE_STATE { public @interface QRCODE_STATE {
} }
private @QRCODE_STATE private @QRCODE_STATE int state;
int state;
private PayData data; private PayData data;
private String message;
public QRCodeState(@QRCODE_STATE int state) { public QRCodeState(@QRCODE_STATE int state) {
this(state, null); this(state, null, "");
} }
public QRCodeState(@QRCODE_STATE int state, PayData data) { public QRCodeState(@QRCODE_STATE int state, String message) {
this(state, null, message);
}
public QRCodeState(@QRCODE_STATE int state, PayData data, String message) {
this.state = state; this.state = state;
this.data = data; this.data = data;
this.message = message;
} }
public int getState() { public int getState() {
...@@ -46,18 +51,27 @@ public class QRCodeState { ...@@ -46,18 +51,27 @@ public class QRCodeState {
this.data = data; this.data = data;
} }
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
QRCodeState that = (QRCodeState) o; QRCodeState that = (QRCodeState) o;
return state == that.state && return state == that.state &&
Objects.equals(data, that.data); Objects.equals(data, that.data) &&
Objects.equals(message, that.message);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(state, data); return Objects.hash(state, data, message);
} }
@Override @Override
...@@ -65,6 +79,7 @@ public class QRCodeState { ...@@ -65,6 +79,7 @@ public class QRCodeState {
return "QRCodeState{" + return "QRCodeState{" +
"state=" + state + "state=" + state +
", data=" + data + ", data=" + data +
", message='" + message + '\'' +
'}'; '}';
} }
} }
...@@ -108,8 +108,9 @@ public class QRCodeViewModel extends ViewModel { ...@@ -108,8 +108,9 @@ public class QRCodeViewModel extends ViewModel {
String action = jsonObject.get(RESPONSE_ACTION).getAsString(); String action = jsonObject.get(RESPONSE_ACTION).getAsString();
Command command = new Command(scanData, action); Command command = new Command(scanData, action);
commandRepository.insertCommand(command); commandRepository.insertCommand(command);
LogUtils.d(TAG, "扫码结果: " + command.toString());
// 任务写入数据库成功后,主动发送一次IDLE,以重置界面提示语 // 任务写入数据库成功后,主动发送一次IDLE,以重置界面提示语
qrCodeState.postValue(new QRCodeState(QRCodeState.IDLE)); qrCodeState.postValue(new QRCodeState(QRCodeState.SUCCESS, scanData));
againDelay(); againDelay();
} else { } else {
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED)); qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
...@@ -124,7 +125,7 @@ public class QRCodeViewModel extends ViewModel { ...@@ -124,7 +125,7 @@ public class QRCodeViewModel extends ViewModel {
LogUtils.e(TAG, "数据库插入失败: " + newPay.toString()); LogUtils.e(TAG, "数据库插入失败: " + newPay.toString());
} }
LogUtils.d(TAG, "扫码结果: " + newPay.toString()); LogUtils.d(TAG, "扫码结果: " + newPay.toString());
qrCodeState.postValue(new QRCodeState(QRCodeState.SUCCESS, newPay)); qrCodeState.postValue(new QRCodeState(QRCodeState.SUCCESS, newPay, newPay.getPayCode()));
}; };
private void againDelay() { private void againDelay() {
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<string name="connect_offline">%s 未连接</string> <string name="connect_offline">%s 未连接</string>
<string name="connect_connecting">%s 正在连接…</string> <string name="connect_connecting">%s 正在连接…</string>
<string name="connect_connected">Socket已连接,网络类型: %s</string> <string name="connect_connected">服务器: %s,网络类型: %s</string>
<string name="connect_reconnecting">%s 正在重连…</string> <string name="connect_reconnecting">服务器: %s,正在重连… %s</string>
<string name="connect_change_network">%s 正在切换…</string> <string name="connect_change_network">%s 正在切换…</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment