Commit 043dd808 by pye52

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

2、现在重新进入app会将所有未完成的指令设置为已完成
parent bf416e36
......@@ -129,33 +129,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
initViews();
SCWebSocketClient.getInstance().getConnectStateEvent().observe(this, event -> {
SCWebSocketClient.getConnectStateEvent().observe(this, event -> {
if (debugLayoutIsNotInflate()) 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);
refreshServerInfo();
});
payOnlineViewModel.getPayOnlineStateEvent().observe(this, event -> {
......@@ -469,11 +445,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
logoLayout.setVisibility(View.GONE);
debugLayout.setOnClickListener(this);
logoLayout.setOnClickListener(this);
refreshServerInfo();
refreshEthInfo();
refreshWifiInfo();
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() {
String ethMac = NetworkUtils.getEthernetMacAddress();
String ethIP = NetworkUtils.getEthernetIpString();
......
......@@ -61,6 +61,7 @@ public abstract class DatabaseManager extends RoomDatabase {
DatabaseManager.class,
DB_NAME)
.addCallback(new OldDataCompatible())
.addCallback(new FinishCommand())
.addCallback(new ForceToPayOffline())
.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 {
private MutableLiveData<ConnectState> connectState = new MutableLiveData<>();
public LiveData<ConnectState> getConnectStateEvent() {
return connectState;
}
public static void init(URI serverUri, String deviceSN, Gson gson) {
if (instance != null) return;
instance = new SCWebSocketClient(serverUri, deviceSN, gson);
......@@ -70,6 +66,11 @@ public class SCWebSocketClient extends WebSocketClient {
return instance;
}
public static LiveData<ConnectState> getConnectStateEvent() {
if (instance == null) return null;
return instance.connectState;
}
public void tryConnect() {
LogUtils.d(TAG, "尝试通过WebSocket链接服务器");
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