Commit 8b53b469 authored by chenyuling's avatar chenyuling

"优化连接接口状态存储"

parent f3847fe2
Pipeline #1634 canceled with stages
......@@ -213,10 +213,13 @@ public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPC
@Override
public void onAllConnectStatus(boolean hasConnect, int type) {
HashMap<String, Boolean> devicesConnect = MyApplication.getInstance().devicesConnect;
if (type==ENTER_TYPE){
SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect);
devicesConnect.put("enter_connect",hasConnect);
// SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect);
}else if (type==LEAVE_TYPE){
SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect);
// SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect);
devicesConnect.put("leave_connect",hasConnect);
}
}
......
......@@ -4,8 +4,12 @@ import android.app.Application;
import com.raizlabs.android.dbflow.config.FlowManager;
import java.util.HashMap;
public class MyApplication extends Application {
private static MyApplication application;
//声明一个公共的变量,存储网络状态
public HashMap<String,Boolean> devicesConnect = new HashMap<>();
// 1秒钟后重启应用
private int time = 1000;
......
......@@ -33,6 +33,7 @@ import com.srthinker.statinfo.presenter.ApiQuest;
import com.srthinker.statinfo.presenter.StatSize;
import com.srthinker.statinfo.uis.BaseActivity;
import com.srthinker.statinfo.uis.GroupActivity;
import com.srthinker.statinfo.uis.MyApplication;
import com.srthinker.statinfo.uis.fragment.ConfigDlgFragment;
import com.srthinker.statinfo.util.common.ClickUtil;
import com.srthinker.statinfo.util.common.SharedUtil;
......@@ -145,8 +146,11 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Que
}
private void updateDeviceConnect() {
enter_connect = SharedUtil.getInstance(this).readShared("enter_connect", false);
leave_connect = SharedUtil.getInstance(this).readShared("leave_connect", false);
HashMap<String, Boolean> devicesConnect = MyApplication.getInstance().devicesConnect;
enter_connect = devicesConnect.getOrDefault("enter_connect",false);
leave_connect = devicesConnect.getOrDefault("leave_connect",false);
/*enter_connect = SharedUtil.getInstance(this).readShared("enter_connect", false);
leave_connect = SharedUtil.getInstance(this).readShared("leave_connect", false);*/
if (enter_connect){
mBinding.tvEnterError.setVisibility(View.GONE);
}else{
......@@ -450,8 +454,10 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Que
Log.i(TAG, "onAllConnectStatus: 接收到的连接状态 hasConnect="+hasConnect);
Log.i(TAG, "onAllConnectStatus: type="+type);
runOnUiThread(()->{
HashMap<String, Boolean> devicesConnect = MyApplication.getInstance().devicesConnect;
if (type==ENTER_TYPE){
SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect);
devicesConnect.put("enter_connect",hasConnect);
//SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect);
if (!hasConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{
......@@ -459,7 +465,8 @@ public class SettingActivity extends BaseActivity implements ConfigCallback, Que
}
}else if (type == LEAVE_TYPE){
SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect);
devicesConnect.put("leave_connect",hasConnect);
//SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect);
if (!hasConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{
......
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 to comment