Commit a4f49f09 authored by chenyuling's avatar chenyuling

"另外开分支,使用设计稿的UI显示,定制组名信息"

parent 86253c4b
...@@ -19,8 +19,8 @@ android { ...@@ -19,8 +19,8 @@ android {
applicationId "com.srthinker.statinfo" applicationId "com.srthinker.statinfo"
minSdk 24 minSdk 24
targetSdk 32 targetSdk 32
versionCode 1 versionCode 2
versionName "1.0.4" versionName "2.0.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
......
...@@ -33,19 +33,19 @@ ...@@ -33,19 +33,19 @@
android:value="" /> android:value="" />
</activity> </activity>
<activity <activity
android:name=".uis.MainActivity" android:name=".uis.MainActivity1"
android:exported="true" > android:exported="false" >
<intent-filter> <!--<intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<!-- &lt;!&ndash;
<category android:name="android.intent.category.HOME" /> <category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
--> &ndash;&gt;
</intent-filter> </intent-filter>-->
<meta-data <meta-data
android:name="android.app.lib_name" android:name="android.app.lib_name"
...@@ -80,10 +80,21 @@ ...@@ -80,10 +80,21 @@
</provider> </provider>
<activity <activity
android:name=".uis.MainOldActivity" android:name=".uis.MainActivity"
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|orientation"
android:exported="false" android:exported="true"
android:windowSoftInputMode="adjustPan" > android:windowSoftInputMode="adjustPan" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<!--
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
-->
</intent-filter>
<meta-data <meta-data
android:name="android.app.lib_name" android:name="android.app.lib_name"
android:value="" /> android:value="" />
......
...@@ -19,16 +19,18 @@ public class GroupConst { ...@@ -19,16 +19,18 @@ public class GroupConst {
public static final int NO_GROUP = 100; public static final int NO_GROUP = 100;
public static final int GROUPED = 200; public static final int GROUPED = 200;
//钢筋班组,木工班组,泥工班组,水电班组,防水班组,外架班组,项目部,监理单位 //钢筋班组,木工班组,外架班组,防水班组,瓦工班组,安全文明施工,防水班组,众安管理人员,中交六公司管理人员,特种作业人员
public static ArrayList<Group2Bean> group2BeansConst = new ArrayList<>(); public static ArrayList<Group2Bean> group2BeansConst = new ArrayList<>();
static { static {
group2BeansConst.add(new Group2Bean(5, "钢筋班组",0)); group2BeansConst.add(new Group2Bean(1, "钢筋班组",0));
group2BeansConst.add(new Group2Bean(6, "木工班组",0)); group2BeansConst.add(new Group2Bean(2, "木工班组",0));
group2BeansConst.add(new Group2Bean(7, "泥工班组",0)); group2BeansConst.add(new Group2Bean(3, "外架班组",0));
group2BeansConst.add(new Group2Bean(8, "水电班组",0)); group2BeansConst.add(new Group2Bean(4, "防水班组",0));
group2BeansConst.add(new Group2Bean(1, "防水班组",0)); group2BeansConst.add(new Group2Bean(5, "瓦工班组",0));
group2BeansConst.add(new Group2Bean(2, "外架班组",0)); group2BeansConst.add(new Group2Bean(6, "安全文明施工",0));
group2BeansConst.add(new Group2Bean(3, "项目部",0)); group2BeansConst.add(new Group2Bean(7, "防水班组",0));
group2BeansConst.add(new Group2Bean(4, "监理单位",0)); group2BeansConst.add(new Group2Bean(8, "众安管理人员",0));
group2BeansConst.add(new Group2Bean(9, "中交六公司管理人员",0));
group2BeansConst.add(new Group2Bean(10, "特种作业人员",0));
} }
} }
package com.srthinker.statinfo.uis; package com.srthinker.statinfo.uis;
import static com.srthinker.statinfo.constant.Const.DEVICE_SN;
import static com.srthinker.statinfo.constant.Const.DEVICE_TYPE; import static com.srthinker.statinfo.constant.Const.DEVICE_TYPE;
import static com.srthinker.statinfo.constant.Const.SN_PATH;
import static com.srthinker.statinfo.constant.InOutType.ENTER_TYPE; import static com.srthinker.statinfo.constant.InOutType.ENTER_TYPE;
import static com.srthinker.statinfo.constant.InOutType.LEAVE_TYPE; import static com.srthinker.statinfo.constant.InOutType.LEAVE_TYPE;
import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_ERROR; import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_ERROR;
...@@ -9,6 +9,7 @@ import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_FINISH; ...@@ -9,6 +9,7 @@ import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_FINISH;
import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_START; import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_START;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
...@@ -18,31 +19,41 @@ import android.widget.Toast; ...@@ -18,31 +19,41 @@ import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.srthinker.statinfo.adapter.GroupShowAdapter; import com.srthinker.statinfo.R;
import com.srthinker.statinfo.adapter.EnterAdapter;
import com.srthinker.statinfo.adapter.GroupAdapter;
import com.srthinker.statinfo.adapter.GroupSmallAdapter;
import com.srthinker.statinfo.adapter.LeaveAdapter;
import com.srthinker.statinfo.bean.Group2Bean; import com.srthinker.statinfo.bean.Group2Bean;
import com.srthinker.statinfo.bean.StatusInfoBean; import com.srthinker.statinfo.bean.TimeBean;
import com.srthinker.statinfo.constant.GroupConst; import com.srthinker.statinfo.constant.GroupConst;
import com.srthinker.statinfo.database.PersonMgr;
import com.srthinker.statinfo.database.entity.ConfigEntity; import com.srthinker.statinfo.database.entity.ConfigEntity;
import com.srthinker.statinfo.database.entity.PersonEntity; import com.srthinker.statinfo.database.entity.PersonEntity;
import com.srthinker.statinfo.database.helper.ConfigHelper; import com.srthinker.statinfo.database.helper.ConfigHelper;
import com.srthinker.statinfo.database.helper.PersonHelper; import com.srthinker.statinfo.database.helper.PersonHelper;
import com.srthinker.statinfo.databinding.ActivityNewMainBinding; import com.srthinker.statinfo.databinding.ActivityMainBinding;
import com.srthinker.statinfo.download.upper.DownloadViewModel; import com.srthinker.statinfo.download.upper.DownloadViewModel;
import com.srthinker.statinfo.download.upper.UpperDownloadCallback; import com.srthinker.statinfo.download.upper.UpperDownloadCallback;
import com.srthinker.statinfo.listener.ConfigCallback;
import com.srthinker.statinfo.listener.OnTimeUpdateListener;
import com.srthinker.statinfo.listener.QueryPersonCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesCallback; import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesPortCallback; import com.srthinker.statinfo.presenter.ApiManager;
import com.srthinker.statinfo.presenter.ApiQuest; import com.srthinker.statinfo.presenter.ApiQuest;
import com.srthinker.statinfo.presenter.RealTimeClock;
import com.srthinker.statinfo.presenter.StatSize; import com.srthinker.statinfo.presenter.StatSize;
import com.srthinker.statinfo.uis.news.SettingActivity; import com.srthinker.statinfo.uis.fragment.ConfigDlgFragment;
import com.srthinker.statinfo.update.MDownloadCallBack; import com.srthinker.statinfo.update.MDownloadCallBack;
import com.srthinker.statinfo.update.NetworkViewModel; import com.srthinker.statinfo.update.NetworkViewModel;
import com.srthinker.statinfo.update.UpdateInfo; import com.srthinker.statinfo.update.UpdateInfo;
import com.srthinker.statinfo.util.common.ClickUtil;
import com.srthinker.statinfo.util.common.FileUtil; import com.srthinker.statinfo.util.common.FileUtil;
import com.srthinker.statinfo.util.common.GsonUtil; import com.srthinker.statinfo.util.common.GsonUtil;
import com.srthinker.statinfo.util.common.PermissionUtil; import com.srthinker.statinfo.util.common.PermissionUtil;
import com.srthinker.statinfo.util.common.SharedUtil;
import com.srthinker.statinfo.util.common.ThreadPool; import com.srthinker.statinfo.util.common.ThreadPool;
import com.srthinker.statinfo.util.common.Utils; import com.srthinker.statinfo.util.common.Utils;
import com.srthinker.statinfo.util.other.NetworkIPMonitor; import com.srthinker.statinfo.util.other.NetworkIPMonitor;
...@@ -53,113 +64,123 @@ import java.util.ArrayList; ...@@ -53,113 +64,123 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPChangeCallback, UpperDevicesCallback, MDownloadCallBack, UpperDownloadCallback, UpperDevicesPortCallback { public class MainActivity extends BaseActivity implements OnTimeUpdateListener, MDownloadCallBack, UpperDownloadCallback, NetworkIPMonitor.OnIPChangeCallback, ConfigCallback, QueryPersonCallback, UpperDevicesCallback {
private static final String TAG = "NewMainActivity"; private static final String TAG = "MainActivity";
private com.srthinker.statinfo.databinding.ActivityNewMainBinding mBinding; private com.srthinker.statinfo.databinding.ActivityMainBinding mBinding;
private NetworkIPMonitor networkIPMonitor; private RealTimeClock mRealTimeClock;
private float groupSize = 100;
private boolean isPermission;
private List<PersonEntity> enterBeans; private List<PersonEntity> enterBeans;
private List<PersonEntity> leaveBeans; private List<PersonEntity> leaveBeans;
private EnterAdapter enterAdapter;
private LeaveAdapter leaveAdapter;
private NetworkIPMonitor networkIPMonitor;
private String installPath = ""; private String installPath = "";
private LoadDialog mLoadDialog; private LoadDialog mLoadDialog;
//private String savePath = "/sdcard/update/StatInfo.apk"; //private String savePath = "/sdcard/update/StatInfo.apk";
//getFilesDir() + "/update", "StatInfo.apk" //getFilesDir() + "/update", "StatInfo.apk"
private String savePath = Environment.getExternalStorageDirectory().getPath() + "/update"; private String savePath = Environment.getExternalStorageDirectory().getPath() + "/update";
private String sessionId;
private ApiManager enterMgr;
private static ScheduledExecutorService executor;
private int lastEnterSize = 0; private int lastEnterSize = 0;
private int lastLeaveSize = 0; private int lastLeaveSize = 0;
private int lastPresentSize = 0; private int lastPresentSize = 0;
private String deviceSn;
private List<PersonEntity> mQueryPersonList; private List<PersonEntity> mQueryPersonList;
private GroupAdapter groupAdapter;
private HashMap<Integer, Integer> groupEnterHashMap=null; private HashMap<Integer, Integer> groupEnterHashMap=null;
private HashMap<Integer, Integer> groupLeaveHashMap=null; private HashMap<Integer, Integer> groupLeaveHashMap=null;
private HashMap<Integer,Integer> groupPresentHashMap=null; private HashMap<Integer,Integer> groupPresentHashMap=null;
private boolean isPermission;
public static boolean NEED_NO_REPET = true; //是否需要去重,false:不需要,true:需要 public static boolean NEED_NO_REPET = true; //是否需要去重,false:不需要,true:需要
private int group; private String deviceDesc;
private GroupShowAdapter showAdapter; private GroupSmallAdapter groupSmallAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_new_main); //setContentView(R.layout.activity_main);
mBinding = ActivityNewMainBinding.inflate(getLayoutInflater()); mBinding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot()); setContentView(mBinding.getRoot());
checkAllPermission();
initData(); initData();
initView(); initView();
checkAllPermission();
} }
@SuppressLint("SdCardPath")
@Override @Override
protected void initData() { protected void initData() {
//获取Sn
deviceSn = FileUtil.readTextFromFile(SN_PATH);
enterBeans = new ArrayList<>();
leaveBeans = new ArrayList<>();
/*for (int i = 0; i < 12; i++) {
enterBeans.add(new PeopleBean("08:14","王大锤"));
}
for (int i = 0; i < 5; i++) {
leaveBeans.add(new PeopleBean("08:04","赵美丽"));
}*/
//检测网络
networkIPMonitor = new NetworkIPMonitor(this); networkIPMonitor = new NetworkIPMonitor(this);
networkIPMonitor.startMonitoring(); networkIPMonitor.startMonitoring();
networkIPMonitor.setOnIPChangeCallback(this); networkIPMonitor.setOnIPChangeCallback(this);
enterBeans = new ArrayList<>();
leaveBeans = new ArrayList<>();
} }
@SuppressLint("SetTextI18n")
@Override @Override
protected void initView() { protected void initView() {
initNumber();
updateTime();
initGroup(); initGroup();
mBinding.tvSetting.setOnClickListener(v->{ initPeopleList();
Intent intent = new Intent(this, SettingActivity.class); //mLoadDialog = LoadDialog.getInstance(this);
startActivity(intent); mLoadDialog = new LoadDialog(this);
//Log.i(TAG, "initView: deviceSn="+deviceSn+"V"+ Utils.getVersionName(this));
deviceDesc = DEVICE_TYPE+" "+deviceSn+" V"+ Utils.getVersionName(this)+" ";
mBinding.tvDeviceDesc.setText(deviceDesc+"网络未连接");
//getResp();
mBinding.tvEnterText.setOnClickListener(v->{
showConfigDialog(ENTER_TYPE);
});
mBinding.tvLeaveText.setOnClickListener(v->{
showConfigDialog(LEAVE_TYPE);
});
mBinding.btnGroupDetail.setOnClickListener(v->{
/*ApiQuest.getInstance().queryPersons(this);
ClickUtil.disableClick(mBinding.btnGroupDetail);*/
boolean isQueryPersons = ApiQuest.getInstance().queryPersons(this);
//Log.i(TAG, "initView: isQueryPersons="+isQueryPersons);
if (!isQueryPersons) {
showTips("请检查配置信息和检查网络");
}else{
ClickUtil.disableClick(mBinding.btnGroupDetail);
}
}); });
mLoadDialog = new LoadDialog(this); //1.0.2版本把这个漏了
}
/*private void initGroup() {
int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
*//*mBinding.ngvBuild.initItem("工地班组",build,groupSize);
mBinding.ngvWaterproof.initItem("防水班组",waterproof,groupSize);
mBinding.ngvOutrigger.initItem("外架班组",outrigger,groupSize);
mBinding.ngvSupervisor.initItem("监理单位",supervisor,groupSize);*//*
mBinding.ngvBuild.initItem("工地班组",build);
mBinding.ngvWaterproof.initItem("防水班组",waterproof);
mBinding.ngvOutrigger.initItem("外架班组",outrigger);
mBinding.ngvSupervisor.initItem("监理单位",supervisor);
}*/
private void initGroup(){
GridLayoutManager gLM = new GridLayoutManager(this, 4, RecyclerView.HORIZONTAL, false);
mBinding.rvGroupTotal.setLayoutManager(gLM);
showAdapter = new GroupShowAdapter(this, GroupConst.group2BeansConst);
mBinding.rvGroupTotal.setAdapter(showAdapter);
} }
private void checkAllPermission() { private void showConfigDialog(int type) {
isPermission = PermissionUtil.checkMultiPermission(this, new String[]{ ConfigDlgFragment configDlgFragment = ConfigDlgFragment.getInstance(type);
Manifest.permission.READ_EXTERNAL_STORAGE, configDlgFragment.setUsername("admin");
Manifest.permission.WRITE_EXTERNAL_STORAGE, configDlgFragment.setConfigCallback(this);
Manifest.permission.INTERNET if (configDlgFragment.isResumed()){
}, 4096); return;
if (!isPermission){
Toast.makeText(this, "需要允许权限才能正常使用哦", Toast.LENGTH_SHORT).show();
} }
configDlgFragment.showNow(getSupportFragmentManager(),configDlgFragment.getClass().getSimpleName());
configDlgFragment.setCancelable(false);
} }
/*private void updateGroup() {
int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
mBinding.ngvBuild.setNumber(build);
mBinding.ngvWaterproof.setNumber(waterproof);
mBinding.ngvOutrigger.setNumber(outrigger);
mBinding.ngvSupervisor.setNumber(supervisor);
}*/
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Log.i(TAG, "onResume: Main-Resume"); Log.i(TAG, "onResume: Main-Resume");
//如果设置页面有更新,主页面也需要进行访问接口,绑定监听
updateApi();
//获取最新的人员信息列表 //获取最新的人员信息列表
mQueryPersonList = PersonHelper.getInstance().queryAll(); mQueryPersonList = PersonHelper.getInstance().queryAll();
//更新分组情况 //更新分组情况
...@@ -169,141 +190,251 @@ public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPC ...@@ -169,141 +190,251 @@ public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPC
detectUpgrade(); //检测版本升级 detectUpgrade(); //检测版本升级
} }
private void updateApi() { @Override
boolean isModified = SharedUtil.getInstance(this).readShared("isModified", false); protected void onDestroy() {
if (isModified){ Log.i(TAG, "onDestroy: Main--destroy");
questApi();
SharedUtil.getInstance(this).writeShared("isModified",false); networkIPMonitor.stopMonitoring();
} mRealTimeClock.stop();
//关闭循环拉取
//executor.shutdownNow();
/*if (enterMgr != null) {
enterMgr.stop();
}*/
ApiQuest.getInstance().stopApi();
super.onDestroy();
} }
private void detectUpgrade() { private void detectUpgrade() {
NetworkViewModel networkViewModel = new NetworkViewModel(); NetworkViewModel networkViewModel = new NetworkViewModel();
networkViewModel.init(this,this); networkViewModel.init(this,this);
networkViewModel.setDownloadCallback(this); networkViewModel.setDownloadCallback(this);
networkViewModel.getLastestVersion(DEVICE_SN,DEVICE_TYPE); networkViewModel.getLastestVersion(deviceSn,DEVICE_TYPE);
} }
@Override private void checkAllPermission() {
protected void onDestroy() { isPermission = PermissionUtil.checkMultiPermission(this, new String[]{
Log.i(TAG, "onDestroy: Main--destroy"); Manifest.permission.READ_EXTERNAL_STORAGE,
networkIPMonitor.stopMonitoring(); Manifest.permission.WRITE_EXTERNAL_STORAGE,
ApiQuest.getInstance().stopApi(); Manifest.permission.INTERNET
clearStatusInfoBeans(); }, 4096);
super.onDestroy(); if (!isPermission){
Toast.makeText(this, "需要允许权限才能正常使用哦", Toast.LENGTH_SHORT).show();
}
} }
@Override private void initNumber() {
public void OnIPChange(String ipAddress, String networkType) { mBinding.nvEnter.initItem(lastEnterSize,"进去人数", R.mipmap.enter_bg);
Log.i(TAG, "OnIPChange: change==>"); mBinding.nvLeave.initItem(lastLeaveSize,"离开人数", R.mipmap.leave_bg);
//questApi(); mBinding.nvPresent.initItem(lastPresentSize,"在场人数", R.mipmap.present_bg);
questApi();
} }
private void questApi() { private void initPeopleList() {
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE); LinearLayoutManager enterLLM = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE); mBinding.rvEnterList.setLayoutManager(enterLLM);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE); enterAdapter = new EnterAdapter(this, enterBeans);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE); mBinding.rvEnterList.setAdapter(enterAdapter);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); LinearLayoutManager leaveLLM = new LinearLayoutManager(this, RecyclerView.VERTICAL, false);
ApiQuest.getInstance().setOnUpperDevicesPortCallback(this); mBinding.rvLeaveList.setLayoutManager(leaveLLM);
leaveAdapter = new LeaveAdapter(this, leaveBeans);
mBinding.rvLeaveList.setAdapter(leaveAdapter);
}
/* private void initGroup() {
GridLayoutManager groupGLM = new GridLayoutManager(this, 4);
mBinding.rvGroup.setLayoutManager(groupGLM);
ArrayList<GroupBean> groupBeans = updateGroup();
groupAdapter = new GroupAdapter(this, groupBeans);
mBinding.rvGroup.setAdapter(groupAdapter);
*//*mBinding.gvWaterproof.initItem("防水班组",34,R.color.color_2D52E3);
mBinding.gvOutrigger.initItem("外架班组",12,R.color.color_694BFF);
mBinding.gvBuild.initItem("工地班组",26,R.color.color_8A34D5);
mBinding.gvSupervisor.initItem("监理单位",28,R.color.color_00A89C);*//*
}*/
private void initGroup(){
GridLayoutManager gLM = new GridLayoutManager(this, 5, RecyclerView.VERTICAL, false);
mBinding.rvGroup.setLayoutManager(gLM);
groupSmallAdapter = new GroupSmallAdapter(this, GroupConst.group2BeansConst);
mBinding.rvGroup.setAdapter(groupSmallAdapter);
}
/* private ArrayList<GroupBean> updateGroup() {
ArrayList<GroupBean> groupBeans = new ArrayList<>();
int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
groupBeans.add(new GroupBean("防水班组",waterproof,R.color.color_2D52E3,WATERPROOF));
groupBeans.add(new GroupBean("外架班组",outrigger,R.color.color_694BFF,OUTRIGGER));
groupBeans.add(new GroupBean("工地班组",build,R.color.color_8A34D5,BUILD));
groupBeans.add(new GroupBean("监理单位",supervisor,R.color.color_00A89C,SUPERVISOR));
return groupBeans;
}*/
private void updateTime() {
mRealTimeClock = new RealTimeClock();
mRealTimeClock.setOnTimeUpdateListener(this);
mRealTimeClock.start();
} }
@SuppressLint("SetTextI18n")
@Override @Override
public void OnIPLost(String error) { public void OnTimeUpdate(TimeBean timeBean) {
ApiQuest.getInstance().stopApi(); if (timeBean != null) {
//修改状态 mBinding.tvTime.setText(timeBean.getyMD()+" "+timeBean.getWeek()+" "+timeBean.getHm());
List<ConfigEntity> configEntities = ConfigHelper.getInstance().queryAll();
for (ConfigEntity configEntity : configEntities) {
configEntity.setConnect(false);
//更新ip接口状态
ConfigHelper.getInstance().update(configEntity);
} }
} }
@Override @Override
public void getAllPassInfo(List<PersonEntity> passAllEntities, int type) { public void checkResult(boolean needUpdate, boolean canInstall, UpdateInfo onlineInfo) {
if (needUpdate){
if (onlineInfo!=null){
Log.i(TAG, "checkResult: onlineInfo="+ GsonUtil.toJsonString(onlineInfo));
//Environment.getExternalStorageDirectory().getPath()=/storage/emulated/0
//getFilesDir()=installPath=/data/user/0/com.srthinker.statinfo/files
//String installPath = getFilesDir() + "/" + "StatInfo.apk";
//boolean isCreate = FileUtil.createFile(getFilesDir() + "/update", "StatInfo.apk");
FileUtil.deleteFile(savePath+File.separator+"StatInfo.apk");
boolean isCreate = FileUtil.createFile( savePath+File.separator, "StatInfo.apk");
if (isCreate){
//installPath = getFilesDir()+"/update/StatInfo.apk";
installPath = savePath+File.separator+"StatInfo.apk";
DownloadViewModel downloadViewModel = new DownloadViewModel(this);
downloadViewModel.initData();
downloadViewModel.startDownload(onlineInfo.getDownloadUrl(),installPath);
downloadViewModel.setOnUpperDownloadCallback(this);
}
}
}
}
@Override
public void onProgress(String progress, String filePath) {
runOnUiThread(()->{ runOnUiThread(()->{
updatePassInfo(passAllEntities, type); //Log.i(TAG, "onProgress: progress="+progress);
String desc = "下载更新中..."+progress;
if (mLoadDialog != null) {
mLoadDialog.setContent(desc);
mLoadDialog.showDialog();
}
}); });
} }
@Override @Override
public void onAllConnectStatus(boolean hasConnect, int type) { public void onResult(int downStatus, String filePath) {
/*HashMap<String, Boolean> devicesConnect = MyApplication.getInstance().devicesConnect; runOnUiThread(()->{
if (type==ENTER_TYPE){ if (downStatus == DOWN_START){
devicesConnect.put("enter_connect",hasConnect); String desc = "准备下载更新";
// SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect); if (mLoadDialog != null) {
}else if (type==LEAVE_TYPE){ mLoadDialog.setContent(desc);
// SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect); mLoadDialog.showDialog();
devicesConnect.put("leave_connect",hasConnect); }
}*/ } else if (downStatus== DOWN_FINISH){
//安装更新
//Log.i(TAG, "onResult:进来多少次");
//showTips("更新版本,将进行安装");
String desc = "进行安装,请稍等";
if (mLoadDialog != null) {
mLoadDialog.setContent(desc);
mLoadDialog.showDialog();
}
//Utils.installApp(getApplicationContext(),new File(installPath));
//有静默安装的话需要开新线程,不然前面的弹框不进行显示
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
boolean restricted = Utils.isRootPermissionRestricted();
if (!restricted){
Utils.clientInstall(installPath, MainActivity.this,".uis.MainActivity");
}else{
Utils.installApp(getApplicationContext(),new File(installPath));
}
runOnUiThread(()->{
if (mLoadDialog != null) {
mLoadDialog.dismissDialog();
mLoadDialog=null;
}
});
});
}else if (downStatus==DOWN_ERROR){
showTips("下载更新失败");
FileUtil.deleteFile(installPath);
}
});
} }
private void updatePassInfo(List<PersonEntity> passEntities, int type) { private void updatePassInfo(List<PersonEntity> passEntities, int type) {
if (passEntities != null) { if (passEntities != null) {
Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size()); Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size());
} }
//Log.i(TAG, "updatePassInfo: 进还是出="+type);
/*for (PersonEntity passEntity : passEntities) { /*for (PersonEntity passEntity : passEntities) {
Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name()); Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name());
}*/ }*/
if (type ==ENTER_TYPE){ if (type ==ENTER_TYPE){
if (passEntities != null) { if (passEntities != null) {
int size = passEntities.size(); if (enterAdapter != null) {
if (size!=lastEnterSize){ int size = passEntities.size();
/*//更新进出情况 if (enterBeans!=null&&size!=enterBeans.size()){
//enterBeans = passEntities; 全局变量直接赋值会出现问题 //更新进出情况
enterBeans.clear(); //enterBeans = passEntities; 全局变量直接赋值会出现问题
enterBeans.addAll(passEntities); enterBeans.clear();
enterAdapter.setDataList(passEntities); enterBeans.addAll(passEntities);
//更新人员情况(是否要根据id去重) enterAdapter.setDataList(passEntities);
if (NEED_NO_REPET) { //更新人员情况(是否要根据名字去重)
List<PersonEntity> enterListNo = StatSize.filterList(passEntities); if (NEED_NO_REPET) {
lastEnterSize = enterListNo.size(); List<PersonEntity> enterListNo = StatSize.filterList(passEntities);
}else{ lastEnterSize = enterListNo.size();
lastEnterSize = size; }else{
lastEnterSize = size;
}
lastPresentSize = lastEnterSize-lastLeaveSize;
mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据名字去重)
groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
lastPresentSize = lastEnterSize-lastLeaveSize; /* Log.i(TAG, "updatePassInfo: enterBeans.size="+enterBeans.size());
mBinding.nvEnter.setNumber(lastEnterSize); Log.i(TAG, "updatePassInfo: adapter.size="+enterAdapter.getDataList().size());*/
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);*/
enterBeans.clear();
enterBeans.addAll(passEntities);
lastEnterSize = size;
//更新分组情况(是否要根据id去重)
groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
//leaveBeans = passEntities; //leaveBeans = passEntities;
if (passEntities != null) { if (passEntities != null) {
int size = passEntities.size(); if (leaveAdapter != null) {
//进出有变化时才更新 int size = passEntities.size();
if (size!=lastLeaveSize){ //进出有变化时才更新
/*leaveBeans.clear(); if (leaveBeans!=null&&size!=leaveBeans.size()){
leaveBeans.addAll(passEntities); leaveBeans.clear();
//更新进出情况 leaveBeans.addAll(passEntities);
leaveAdapter.setDataList(passEntities); //更新进出情况
//更新人员情况(是否要根据id去重) leaveAdapter.setDataList(passEntities);
if (NEED_NO_REPET) { //更新人员情况(是否要根据名字去重)
List<PersonEntity> leaveListNo = StatSize.filterList(passEntities); if (NEED_NO_REPET) {
lastLeaveSize = leaveListNo.size(); List<PersonEntity> leaveListNo = StatSize.filterList(passEntities);
}else{ lastLeaveSize = leaveListNo.size();
lastLeaveSize = size; }else{
lastLeaveSize = size;
}
lastPresentSize = lastEnterSize-lastLeaveSize;
mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据名字去重)
groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
lastPresentSize = lastEnterSize-lastLeaveSize; /*Log.i(TAG, "updatePassInfo: leaveBeans.size="+leaveBeans.size());
mBinding.nvEnter.setNumber(lastEnterSize); Log.i(TAG, "updatePassInfo: adapter.size="+leaveAdapter.getDataList().size());*/
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);*/
leaveBeans.clear();
leaveBeans.addAll(passEntities);
lastLeaveSize = size;
//更新分组情况(是否要根据id去重)
groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
...@@ -403,98 +534,108 @@ public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPC ...@@ -403,98 +534,108 @@ public class MainActivity extends BaseActivity implements NetworkIPMonitor.OnIPC
} }
//要更新演示页面的分组请求 //要更新演示页面的分组请求
//updateGroup(); //updateGroup();
showAdapter.setDataList(GroupConst.group2BeansConst); groupSmallAdapter.setDataList(GroupConst.group2BeansConst);
} }
@Override @Override
public void checkResult(boolean needUpdate, boolean canInstall, UpdateInfo onlineInfo) { public void onQueryStatus(String desc, boolean status) {
if (needUpdate){ runOnUiThread(()->{
if (onlineInfo!=null){ if (!status){
Log.i(TAG, "checkResult: onlineInfo="+ GsonUtil.toJsonString(onlineInfo)); showTips(desc);
//Environment.getExternalStorageDirectory().getPath()=/storage/emulated/0
//getFilesDir()=installPath=/data/user/0/com.srthinker.statinfo/files
//String installPath = getFilesDir() + "/" + "StatInfo.apk";
//boolean isCreate = FileUtil.createFile(getFilesDir() + "/update", "StatInfo.apk");
FileUtil.deleteFile(savePath+ File.separator+"StatInfo.apk");
boolean isCreate = FileUtil.createFile( savePath+File.separator, "StatInfo.apk");
if (isCreate){
//installPath = getFilesDir()+"/update/StatInfo.apk";
installPath = savePath+File.separator+"StatInfo.apk";
DownloadViewModel downloadViewModel = new DownloadViewModel(this);
downloadViewModel.initData();
downloadViewModel.startDownload(onlineInfo.getDownloadUrl(),installPath);
downloadViewModel.setOnUpperDownloadCallback(this);
}
} }
});
}
} }
@Override @Override
public void onProgress(String progress, String filePath) { public void getTotalPerson(List<PersonEntity> personEntities,int type) {
runOnUiThread(()->{ Log.i(TAG, "getTotalPerson: 已获取总数:personEntities.size="+personEntities.size());
//Log.i(TAG, "onProgress: progress="+progress); PersonMgr.getInstance().updatePersonThread(personEntities, () -> {
String desc = "下载更新中..."+progress; runOnUiThread(()->{
if (mLoadDialog != null) { ClickUtil.enableClick(mBinding.btnGroupDetail);
mLoadDialog.setContent(desc); });
mLoadDialog.showDialog(); Intent intent = new Intent(MainActivity.this, GroupActivity.class);
} startActivity(intent);
}); });
} }
@Override @Override
public void onResult(int downStatus, String filePath) { public void OnIPChange(String ipAddress, String networkType) {
runOnUiThread(()->{ Log.i(TAG, "OnIPChange: change==>");
if (downStatus == DOWN_START){ runOnUiThread(() -> mBinding.tvDeviceDesc.setText(deviceDesc+ipAddress));
String desc = "准备下载更新"; //questApi();
if (mLoadDialog != null) { /*List<ConfigBean> enterConfigList = SharedUtil.getInstance(this).readSharedList(ENTER_TYPE, ConfigBean.class, "");
mLoadDialog.setContent(desc); ApiQuest.startEnterApi(enterConfigList,this);
mLoadDialog.showDialog(); List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, "");
} ApiQuest.startLeaveApi(leaveConfigList,this);*/
} else if (downStatus== DOWN_FINISH){ List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
//安装更新 ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
//Log.i(TAG, "onResult:进来多少次"); //ApiQuest.getInstance().setOnUpperDevicesCallback(this);
//showTips("更新版本,将进行安装"); List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
}
String desc = "进行安装,请稍等"; @Override
if (mLoadDialog != null) { public void OnIPLost(String error) {
mLoadDialog.setContent(desc); runOnUiThread(() -> mBinding.tvDeviceDesc.setText(deviceDesc+"网络未连接"));
mLoadDialog.showDialog(); ApiQuest.getInstance().stopApi();
} //修改网络状态
//Utils.installApp(getApplicationContext(),new File(installPath)); List<ConfigEntity> configEntities = ConfigHelper.getInstance().queryAll();
//有静默安装的话需要开新线程,不然前面的弹框不进行显示 for (ConfigEntity configEntity : configEntities) {
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> { configEntity.setConnect(false);
boolean restricted = Utils.isRootPermissionRestricted(); //更新ip接口状态
if (!restricted){ ConfigHelper.getInstance().update(configEntity);
Utils.clientInstall(installPath, MainActivity.this,".uis.MainActivity"); }
}else{ }
Utils.installApp(getApplicationContext(),new File(installPath));
}
runOnUiThread(()->{
if (mLoadDialog != null) {
mLoadDialog.dismissDialog();
mLoadDialog=null;
}
});
});
}else if (downStatus==DOWN_ERROR){ @Override
showTips("下载更新失败"); public void onUpdateConfig(List<ConfigEntity> configList, int type) {
FileUtil.deleteFile(installPath); //配置改变,更新接口
} //Log.i(TAG, "onUpdateConfig: config="+configBean.toString()+",type="+type);
}); /*if (type==ENTER_TYPE){
ApiQuest.getInstance().startEnterApi(configList);
}else if (type == LEAVE_TYPE){
ApiQuest.getInstance().startLeaveApi(configList);
}*/
/*for (ConfigEntity config : configList) {
Log.i(TAG, "onUpdateConfig: pass="+config.getPassword());
Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp());
}*/
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
} }
public List<StatusInfoBean> statusInfoBeans = new ArrayList<>();
@Override @Override
public void onDevicesPort(StatusInfoBean statusInfoBean) { public void getAllPassInfo(List<PersonEntity> passAllEntities, int type) {
//Log.i(TAG, "onDevicesPort: statusInfoBean="+statusInfoBean.toString()); runOnUiThread(()->{
statusInfoBeans.add(0,statusInfoBean); updatePassInfo(passAllEntities, type);
SharedUtil.getInstance(this).writeShared("statusInfoBeans",statusInfoBeans); });
} }
private void clearStatusInfoBeans(){ @Override
statusInfoBeans.clear(); public void onAllConnectStatus(boolean hasConnect, int type) {
SharedUtil.getInstance(this).writeShared("statusInfoBeans",statusInfoBeans); /*Log.i(TAG, "onAllConnectStatus: 接收到的连接状态 hasConnect="+hasConnect);
runOnUiThread(()->{
if (type==ENTER_TYPE){
if (!hasConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{
mBinding.tvEnterError.setVisibility(View.GONE);
}
}else if (type == LEAVE_TYPE){
if (!hasConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{
mBinding.tvLeaveError.setVisibility(View.GONE);
}
}
});*/
} }
} }
\ No newline at end of file
package com.srthinker.statinfo.uis; package com.srthinker.statinfo.uis;
import static com.srthinker.statinfo.constant.Const.DEVICE_TYPE;
import static com.srthinker.statinfo.constant.Const.SN_PATH;
import static com.srthinker.statinfo.constant.GroupConst.BUILD;
import static com.srthinker.statinfo.constant.GroupConst.BUILD_ID;
import static com.srthinker.statinfo.constant.GroupConst.OUTRIGGER;
import static com.srthinker.statinfo.constant.GroupConst.OUTRIGGER_ID;
import static com.srthinker.statinfo.constant.GroupConst.SUPERVISOR;
import static com.srthinker.statinfo.constant.GroupConst.SUPERVISOR_ID;
import static com.srthinker.statinfo.constant.GroupConst.WATERPROOF;
import static com.srthinker.statinfo.constant.GroupConst.WATERPROOF_ID;
import static com.srthinker.statinfo.constant.InOutType.ENTER_TYPE; import static com.srthinker.statinfo.constant.InOutType.ENTER_TYPE;
import static com.srthinker.statinfo.constant.InOutType.LEAVE_TYPE; import static com.srthinker.statinfo.constant.InOutType.LEAVE_TYPE;
import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_ERROR; import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_ERROR;
...@@ -17,46 +7,35 @@ import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_FINISH; ...@@ -17,46 +7,35 @@ import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_FINISH;
import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_START; import static com.srthinker.statinfo.download.upper.DownStatus.DOWN_START;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.srthinker.statinfo.R; import com.srthinker.statinfo.adapter.GroupShowAdapter;
import com.srthinker.statinfo.adapter.EnterAdapter; import com.srthinker.statinfo.bean.Group2Bean;
import com.srthinker.statinfo.adapter.GroupAdapter; import com.srthinker.statinfo.bean.StatusInfoBean;
import com.srthinker.statinfo.adapter.LeaveAdapter; import com.srthinker.statinfo.constant.GroupConst;
import com.srthinker.statinfo.bean.GroupBean;
import com.srthinker.statinfo.bean.TimeBean;
import com.srthinker.statinfo.database.PersonMgr;
import com.srthinker.statinfo.database.entity.ConfigEntity; import com.srthinker.statinfo.database.entity.ConfigEntity;
import com.srthinker.statinfo.database.entity.PersonEntity; import com.srthinker.statinfo.database.entity.PersonEntity;
import com.srthinker.statinfo.database.helper.ConfigHelper; import com.srthinker.statinfo.database.helper.ConfigHelper;
import com.srthinker.statinfo.database.helper.PersonHelper; import com.srthinker.statinfo.database.helper.PersonHelper;
import com.srthinker.statinfo.databinding.ActivityMainBinding; import com.srthinker.statinfo.databinding.ActivityNewMainBinding;
import com.srthinker.statinfo.download.upper.DownloadViewModel; import com.srthinker.statinfo.download.upper.DownloadViewModel;
import com.srthinker.statinfo.download.upper.UpperDownloadCallback; import com.srthinker.statinfo.download.upper.UpperDownloadCallback;
import com.srthinker.statinfo.listener.ConfigCallback;
import com.srthinker.statinfo.listener.OnTimeUpdateListener;
import com.srthinker.statinfo.listener.QueryPersonCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesCallback; import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.presenter.ApiManager; import com.srthinker.statinfo.listener.upper.UpperDevicesPortCallback;
import com.srthinker.statinfo.presenter.ApiQuest; import com.srthinker.statinfo.presenter.ApiQuest;
import com.srthinker.statinfo.presenter.RealTimeClock;
import com.srthinker.statinfo.presenter.StatSize; import com.srthinker.statinfo.presenter.StatSize;
import com.srthinker.statinfo.uis.fragment.ConfigDlgFragment; import com.srthinker.statinfo.uis.news.SettingActivity;
import com.srthinker.statinfo.update.MDownloadCallBack; import com.srthinker.statinfo.update.MDownloadCallBack;
import com.srthinker.statinfo.update.UpdateInfo; import com.srthinker.statinfo.update.UpdateInfo;
import com.srthinker.statinfo.util.common.ClickUtil;
import com.srthinker.statinfo.util.common.FileUtil; import com.srthinker.statinfo.util.common.FileUtil;
import com.srthinker.statinfo.util.common.GsonUtil; import com.srthinker.statinfo.util.common.GsonUtil;
import com.srthinker.statinfo.util.common.PermissionUtil; import com.srthinker.statinfo.util.common.PermissionUtil;
...@@ -71,113 +50,113 @@ import java.util.ArrayList; ...@@ -71,113 +50,113 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
public class MainOldActivity extends BaseActivity implements OnTimeUpdateListener, MDownloadCallBack, UpperDownloadCallback, NetworkIPMonitor.OnIPChangeCallback, ConfigCallback, QueryPersonCallback, UpperDevicesCallback { public class MainActivity1 extends BaseActivity implements NetworkIPMonitor.OnIPChangeCallback, UpperDevicesCallback, MDownloadCallBack, UpperDownloadCallback, UpperDevicesPortCallback {
private static final String TAG = "MainActivity"; private static final String TAG = "NewMainActivity";
private com.srthinker.statinfo.databinding.ActivityMainBinding mBinding; private com.srthinker.statinfo.databinding.ActivityNewMainBinding mBinding;
private RealTimeClock mRealTimeClock; private NetworkIPMonitor networkIPMonitor;
private float groupSize = 100;
private boolean isPermission;
private List<PersonEntity> enterBeans; private List<PersonEntity> enterBeans;
private List<PersonEntity> leaveBeans; private List<PersonEntity> leaveBeans;
private EnterAdapter enterAdapter;
private LeaveAdapter leaveAdapter;
private NetworkIPMonitor networkIPMonitor;
private String installPath = ""; private String installPath = "";
private LoadDialog mLoadDialog; private LoadDialog mLoadDialog;
//private String savePath = "/sdcard/update/StatInfo.apk"; //private String savePath = "/sdcard/update/StatInfo.apk";
//getFilesDir() + "/update", "StatInfo.apk" //getFilesDir() + "/update", "StatInfo.apk"
private String savePath = Environment.getExternalStorageDirectory().getPath() + "/update"; private String savePath = Environment.getExternalStorageDirectory().getPath() + "/update";
private String sessionId;
private ApiManager enterMgr;
private static ScheduledExecutorService executor;
private int lastEnterSize = 0; private int lastEnterSize = 0;
private int lastLeaveSize = 0; private int lastLeaveSize = 0;
private int lastPresentSize = 0; private int lastPresentSize = 0;
private String deviceSn;
private List<PersonEntity> mQueryPersonList; private List<PersonEntity> mQueryPersonList;
private GroupAdapter groupAdapter;
private HashMap<Integer, Integer> groupEnterHashMap=null; private HashMap<Integer, Integer> groupEnterHashMap=null;
private HashMap<Integer, Integer> groupLeaveHashMap=null; private HashMap<Integer, Integer> groupLeaveHashMap=null;
private HashMap<Integer,Integer> groupPresentHashMap=null; private HashMap<Integer,Integer> groupPresentHashMap=null;
private boolean isPermission;
public static boolean NEED_NO_REPET = true; //是否需要去重,false:不需要,true:需要 public static boolean NEED_NO_REPET = true; //是否需要去重,false:不需要,true:需要
private int group;
private GroupShowAdapter showAdapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main); //setContentView(R.layout.activity_new_main);
mBinding = ActivityMainBinding.inflate(getLayoutInflater()); mBinding = ActivityNewMainBinding.inflate(getLayoutInflater());
setContentView(mBinding.getRoot()); setContentView(mBinding.getRoot());
checkAllPermission();
initData(); initData();
initView(); initView();
checkAllPermission();
} }
@SuppressLint("SdCardPath")
@Override @Override
protected void initData() { protected void initData() {
//获取Sn
deviceSn = FileUtil.readTextFromFile(SN_PATH);
networkIPMonitor = new NetworkIPMonitor(this); networkIPMonitor = new NetworkIPMonitor(this);
enterBeans = new ArrayList<>();
leaveBeans = new ArrayList<>();
/*for (int i = 0; i < 12; i++) {
enterBeans.add(new PeopleBean("08:14","王大锤"));
}
for (int i = 0; i < 5; i++) {
leaveBeans.add(new PeopleBean("08:04","赵美丽"));
}*/
networkIPMonitor.startMonitoring(); networkIPMonitor.startMonitoring();
networkIPMonitor.setOnIPChangeCallback(this); networkIPMonitor.setOnIPChangeCallback(this);
enterBeans = new ArrayList<>();
leaveBeans = new ArrayList<>();
} }
@SuppressLint("SetTextI18n")
@Override @Override
protected void initView() { protected void initView() {
initNumber();
updateTime();
initGroup(); initGroup();
initPeopleList(); mBinding.tvSetting.setOnClickListener(v->{
//mLoadDialog = LoadDialog.getInstance(this); Intent intent = new Intent(this, SettingActivity.class);
mLoadDialog = new LoadDialog(this); startActivity(intent);
//Log.i(TAG, "initView: deviceSn="+deviceSn+"V"+ Utils.getVersionName(this));
mBinding.tvDeviceDesc.setText(DEVICE_TYPE+" "+deviceSn+" V"+ Utils.getVersionName(this));
//getResp();
mBinding.tvEnterText.setOnClickListener(v->{
showConfigDialog(ENTER_TYPE);
});
mBinding.tvLeaveText.setOnClickListener(v->{
showConfigDialog(LEAVE_TYPE);
});
mBinding.btnGroupDetail.setOnClickListener(v->{
ApiQuest.getInstance().queryPersons(this);
ClickUtil.disableClick(mBinding.btnGroupDetail);
}); });
mLoadDialog = new LoadDialog(this); //1.0.2版本把这个漏了
} }
private void showConfigDialog(int type) { /*private void initGroup() {
ConfigDlgFragment configDlgFragment = ConfigDlgFragment.getInstance(type); int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
configDlgFragment.setUsername("admin"); int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
configDlgFragment.setConfigCallback(this); int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
if (configDlgFragment.isResumed()){ int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
return; *//*mBinding.ngvBuild.initItem("工地班组",build,groupSize);
mBinding.ngvWaterproof.initItem("防水班组",waterproof,groupSize);
mBinding.ngvOutrigger.initItem("外架班组",outrigger,groupSize);
mBinding.ngvSupervisor.initItem("监理单位",supervisor,groupSize);*//*
mBinding.ngvBuild.initItem("工地班组",build);
mBinding.ngvWaterproof.initItem("防水班组",waterproof);
mBinding.ngvOutrigger.initItem("外架班组",outrigger);
mBinding.ngvSupervisor.initItem("监理单位",supervisor);
}*/
private void initGroup(){
GridLayoutManager gLM = new GridLayoutManager(this, 4, RecyclerView.HORIZONTAL, false);
mBinding.rvGroupTotal.setLayoutManager(gLM);
showAdapter = new GroupShowAdapter(this, GroupConst.group2BeansConst);
mBinding.rvGroupTotal.setAdapter(showAdapter);
}
private void checkAllPermission() {
isPermission = PermissionUtil.checkMultiPermission(this, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.INTERNET
}, 4096);
if (!isPermission){
Toast.makeText(this, "需要允许权限才能正常使用哦", Toast.LENGTH_SHORT).show();
} }
configDlgFragment.showNow(getSupportFragmentManager(),configDlgFragment.getClass().getSimpleName());
configDlgFragment.setCancelable(false);
} }
/*private void updateGroup() {
int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
mBinding.ngvBuild.setNumber(build);
mBinding.ngvWaterproof.setNumber(waterproof);
mBinding.ngvOutrigger.setNumber(outrigger);
mBinding.ngvSupervisor.setNumber(supervisor);
}*/
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
Log.i(TAG, "onResume: Main-Resume"); Log.i(TAG, "onResume: Main-Resume");
//如果设置页面有更新,主页面也需要进行访问接口,绑定监听
updateApi();
//获取最新的人员信息列表 //获取最新的人员信息列表
mQueryPersonList = PersonHelper.getInstance().queryAll(); mQueryPersonList = PersonHelper.getInstance().queryAll();
//更新分组情况 //更新分组情况
...@@ -187,242 +166,141 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene ...@@ -187,242 +166,141 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene
detectUpgrade(); //检测版本升级 detectUpgrade(); //检测版本升级
} }
@Override private void updateApi() {
protected void onDestroy() { boolean isModified = SharedUtil.getInstance(this).readShared("isModified", false);
Log.i(TAG, "onDestroy: Main--destroy"); if (isModified){
questApi();
networkIPMonitor.stopMonitoring(); SharedUtil.getInstance(this).writeShared("isModified",false);
mRealTimeClock.stop(); }
//关闭循环拉取
//executor.shutdownNow();
/*if (enterMgr != null) {
enterMgr.stop();
}*/
ApiQuest.getInstance().stopApi();
super.onDestroy();
} }
private void detectUpgrade() { private void detectUpgrade() {
/*NetworkViewModel networkViewModel = new NetworkViewModel(); /*NetworkViewModel networkViewModel = new NetworkViewModel();
networkViewModel.init(this,this); networkViewModel.init(this,this);
networkViewModel.setDownloadCallback(this); networkViewModel.setDownloadCallback(this);
networkViewModel.getLastestVersion(deviceSn,DEVICE_TYPE);*/ networkViewModel.getLastestVersion(DEVICE_SN,DEVICE_TYPE);*/
}
private void checkAllPermission() {
isPermission = PermissionUtil.checkMultiPermission(this, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.INTERNET
}, 4096);
if (!isPermission){
Toast.makeText(this, "需要允许权限才能正常使用哦", Toast.LENGTH_SHORT).show();
}
}
private void initNumber() {
mBinding.nvEnter.initItem(lastEnterSize,"进去人数", R.mipmap.enter_bg);
mBinding.nvLeave.initItem(lastLeaveSize,"离开人数", R.mipmap.leave_bg);
mBinding.nvPresent.initItem(lastPresentSize,"在场人数", R.mipmap.present_bg);
} }
private void initPeopleList() { @Override
LinearLayoutManager enterLLM = new LinearLayoutManager(this, RecyclerView.VERTICAL, false); protected void onDestroy() {
mBinding.rvEnterList.setLayoutManager(enterLLM); Log.i(TAG, "onDestroy: Main--destroy");
enterAdapter = new EnterAdapter(this, enterBeans); networkIPMonitor.stopMonitoring();
mBinding.rvEnterList.setAdapter(enterAdapter); ApiQuest.getInstance().stopApi();
LinearLayoutManager leaveLLM = new LinearLayoutManager(this, RecyclerView.VERTICAL, false); clearStatusInfoBeans();
mBinding.rvLeaveList.setLayoutManager(leaveLLM); super.onDestroy();
leaveAdapter = new LeaveAdapter(this, leaveBeans);
mBinding.rvLeaveList.setAdapter(leaveAdapter);
}
private void initGroup() {
GridLayoutManager groupGLM = new GridLayoutManager(this, 4);
mBinding.rvGroup.setLayoutManager(groupGLM);
ArrayList<GroupBean> groupBeans = updateGroup();
groupAdapter = new GroupAdapter(this, groupBeans);
mBinding.rvGroup.setAdapter(groupAdapter);
/*mBinding.gvWaterproof.initItem("防水班组",34,R.color.color_2D52E3);
mBinding.gvOutrigger.initItem("外架班组",12,R.color.color_694BFF);
mBinding.gvBuild.initItem("工地班组",26,R.color.color_8A34D5);
mBinding.gvSupervisor.initItem("监理单位",28,R.color.color_00A89C);*/
}
private ArrayList<GroupBean> updateGroup() {
ArrayList<GroupBean> groupBeans = new ArrayList<>();
int waterproof = SharedUtil.getInstance(this).readShared(WATERPROOF, 0);
int outrigger = SharedUtil.getInstance(this).readShared(OUTRIGGER, 0);
int build = SharedUtil.getInstance(this).readShared(BUILD, 0);
int supervisor = SharedUtil.getInstance(this).readShared(SUPERVISOR, 0);
groupBeans.add(new GroupBean("防水班组",waterproof,R.color.color_2D52E3,WATERPROOF));
groupBeans.add(new GroupBean("外架班组",outrigger,R.color.color_694BFF,OUTRIGGER));
groupBeans.add(new GroupBean("工地班组",build,R.color.color_8A34D5,BUILD));
groupBeans.add(new GroupBean("监理单位",supervisor,R.color.color_00A89C,SUPERVISOR));
return groupBeans;
}
private void updateTime() {
mRealTimeClock = new RealTimeClock();
mRealTimeClock.setOnTimeUpdateListener(this);
mRealTimeClock.start();
} }
@SuppressLint("SetTextI18n")
@Override @Override
public void OnTimeUpdate(TimeBean timeBean) { public void OnIPChange(String ipAddress, String networkType) {
if (timeBean != null) { Log.i(TAG, "OnIPChange: change==>");
mBinding.tvTime.setText(timeBean.getyMD()+" "+timeBean.getWeek()+" "+timeBean.getHm()); //questApi();
} questApi();
} }
private void questApi() {
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
ApiQuest.getInstance().setOnUpperDevicesPortCallback(this);
}
@Override @Override
public void checkResult(boolean needUpdate, boolean canInstall, UpdateInfo onlineInfo) { public void OnIPLost(String error) {
if (needUpdate){ ApiQuest.getInstance().stopApi();
if (onlineInfo!=null){ //修改状态
Log.i(TAG, "checkResult: onlineInfo="+ GsonUtil.toJsonString(onlineInfo)); List<ConfigEntity> configEntities = ConfigHelper.getInstance().queryAll();
//Environment.getExternalStorageDirectory().getPath()=/storage/emulated/0 for (ConfigEntity configEntity : configEntities) {
//getFilesDir()=installPath=/data/user/0/com.srthinker.statinfo/files configEntity.setConnect(false);
//String installPath = getFilesDir() + "/" + "StatInfo.apk"; //更新ip接口状态
//boolean isCreate = FileUtil.createFile(getFilesDir() + "/update", "StatInfo.apk"); ConfigHelper.getInstance().update(configEntity);
FileUtil.deleteFile(savePath+File.separator+"StatInfo.apk");
boolean isCreate = FileUtil.createFile( savePath+File.separator, "StatInfo.apk");
if (isCreate){
//installPath = getFilesDir()+"/update/StatInfo.apk";
installPath = savePath+File.separator+"StatInfo.apk";
DownloadViewModel downloadViewModel = new DownloadViewModel(this);
downloadViewModel.initData();
downloadViewModel.startDownload(onlineInfo.getDownloadUrl(),installPath);
downloadViewModel.setOnUpperDownloadCallback(this);
}
}
} }
} }
@Override @Override
public void onProgress(String progress, String filePath) { public void getAllPassInfo(List<PersonEntity> passAllEntities, int type) {
runOnUiThread(()->{ runOnUiThread(()->{
//Log.i(TAG, "onProgress: progress="+progress); updatePassInfo(passAllEntities, type);
String desc = "下载更新中..."+progress;
if (mLoadDialog != null) {
mLoadDialog.setContent(desc);
mLoadDialog.showDialog();
}
}); });
} }
@Override @Override
public void onResult(int downStatus, String filePath) { public void onAllConnectStatus(boolean hasConnect, int type) {
runOnUiThread(()->{ /*HashMap<String, Boolean> devicesConnect = MyApplication.getInstance().devicesConnect;
if (downStatus == DOWN_START){ if (type==ENTER_TYPE){
String desc = "准备下载更新"; devicesConnect.put("enter_connect",hasConnect);
if (mLoadDialog != null) { // SharedUtil.getInstance(this).writeShared("enter_connect",hasConnect);
mLoadDialog.setContent(desc); }else if (type==LEAVE_TYPE){
mLoadDialog.showDialog(); // SharedUtil.getInstance(this).writeShared("leave_connect",hasConnect);
} devicesConnect.put("leave_connect",hasConnect);
} else if (downStatus== DOWN_FINISH){ }*/
//安装更新
//Log.i(TAG, "onResult:进来多少次");
//showTips("更新版本,将进行安装");
String desc = "进行安装,请稍等";
if (mLoadDialog != null) {
mLoadDialog.setContent(desc);
mLoadDialog.showDialog();
}
//Utils.installApp(getApplicationContext(),new File(installPath));
//有静默安装的话需要开新线程,不然前面的弹框不进行显示
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
boolean restricted = Utils.isRootPermissionRestricted();
if (!restricted){
Utils.clientInstall(installPath, MainOldActivity.this,".uis.MainActivity");
}else{
Utils.installApp(getApplicationContext(),new File(installPath));
}
runOnUiThread(()->{
if (mLoadDialog != null) {
mLoadDialog.dismissDialog();
mLoadDialog=null;
}
});
});
}else if (downStatus==DOWN_ERROR){
showTips("下载更新失败");
FileUtil.deleteFile(installPath);
}
});
} }
private void updatePassInfo(List<PersonEntity> passEntities, int type) { private void updatePassInfo(List<PersonEntity> passEntities, int type) {
Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size()); if (passEntities != null) {
Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size());
}
//Log.i(TAG, "updatePassInfo: 进还是出="+type);
/*for (PersonEntity passEntity : passEntities) { /*for (PersonEntity passEntity : passEntities) {
Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name()); Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name());
}*/ }*/
if (type ==ENTER_TYPE){ if (type ==ENTER_TYPE){
if (passEntities != null) { if (passEntities != null) {
if (enterAdapter != null) { int size = passEntities.size();
int size = passEntities.size(); if (size!=lastEnterSize){
if (enterBeans!=null&&size!=enterBeans.size()){ /*//更新进出情况
//更新进出情况 //enterBeans = passEntities; 全局变量直接赋值会出现问题
//enterBeans = passEntities; 全局变量直接赋值会出现问题 enterBeans.clear();
enterBeans.clear(); enterBeans.addAll(passEntities);
enterBeans.addAll(passEntities); enterAdapter.setDataList(passEntities);
enterAdapter.setDataList(passEntities); //更新人员情况(是否要根据id去重)
//更新人员情况(是否要根据id去重) if (NEED_NO_REPET) {
if (NEED_NO_REPET) { List<PersonEntity> enterListNo = StatSize.filterList(passEntities);
List<PersonEntity> enterListNo = StatSize.filterList(passEntities); lastEnterSize = enterListNo.size();
lastEnterSize = enterListNo.size(); }else{
}else{ lastEnterSize = size;
lastEnterSize = size;
}
lastPresentSize = lastEnterSize-lastLeaveSize;
mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据id去重)
groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
/* Log.i(TAG, "updatePassInfo: enterBeans.size="+enterBeans.size()); lastPresentSize = lastEnterSize-lastLeaveSize;
Log.i(TAG, "updatePassInfo: adapter.size="+enterAdapter.getDataList().size());*/ mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);*/
enterBeans.clear();
enterBeans.addAll(passEntities);
lastEnterSize = size;
//更新分组情况(是否要根据id去重)
groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
//leaveBeans = passEntities; //leaveBeans = passEntities;
if (passEntities != null) { if (passEntities != null) {
if (leaveAdapter != null) { int size = passEntities.size();
int size = passEntities.size(); //进出有变化时才更新
//进出有变化时才更新 if (size!=lastLeaveSize){
if (leaveBeans!=null&&size!=leaveBeans.size()){ /*leaveBeans.clear();
leaveBeans.clear(); leaveBeans.addAll(passEntities);
leaveBeans.addAll(passEntities); //更新进出情况
//更新进出情况 leaveAdapter.setDataList(passEntities);
leaveAdapter.setDataList(passEntities); //更新人员情况(是否要根据id去重)
//更新人员情况(是否要根据id去重) if (NEED_NO_REPET) {
if (NEED_NO_REPET) { List<PersonEntity> leaveListNo = StatSize.filterList(passEntities);
List<PersonEntity> leaveListNo = StatSize.filterList(passEntities); lastLeaveSize = leaveListNo.size();
lastLeaveSize = leaveListNo.size(); }else{
}else{ lastLeaveSize = size;
lastLeaveSize = size;
}
lastPresentSize = lastEnterSize-lastLeaveSize;
mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);
//更新分组情况(是否要根据id去重)
groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
/*Log.i(TAG, "updatePassInfo: leaveBeans.size="+leaveBeans.size()); lastPresentSize = lastEnterSize-lastLeaveSize;
Log.i(TAG, "updatePassInfo: adapter.size="+leaveAdapter.getDataList().size());*/ mBinding.nvEnter.setNumber(lastEnterSize);
mBinding.nvLeave.setNumber(lastLeaveSize);
mBinding.nvPresent.setNumber(lastPresentSize);*/
leaveBeans.clear();
leaveBeans.addAll(passEntities);
lastLeaveSize = size;
//更新分组情况(是否要根据id去重)
groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
} }
...@@ -445,10 +323,13 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene ...@@ -445,10 +323,13 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene
} }
for (PersonEntity personEntity : personEntityList) { for (PersonEntity personEntity : personEntityList) {
String personId = personEntity.getId(); String personId = personEntity.getId();
String personName = personEntity.getPerson_name();
for (PersonEntity queryPerson : mQueryPersonList) { for (PersonEntity queryPerson : mQueryPersonList) {
String queryId = queryPerson.getId(); String queryId = queryPerson.getId();
String queryName = queryPerson.getPerson_name();
int group = queryPerson.getGroup(); int group = queryPerson.getGroup();
if (TextUtils.equals(personId,queryId)&& groupSizeHashMap.containsKey(group)){ //改成对比名字
if (TextUtils.equals(personName,queryName)&& groupSizeHashMap.containsKey(group)){
int totalSize = groupSizeHashMap.get(group); int totalSize = groupSizeHashMap.get(group);
groupSizeHashMap.put(group,totalSize+1); groupSizeHashMap.put(group,totalSize+1);
} }
...@@ -484,15 +365,25 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene ...@@ -484,15 +365,25 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene
} }
} }
//如果只有一个人,从一个组换到另一个组,之前的数据没有清空,需要先进行清空,置空为0 //如果只有一个人,从一个组换到另一个组,之前的数据没有清空,需要先进行清空,置空为0
SharedUtil.getInstance(this).writeShared(WATERPROOF,0); /*SharedUtil.getInstance(this).writeShared(WATERPROOF,0);
SharedUtil.getInstance(this).writeShared(OUTRIGGER,0); SharedUtil.getInstance(this).writeShared(OUTRIGGER,0);
SharedUtil.getInstance(this).writeShared(BUILD,0); SharedUtil.getInstance(this).writeShared(BUILD,0);
SharedUtil.getInstance(this).writeShared(SUPERVISOR,0); SharedUtil.getInstance(this).writeShared(SUPERVISOR,0);*/
//清空
for (Group2Bean group2Bean : GroupConst.group2BeansConst) {
group2Bean.setNumber(0);
}
for (Map.Entry<Integer, Integer> presentEntry : groupPresentHashMap.entrySet()) { for (Map.Entry<Integer, Integer> presentEntry : groupPresentHashMap.entrySet()) {
int group = presentEntry.getKey(); int group = presentEntry.getKey();
int presentSize = presentEntry.getValue(); int presentSize = presentEntry.getValue();
Log.i(TAG, "updatePresentSize: group="+group+",presentSize="+presentSize); Log.i(TAG, "updatePresentSize: group="+group+",presentSize="+presentSize);
switch (group){ for (Group2Bean group2Bean : GroupConst.group2BeansConst) {
if (group2Bean.getGroup_id()==group){
group2Bean.setNumber(presentSize);
break;
}
}
/* switch (group){
case WATERPROOF_ID: case WATERPROOF_ID:
SharedUtil.getInstance(this).writeShared(WATERPROOF,presentSize); SharedUtil.getInstance(this).writeShared(WATERPROOF,presentSize);
break; break;
...@@ -505,104 +396,102 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene ...@@ -505,104 +396,102 @@ public class MainOldActivity extends BaseActivity implements OnTimeUpdateListene
case SUPERVISOR_ID: case SUPERVISOR_ID:
SharedUtil.getInstance(this).writeShared(SUPERVISOR,presentSize); SharedUtil.getInstance(this).writeShared(SUPERVISOR,presentSize);
break; break;
} }*/
}
ArrayList<GroupBean> groupBeans = updateGroup();
if (groupAdapter != null) {
groupAdapter.setDataList(groupBeans);
} }
//要更新演示页面的分组请求
//updateGroup();
showAdapter.setDataList(GroupConst.group2BeansConst);
} }
@Override @Override
public void onQueryStatus(String desc, boolean status) { public void checkResult(boolean needUpdate, boolean canInstall, UpdateInfo onlineInfo) {
runOnUiThread(()->{ if (needUpdate){
if (!status){ if (onlineInfo!=null){
showTips(desc); Log.i(TAG, "checkResult: onlineInfo="+ GsonUtil.toJsonString(onlineInfo));
//Environment.getExternalStorageDirectory().getPath()=/storage/emulated/0
//getFilesDir()=installPath=/data/user/0/com.srthinker.statinfo/files
//String installPath = getFilesDir() + "/" + "StatInfo.apk";
//boolean isCreate = FileUtil.createFile(getFilesDir() + "/update", "StatInfo.apk");
FileUtil.deleteFile(savePath+ File.separator+"StatInfo.apk");
boolean isCreate = FileUtil.createFile( savePath+File.separator, "StatInfo.apk");
if (isCreate){
//installPath = getFilesDir()+"/update/StatInfo.apk";
installPath = savePath+File.separator+"StatInfo.apk";
DownloadViewModel downloadViewModel = new DownloadViewModel(this);
downloadViewModel.initData();
downloadViewModel.startDownload(onlineInfo.getDownloadUrl(),installPath);
downloadViewModel.setOnUpperDownloadCallback(this);
}
} }
});
}
} }
@Override @Override
public void getTotalPerson(List<PersonEntity> personEntities,int type) { public void onProgress(String progress, String filePath) {
Log.i(TAG, "getTotalPerson: 已获取总数:personEntities.size="+personEntities.size());
PersonMgr.getInstance().updatePersonThread(personEntities, () -> {
runOnUiThread(()->{
ClickUtil.enableClick(mBinding.btnGroupDetail);
});
Intent intent = new Intent(MainOldActivity.this, GroupActivity.class);
startActivity(intent);
});
}
@Override
public void OnIPChange(String ipAddress, String networkType) {
Log.i(TAG, "OnIPChange: change==>");
//questApi();
/*List<ConfigBean> enterConfigList = SharedUtil.getInstance(this).readSharedList(ENTER_TYPE, ConfigBean.class, "");
ApiQuest.startEnterApi(enterConfigList,this);
List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, "");
ApiQuest.startLeaveApi(leaveConfigList,this);*/
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
List<ConfigEntity> leaveConfigList = ConfigHelper.getInstance().queryByType(LEAVE_TYPE);
ApiQuest.getInstance().startApi(leaveConfigList,LEAVE_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
}
@Override
public void OnIPLost(String error) {
ApiQuest.getInstance().stopApi();
}
@Override
public void onUpdateConfig(List<ConfigEntity> configList, int type) {
//配置改变,更新接口
//Log.i(TAG, "onUpdateConfig: config="+configBean.toString()+",type="+type);
/*if (type==ENTER_TYPE){
ApiQuest.getInstance().startEnterApi(configList);
}else if (type == LEAVE_TYPE){
ApiQuest.getInstance().startLeaveApi(configList);
}*/
/*for (ConfigEntity config : configList) {
Log.i(TAG, "onUpdateConfig: pass="+config.getPassword());
Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp());
}*/
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
}
@Override
public void getAllPassInfo(List<PersonEntity> passAllEntities, int type) {
runOnUiThread(()->{ runOnUiThread(()->{
updatePassInfo(passAllEntities, type); //Log.i(TAG, "onProgress: progress="+progress);
String desc = "下载更新中..."+progress;
if (mLoadDialog != null) {
mLoadDialog.setContent(desc);
mLoadDialog.showDialog();
}
}); });
} }
@Override @Override
public void onAllConnectStatus(boolean hasConnect, int type) { public void onResult(int downStatus, String filePath) {
Log.i(TAG, "onAllConnectStatus: 接收到的连接状态 hasConnect="+hasConnect);
runOnUiThread(()->{ runOnUiThread(()->{
if (type==ENTER_TYPE){ if (downStatus == DOWN_START){
if (!hasConnect) { String desc = "准备下载更新";
mBinding.tvEnterError.setVisibility(View.VISIBLE); if (mLoadDialog != null) {
}else{ mLoadDialog.setContent(desc);
mBinding.tvEnterError.setVisibility(View.GONE); mLoadDialog.showDialog();
} }
} else if (downStatus== DOWN_FINISH){
//安装更新
//Log.i(TAG, "onResult:进来多少次");
//showTips("更新版本,将进行安装");
}else if (type == LEAVE_TYPE){ String desc = "进行安装,请稍等";
if (!hasConnect) { if (mLoadDialog != null) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE); mLoadDialog.setContent(desc);
}else{ mLoadDialog.showDialog();
mBinding.tvLeaveError.setVisibility(View.GONE);
} }
//Utils.installApp(getApplicationContext(),new File(installPath));
//有静默安装的话需要开新线程,不然前面的弹框不进行显示
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
boolean restricted = Utils.isRootPermissionRestricted();
if (!restricted){
Utils.clientInstall(installPath, MainActivity1.this,".uis.MainActivity");
}else{
Utils.installApp(getApplicationContext(),new File(installPath));
}
runOnUiThread(()->{
if (mLoadDialog != null) {
mLoadDialog.dismissDialog();
mLoadDialog=null;
}
});
});
}else if (downStatus==DOWN_ERROR){
showTips("下载更新失败");
FileUtil.deleteFile(installPath);
} }
}); });
} }
public List<StatusInfoBean> statusInfoBeans = new ArrayList<>();
@Override
public void onDevicesPort(StatusInfoBean statusInfoBean) {
//Log.i(TAG, "onDevicesPort: statusInfoBean="+statusInfoBean.toString());
statusInfoBeans.add(0,statusInfoBean);
SharedUtil.getInstance(this).writeShared("statusInfoBeans",statusInfoBeans);
}
private void clearStatusInfoBeans(){
statusInfoBeans.clear();
SharedUtil.getInstance(this).writeShared("statusInfoBeans",statusInfoBeans);
}
} }
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:orientation="vertical" android:orientation="vertical"
android:background="@color/bg_070A2E" android:background="@color/bg_070A2E"
tools:context=".uis.MainOldActivity"> tools:context=".uis.MainActivity">
<RelativeLayout <RelativeLayout
android:layout_width="939.59dp" android:layout_width="939.59dp"
...@@ -109,8 +109,9 @@ ...@@ -109,8 +109,9 @@
android:id="@+id/rv_group" android:id="@+id/rv_group"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="32dp" android:layout_gravity="center"
android:layout_marginLeft="10dp"/> android:layout_marginTop="15dp"
/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="653dp" android:layout_width="653dp"
...@@ -195,7 +196,7 @@ ...@@ -195,7 +196,7 @@
android:textSize="@dimen/text_10" android:textSize="@dimen/text_10"
android:layout_toRightOf="@+id/tv_enter_text" android:layout_toRightOf="@+id/tv_enter_text"
android:layout_alignBottom="@+id/tv_enter_text" android:layout_alignBottom="@+id/tv_enter_text"
android:visibility="visible" android:visibility="invisible"
android:layout_marginLeft="5dp"/> android:layout_marginLeft="5dp"/>
<TextView <TextView
android:id="@+id/tv_leave_text" android:id="@+id/tv_leave_text"
...@@ -216,7 +217,7 @@ ...@@ -216,7 +217,7 @@
android:textSize="@dimen/text_10" android:textSize="@dimen/text_10"
android:layout_toLeftOf="@+id/tv_leave_text" android:layout_toLeftOf="@+id/tv_leave_text"
android:layout_alignBottom="@+id/tv_leave_text" android:layout_alignBottom="@+id/tv_leave_text"
android:visibility="visible" android:visibility="invisible"
android:layout_marginRight="5dp"/> android:layout_marginRight="5dp"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -245,5 +246,6 @@ ...@@ -245,5 +246,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="left|center" android:gravity="left|center"
android:textColor="@color/white" android:textColor="@color/white"
android:layout_marginLeft="15dp"
android:textSize="@dimen/text_10"/> android:textSize="@dimen/text_10"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black" android:background="@color/black"
tools:context=".uis.MainActivity"> tools:context=".uis.MainActivity1">
<TextView <TextView
android:id="@+id/tv_setting" android:id="@+id/tv_setting"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="42dp" android:layout_height="42dp"
android:layout_marginBottom="32dp" android:layout_marginBottom="22dp"
android:background="@color/color_2D52E3"> android:background="@color/color_2D52E3">
<TextView <TextView
android:id="@+id/tv_title" android:id="@+id/tv_title"
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:layout_gravity="center"
android:padding="10dp"
android:gravity="center"> android:gravity="center">
</androidx.recyclerview.widget.RecyclerView> </androidx.recyclerview.widget.RecyclerView>
<LinearLayout <LinearLayout
......
...@@ -11,5 +11,7 @@ ...@@ -11,5 +11,7 @@
<dimen name="text_15">15sp</dimen> <dimen name="text_15">15sp</dimen>
<dimen name="text_11">11sp</dimen> <dimen name="text_11">11sp</dimen>
<dimen name="dlg_margin">10dp</dimen> <dimen name="dlg_margin">10dp</dimen>
<dimen name="display_text">77sp</dimen> //一列:95sp <dimen name="display_text">77sp</dimen>
<dimen name="text_30">30sp</dimen>
//一列:95sp
</resources> </resources>
\ No newline at end of file
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