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