Commit 30b4d247 by pye52

1、优化代码结构及注释

2、优化后台切换支付提示语后的响应
parent e251b4e5
...@@ -89,6 +89,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -89,6 +89,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private TextView message; private TextView message;
private AudioManager audioManager; private AudioManager audioManager;
private Gson gson;
private String idle_notice; private String idle_notice;
private WorkManager workManager; private WorkManager workManager;
private Handler handler = new Handler(); private Handler handler = new Handler();
...@@ -107,9 +108,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -107,9 +108,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
} }
String host = SmartCanteenUtils.getMainWebSocketServerUrl(deviceSN, BuildConfig.VERSION_NAME); String host = SmartCanteenUtils.getMainWebSocketServerUrl(deviceSN, BuildConfig.VERSION_NAME);
LogUtils.d(TAG, "服务器地址: " + host); LogUtils.d(TAG, "服务器地址: " + host);
gson = Injection.provideGson();
try { try {
URI uri = new URI(host); URI uri = new URI(host);
SCWebSocketClient.init(uri, deviceSN, Injection.provideGson()); SCWebSocketClient.init(uri, deviceSN, gson);
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
LogUtils.e(TAG, "服务器地址异常: " + e.getMessage(), e); LogUtils.e(TAG, "服务器地址异常: " + e.getMessage(), e);
} }
...@@ -247,11 +249,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -247,11 +249,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel.commandFinish(command); commandViewModel.commandFinish(command);
return; return;
} }
// 修改主界面的提示语
if (CommandHelper.changedPaymentNotice(command)) { if (CommandHelper.changedPaymentNotice(command)) {
Gson gson = Injection.provideGson();
try { try {
CommandNotice commandNotice = gson.fromJson(command.getData(), CommandNotice.class); CommandNotice commandNotice = gson.fromJson(command.getData(), CommandNotice.class);
idle_notice = commandNotice.getData().getNotice(); idle_notice = commandNotice.getData().getNotice();
message.setText(idle_notice);
} finally { } finally {
commandViewModel.commandFinish(command); commandViewModel.commandFinish(command);
} }
...@@ -343,10 +346,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -343,10 +346,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().tryConnect(); SCWebSocketClient.getInstance().tryConnect();
} }
// 检查debug layout是否已初始化
private boolean debugLayoutIsNotInflate() { private boolean debugLayoutIsNotInflate() {
return debugVs != null; return debugVs != null;
} }
// 主界面显示模式切换: Debug <==> Release
private void toggleDebugLayout() { private void toggleDebugLayout() {
if (debugLayoutIsNotInflate()) { if (debugLayoutIsNotInflate()) {
inflateDebugLayout(); inflateDebugLayout();
......
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