Commit fcdb977b by pye52

修复一个在非debug版本下串口读取失败会崩溃的问题(原因是debug布局未Inflate)

parent 48844894
......@@ -116,7 +116,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
initViews();
SCWebSocketClient.getInstance().getConnectStateEvent().observe(this, event -> {
if (debugVs != null) return;
if (debugLayoutIsNotInflate()) return;
String networkType = NetworkUtils.getNetworkType(this);
String msg;
switch (event.getState()) {
......@@ -154,7 +154,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
String log = "支付进度: " + time + " - " + event.getMessage();
LogUtils.file(TAG, log);
if (debugVs != null) return;
if (debugLayoutIsNotInflate()) return;
sendText.setText(log);
break;
case PayOnlineState.SUCCESS:
......@@ -207,7 +207,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
}
if (debugVs != null) return;
if (debugLayoutIsNotInflate()) return;
String msg;
if (data != null) {
msg = String.format(Locale.getDefault(), getString(R.string.qrcode_text), data.getPayCode());
......@@ -224,6 +224,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
qrCodeViewModel.scan();
break;
case QRCodeState.ILLEGAL:
if (debugLayoutIsNotInflate()) return;
message.setVisibility(View.GONE);
sendText.setTextColor(getResources().getColor(R.color.serial_port_error));
sendText.setText(R.string.serial_port_init_failed);
......@@ -264,8 +265,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().tryConnect();
}
private boolean debugLayoutIsNotInflate() {
return debugVs != null;
}
private void toggleDebugLayout() {
if (debugVs != null) {
if (debugLayoutIsNotInflate()) {
inflateDebugLayout();
} else {
if (debugLayout.getVisibility() == View.GONE) {
......@@ -292,7 +297,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
String successLog = "支付成功: " + successTime + " - " + successMessage;
LogUtils.file(TAG, successLog);
if (debugVs != null) return;
if (debugLayoutIsNotInflate()) return;
recText.setText(successLog);
}
......@@ -310,7 +315,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
String failedLog = "支付失败: " + failedTime + " - " + failedMessage;
LogUtils.file(TAG, failedLog);
if (debugVs != null) return;
if (debugLayoutIsNotInflate()) return;
recText.setText(failedLog);
}
......
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