Commit fcdb977b by pye52

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

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