Commit a4c8df6f by pye52

Merge branch 'develop'

parents 4383580a 5477c597
......@@ -7,8 +7,8 @@ android {
applicationId "com.bgycc.smartcanteen"
minSdkVersion 22
targetSdkVersion 29
versionCode 16
versionName "1.3.6"
versionCode 17
versionName "1.3.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
......
......@@ -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 -> {
......@@ -349,8 +325,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel.initialize();
handler.post(updateTimeRunnable);
MonitorUtils.startLogFilesMonitor(this);
MonitorUtils.startDatabaseMonitor(this);
MonitorUtils.startMonitors(this);
SCWebSocketClient.getInstance().tryConnect();
}
......@@ -424,8 +399,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper.release();
SCWebSocketClient.getInstance().realClose();
SCTaskExecutor.getInstance().quit();
MonitorUtils.stopDatabaseMonitor(this);
MonitorUtils.stopLogFilesMonitor(this);
MonitorUtils.stopMonitors(this);
}
private void initViews() {
......@@ -469,11 +443,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;
......
......@@ -17,8 +17,18 @@ public class MonitorUtils {
private static final int LOG_REPEAT_INTERVAL = 4;
private static final int DATABASE_REPEAT_INTERVAL = 12;
public static void startMonitors(Context context) {
startLogFilesMonitor(context);
startDatabaseMonitor(context);
}
public static void stopMonitors(Context context) {
stopLogFilesMonitor(context);
stopDatabaseMonitor(context);
}
// 每隔一定时间检查日志文件夹并进行清理
public static void startLogFilesMonitor(Context context) {
private static void startLogFilesMonitor(Context context) {
stopLogFilesMonitor(context);
PeriodicWorkRequest request = new PeriodicWorkRequest.Builder(LogFileMonitor.class, LOG_REPEAT_INTERVAL, TimeUnit.HOURS)
.addTag(LOG_MONITOR_WORKER)
......@@ -27,13 +37,13 @@ public class MonitorUtils {
.enqueue(request);
}
public static void stopLogFilesMonitor(Context context) {
private static void stopLogFilesMonitor(Context context) {
WorkManager.getInstance(context)
.cancelAllWorkByTag(LOG_MONITOR_WORKER);
}
// 每隔一定时间检查数据库并进行清理
public static void startDatabaseMonitor(Context context) {
private static void startDatabaseMonitor(Context context) {
stopDatabaseMonitor(context);
PeriodicWorkRequest request = new PeriodicWorkRequest.Builder(DatabaseMonitor.class, DATABASE_REPEAT_INTERVAL, TimeUnit.HOURS)
.addTag(DATABASE_MONITOR_WORKER)
......@@ -42,7 +52,7 @@ public class MonitorUtils {
.enqueue(request);
}
public static void stopDatabaseMonitor(Context context) {
private static void stopDatabaseMonitor(Context context) {
WorkManager.getInstance(context)
.cancelAllWorkByTag(DATABASE_MONITOR_WORKER);
}
......
......@@ -18,7 +18,6 @@ import com.bgycc.smartcanteen.utils.SmartCanteenUtils;
import com.blankj.utilcode.util.LogUtils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
......@@ -99,8 +98,8 @@ public class QRCodeViewModel extends ViewModel {
JsonObject jsonObject;
try {
jsonObject = JsonParser.parseString(scanData).getAsJsonObject();
} catch (JsonSyntaxException jse) {
LogUtils.e(TAG, "非法的指令格式: " + scanData);
} catch (Exception e) {
LogUtils.e(TAG, "非法的指令格式: " + scanData, e);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
return;
}
......
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