Commit 043dd808 by pye52

1、优化debug模式下服务器地址等信息的显示逻辑

2、现在重新进入app会将所有未完成的指令设置为已完成
parent bf416e36
...@@ -129,33 +129,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -129,33 +129,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
initViews(); initViews();
SCWebSocketClient.getInstance().getConnectStateEvent().observe(this, event -> { SCWebSocketClient.getConnectStateEvent().observe(this, event -> {
if (debugLayoutIsNotInflate()) return; if (debugLayoutIsNotInflate()) return;
String msg; refreshServerInfo();
switch (event.getState()) {
case ConnectState.OFFLINE:
msg = String.format(getString(R.string.connect_offline), NetworkUtils.getTryingNetworkType(this));
break;
case ConnectState.CONNECTING:
msg = String.format(getString(R.string.connect_connecting), NetworkUtils.getNetworkType(this));
break;
case ConnectState.CONNECTED:
msg = String.format(getString(R.string.connect_connected), event.getHost(), NetworkUtils.getNetworkType(this));
// socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo();
refreshWifiInfo();
break;
case ConnectState.RECONNECTING:
msg = String.format(getString(R.string.connect_reconnecting), event.getHost());
break;
case ConnectState.CHANGE_NETWORK:
msg = String.format(getString(R.string.connect_change_network), NetworkUtils.getTryingNetworkType(this));
break;
default:
msg = "";
break;
}
serverText.setText(msg);
}); });
payOnlineViewModel.getPayOnlineStateEvent().observe(this, event -> { payOnlineViewModel.getPayOnlineStateEvent().observe(this, event -> {
...@@ -469,11 +445,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -469,11 +445,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
logoLayout.setVisibility(View.GONE); logoLayout.setVisibility(View.GONE);
debugLayout.setOnClickListener(this); debugLayout.setOnClickListener(this);
logoLayout.setOnClickListener(this); logoLayout.setOnClickListener(this);
refreshServerInfo();
refreshEthInfo(); refreshEthInfo();
refreshWifiInfo(); refreshWifiInfo();
refreshPackageInfo(); refreshPackageInfo();
} }
private void refreshServerInfo() {
ConnectState event = SCWebSocketClient.getConnectStateEvent().getValue();
if (event == null) return;
String msg;
switch (event.getState()) {
case ConnectState.OFFLINE:
msg = String.format(getString(R.string.connect_offline), NetworkUtils.getTryingNetworkType(this));
break;
case ConnectState.CONNECTING:
msg = String.format(getString(R.string.connect_connecting), NetworkUtils.getNetworkType(this));
break;
case ConnectState.CONNECTED:
msg = String.format(getString(R.string.connect_connected), event.getHost(), NetworkUtils.getNetworkType(this));
// socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo();
refreshWifiInfo();
break;
case ConnectState.RECONNECTING:
msg = String.format(getString(R.string.connect_reconnecting), event.getHost());
break;
case ConnectState.CHANGE_NETWORK:
msg = String.format(getString(R.string.connect_change_network), NetworkUtils.getTryingNetworkType(this));
break;
default:
msg = "";
break;
}
serverText.setText(msg);
}
private void refreshEthInfo() { private void refreshEthInfo() {
String ethMac = NetworkUtils.getEthernetMacAddress(); String ethMac = NetworkUtils.getEthernetMacAddress();
String ethIP = NetworkUtils.getEthernetIpString(); String ethIP = NetworkUtils.getEthernetIpString();
......
...@@ -61,6 +61,7 @@ public abstract class DatabaseManager extends RoomDatabase { ...@@ -61,6 +61,7 @@ public abstract class DatabaseManager extends RoomDatabase {
DatabaseManager.class, DatabaseManager.class,
DB_NAME) DB_NAME)
.addCallback(new OldDataCompatible()) .addCallback(new OldDataCompatible())
.addCallback(new FinishCommand())
.addCallback(new ForceToPayOffline()) .addCallback(new ForceToPayOffline())
.addMigrations(new _1To_2Migration()) .addMigrations(new _1To_2Migration())
// 一旦版本不兼容则清空数据库 // 一旦版本不兼容则清空数据库
......
package com.bgycc.smartcanteen.data;
import androidx.annotation.NonNull;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteDatabase;
import com.bgycc.smartcanteen.entity.Command;
/**
* 应用启动时,将所有未执行的指令设置为"已完成"
*/
public class FinishCommand extends RoomDatabase.Callback {
@Override
public void onOpen(@NonNull SupportSQLiteDatabase db) {
db.execSQL("update " + Command.TABLE_NAME + " set finish = 1 where finish == 0");
}
}
...@@ -57,10 +57,6 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -57,10 +57,6 @@ public class SCWebSocketClient extends WebSocketClient {
private MutableLiveData<ConnectState> connectState = new MutableLiveData<>(); private MutableLiveData<ConnectState> connectState = new MutableLiveData<>();
public LiveData<ConnectState> getConnectStateEvent() {
return connectState;
}
public static void init(URI serverUri, String deviceSN, Gson gson) { public static void init(URI serverUri, String deviceSN, Gson gson) {
if (instance != null) return; if (instance != null) return;
instance = new SCWebSocketClient(serverUri, deviceSN, gson); instance = new SCWebSocketClient(serverUri, deviceSN, gson);
...@@ -70,6 +66,11 @@ public class SCWebSocketClient extends WebSocketClient { ...@@ -70,6 +66,11 @@ public class SCWebSocketClient extends WebSocketClient {
return instance; return instance;
} }
public static LiveData<ConnectState> getConnectStateEvent() {
if (instance == null) return null;
return instance.connectState;
}
public void tryConnect() { public void tryConnect() {
LogUtils.d(TAG, "尝试通过WebSocket链接服务器"); LogUtils.d(TAG, "尝试通过WebSocket链接服务器");
forceStop = false; forceStop = false;
......
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