Commit 642df084 authored by chenyuling's avatar chenyuling

提交

parent 02ad91e1
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
android:name=".uis.MainActivity" android:name=".uis.MainActivity"
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|orientation"
android:exported="true" android:exported="true"
android:windowSoftInputMode="adjustPan"> android:windowSoftInputMode="stateHidden|adjustPan">
<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" />
......
package com.srthinker.statinfo.adapter; package com.srthinker.statinfo.adapter;
import android.content.Context; import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -12,14 +13,16 @@ import com.srthinker.statinfo.databinding.ItemEnterBinding; ...@@ -12,14 +13,16 @@ import com.srthinker.statinfo.databinding.ItemEnterBinding;
import java.util.List; import java.util.List;
public class EnterAdapter extends RecyclerView.Adapter { public class EnterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final String TAG = "EnterAdapter";
private final Context context; private final Context context;
private List<PersonEntity> peopleBeans; private List<PersonEntity> personEntities;
public EnterAdapter(Context context, List<PersonEntity> peopleBeans){ public EnterAdapter(Context context, List<PersonEntity> pData){
this.context = context; this.context = context;
this.peopleBeans = peopleBeans; this.personEntities = pData;
Log.i(TAG, "EnterAdapter: 更新列表,size="+ pData.size());
} }
@NonNull @NonNull
@Override @Override
...@@ -31,18 +34,20 @@ public class EnterAdapter extends RecyclerView.Adapter { ...@@ -31,18 +34,20 @@ public class EnterAdapter extends RecyclerView.Adapter {
@Override @Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
ItemHolder itemHolder = (ItemHolder) holder; ItemHolder itemHolder = (ItemHolder) holder;
PersonEntity peopleBean = peopleBeans.get(position); PersonEntity peopleBean = personEntities.get(position);
Log.i(TAG, "onBindViewHolder: peopleBeans.size="+ personEntities.size());
if (peopleBean!=null){ if (peopleBean!=null){
Log.i(TAG, "onBindViewHolder: name="+peopleBean.getPerson_name());
itemHolder.mBinding.tvInfo.setText(peopleBean.getTimestamp()+" "+peopleBean.getPerson_name()); itemHolder.mBinding.tvInfo.setText(peopleBean.getTimestamp()+" "+peopleBean.getPerson_name());
} }
} }
@Override @Override
public int getItemCount() { public int getItemCount() {
return peopleBeans!=null&&peopleBeans.size()>0?peopleBeans.size():0; return personEntities !=null&& personEntities.size()>0? personEntities.size():0;
} }
private class ItemHolder extends RecyclerView.ViewHolder { private static class ItemHolder extends RecyclerView.ViewHolder {
private final com.srthinker.statinfo.databinding.ItemEnterBinding mBinding; private final com.srthinker.statinfo.databinding.ItemEnterBinding mBinding;
...@@ -52,8 +57,11 @@ public class EnterAdapter extends RecyclerView.Adapter { ...@@ -52,8 +57,11 @@ public class EnterAdapter extends RecyclerView.Adapter {
} }
} }
public void setDateList(List<PersonEntity> peopleBeans){ public void setDataList(List<PersonEntity> peopleBeans){
this.peopleBeans = peopleBeans; Log.i(TAG, "setDataList: 更新列表,size="+peopleBeans.size());
notifyDataSetChanged(); // this.peopleBeans=new ArrayList<>();
this.personEntities.clear();
this.personEntities = peopleBeans;
this.notifyDataSetChanged();
} }
} }
...@@ -6,6 +6,8 @@ import com.raizlabs.android.dbflow.annotation.Table; ...@@ -6,6 +6,8 @@ import com.raizlabs.android.dbflow.annotation.Table;
import com.raizlabs.android.dbflow.structure.BaseModel; import com.raizlabs.android.dbflow.structure.BaseModel;
import com.srthinker.statinfo.database.AppDB; import com.srthinker.statinfo.database.AppDB;
import java.util.Objects;
@Table(database = AppDB.class) @Table(database = AppDB.class)
public class PersonEntity extends BaseModel { public class PersonEntity extends BaseModel {
@PrimaryKey @PrimaryKey
...@@ -109,4 +111,17 @@ public class PersonEntity extends BaseModel { ...@@ -109,4 +111,17 @@ public class PersonEntity extends BaseModel {
public void setTimestamp(String timestamp) { public void setTimestamp(String timestamp) {
this.timestamp = timestamp; this.timestamp = timestamp;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PersonEntity that = (PersonEntity) o;
return group == that.group && Objects.equals(id, that.id) && Objects.equals(type, that.type) && Objects.equals(recognition_type, that.recognition_type) && Objects.equals(person_name, that.person_name) && Objects.equals(card_number, that.card_number) && Objects.equals(person_code, that.person_code) && Objects.equals(id_number, that.id_number) && Objects.equals(picture_data, that.picture_data) && Objects.equals(timestamp, that.timestamp);
}
@Override
public int hashCode() {
return Objects.hash(id, type, recognition_type, person_name, card_number, person_code, id_number, group, picture_data, timestamp);
}
} }
...@@ -41,6 +41,7 @@ public class ApiManager { ...@@ -41,6 +41,7 @@ public class ApiManager {
private DeviceCallback callback; private DeviceCallback callback;
private PassApiImpl passApi; private PassApiImpl passApi;
private boolean isRunning = false; // 标记任务是否正在执行 private boolean isRunning = false; // 标记任务是否正在执行
private boolean isFirstStatus = false;
private AuthApi authApi; private AuthApi authApi;
private PersonApiImpl personApi; private PersonApiImpl personApi;
private boolean lastConnect = false; private boolean lastConnect = false;
...@@ -73,6 +74,7 @@ public class ApiManager { ...@@ -73,6 +74,7 @@ public class ApiManager {
public void start(){ public void start(){
isRunning = true; isRunning = true;
isFirstStatus = true;
handler.post(authThreadRunnable); handler.post(authThreadRunnable);
//ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable); //ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable);
handler.post(passThreadRunnable); handler.post(passThreadRunnable);
...@@ -93,25 +95,47 @@ public class ApiManager { ...@@ -93,25 +95,47 @@ public class ApiManager {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
if (lastConnect){
if (callback != null) { if (callback != null) {
callback.onConnectStatus(false,type); callback.onConnectStatus(false,type);
lastConnect = false;
} }
Log.i(TAG, "run: authRunnable抛异常"); }
Log.i(TAG, "run: authRunnable抛异常:ip="+serverIp);
if (isRunning){
handler.postDelayed(authThreadRunnable,2000); handler.postDelayed(authThreadRunnable,2000);
} }
}finally {
if (isFirstStatus){
if (callback != null) {
callback.onConnectStatus(false,type);
lastConnect = false;
}
isFirstStatus = false;
}
}
if (loginResp != null) { if (loginResp != null) {
if(loginResp.getStatus() != 200) { if(loginResp.getStatus() != 200) {
if (lastConnect) {
if (callback != null) { if (callback != null) {
callback.onConnectStatus(false,type); callback.onConnectStatus(false,type);
lastConnect = false;
} }
}
//登录出错,打印错误信息 //登录出错,打印错误信息
System.out.println(JSONObject.toJSONString(loginResp)); System.out.println(JSONObject.toJSONString(loginResp));
return; return;
} }
sessionId = loginResp.getSessionId(); sessionId = loginResp.getSessionId();
if (!lastConnect){
if (callback!=null){ if (callback!=null){
callback.onConnectStatus(true,type); callback.onConnectStatus(true,type);
lastConnect = true;
} }
}
Log.i(TAG, "run: sessionId==>"+ sessionId); Log.i(TAG, "run: sessionId==>"+ sessionId);
...@@ -193,8 +217,11 @@ public class ApiManager { ...@@ -193,8 +217,11 @@ public class ApiManager {
} catch (Exception e) { } catch (Exception e) {
Log.i(TAG, "run: passRecordRunnable抛异常"); Log.i(TAG, "run: passRecordRunnable抛异常");
e.printStackTrace(); e.printStackTrace();
if (lastConnect) {
if (callback != null) { if (callback != null) {
callback.onConnectStatus(false,type); callback.onConnectStatus(false,type);
lastConnect = false;
}
} }
} }
if (passQueryResp!=null){ if (passQueryResp!=null){
...@@ -202,7 +229,9 @@ public class ApiManager { ...@@ -202,7 +229,9 @@ public class ApiManager {
if (passQueryResp.getPaging()==null&&passQueryResp.getData()==null&&passQueryResp.getQuery_id()==null){ if (passQueryResp.getPaging()==null&&passQueryResp.getData()==null&&passQueryResp.getQuery_id()==null){
//重新再登录鉴权一下: //重新再登录鉴权一下:
Log.i(TAG, "run: passQueryResp不为空,内容为空时也重新鉴权"); Log.i(TAG, "run: passQueryResp不为空,内容为空时也重新鉴权");
if (isRunning) {
handler.post(authThreadRunnable); handler.post(authThreadRunnable);
}
//清空重新循环 //清空重新循环
person_offset = 0; person_offset = 0;
pass_offset = 0; pass_offset = 0;
...@@ -220,10 +249,14 @@ public class ApiManager { ...@@ -220,10 +249,14 @@ public class ApiManager {
passBeans.add(passBean); passBeans.add(passBean);
} }
totalPassLists.addAll(passBeans); totalPassLists.addAll(passBeans);
if (!lastConnect){
if (callback != null) { if (callback != null) {
callback.onConnectStatus(true,type); callback.onConnectStatus(true,type);
lastConnect = true;
} }
} }
}
PassQueryBean.PagingBean paging = passQueryResp.getPaging(); PassQueryBean.PagingBean paging = passQueryResp.getPaging();
if (paging!=null){ if (paging!=null){
passTotal = paging.getTotal(); passTotal = paging.getTotal();
...@@ -253,7 +286,7 @@ public class ApiManager { ...@@ -253,7 +286,7 @@ public class ApiManager {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.i(TAG, "run: queryPerson抛异常"); Log.i(TAG, "run: queryPerson抛异常:ip="+serverIp);
/*if (callback != null) { /*if (callback != null) {
callback.onConnectStatus(false,type); callback.onConnectStatus(false,type);
}*/ }*/
...@@ -297,14 +330,13 @@ public class ApiManager { ...@@ -297,14 +330,13 @@ public class ApiManager {
} }
public void stop(){ public void stop(){
Log.i(TAG, "stop: 停止连接接口"); Log.i(TAG, "stop: 停止连接接口:ip="+serverIp);
//handler.removeCallbacks(passRunnable); //handler.removeCallbacks(passRunnable);
handler.removeCallbacks(passThreadRunnable);
handler.removeCallbacks(passRecordRunnable); handler.removeCallbacks(passRecordRunnable);
handler.removeCallbacks(authThreadRunnable); handler.removeCallbacks(authThreadRunnable);
handler.removeCallbacks(authRunnable); handler.removeCallbacks(authRunnable);
isRunning = false; isRunning = false;
} }
} }
...@@ -3,6 +3,8 @@ package com.srthinker.statinfo.presenter; ...@@ -3,6 +3,8 @@ package com.srthinker.statinfo.presenter;
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 android.util.Log;
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;
...@@ -13,13 +15,14 @@ import com.srthinker.statinfo.util.common.ThreadPool; ...@@ -13,13 +15,14 @@ import com.srthinker.statinfo.util.common.ThreadPool;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
public class ApiQuest { public class ApiQuest {
// private static ApiManager enterMgr; private static final String TAG = "ApiQuest";
// private static ApiManager leaveMgr;
private static ApiQuest apiQuest; private static ApiQuest apiQuest;
private static boolean isEnterAllConnect = false; private static boolean isEnterAllConnect = false;
private static boolean isLeaveAllConnect = false; private static boolean isLeaveAllConnect = false;
...@@ -45,43 +48,40 @@ public class ApiQuest { ...@@ -45,43 +48,40 @@ public class ApiQuest {
this.upperDevicesCallback = upperDevicesCallback; this.upperDevicesCallback = upperDevicesCallback;
} }
public void startEnterApi(List<ConfigEntity> configList){ public void startApi(List<ConfigEntity> configList,int type){
if (configList != null) { if (configList != null) {
//把之前的所有的停掉
stopApiByType(type);
for (int i = 0; i < configList.size(); i++) { for (int i = 0; i < configList.size(); i++) {
ConfigEntity config = configList.get(i); ConfigEntity config = configList.get(i);
String username = config.getUsername(); String username = config.getUsername();
String password = config.getPassword(); String password = config.getPassword();
String serverIp = config.getServerIp(); String serverIp = config.getServerIp();
boolean isConnect = config.isConnect(); boolean isConnect = config.isConnect();
if (i==0){ if (i==0&&type==ENTER_TYPE){
oneEnterIp = serverIp; oneEnterIp = serverIp;
} }
startEnterIp(username,password,serverIp,isConnect); if (type==ENTER_TYPE){
} startEnterIp(username,password,serverIp);
}else if (type==LEAVE_TYPE){
startLeaveIp(username,password,serverIp,isConnect);
} }
/*if (configBean != null) {
//如果之前曾经有过的,则停掉之前的
if (enterMgr!=null){
stopEnterApi();
} }
enterMgr = new ApiManager(configBean.getUsername(), configBean.getPassword(), configBean.getServerIp(), ENTER_TYPE);
if (enterMgr != null) {
enterMgr.start();
enterMgr.setOnDeviceCallback(this);
} }
}*/
} }
private void startEnterIp(String username, String password, String ip,boolean isLastConnect) { private void startEnterIp(String username, String password, String ip) {
//如果之前有过则停掉 Log.i(TAG, "startEnterIp: 访问接口的ip="+ip);
if (enterMgrHashMap.get(ip)!=null){ /*//如果之前有过则停掉
if (enterMgrHashMap.containsKey(ip)){
ApiManager apiManager = enterMgrHashMap.get(ip); ApiManager apiManager = enterMgrHashMap.get(ip);
if (apiManager != null) { if (apiManager != null) {
apiManager.stop(); apiManager.stop();
} }
enterMgrHashMap.remove(ip); enterMgrHashMap.remove(ip);
} }*/
ApiManager enterMgr = new ApiManager(username, password, ip, ENTER_TYPE); ApiManager enterMgr = new ApiManager(username, password, ip, ENTER_TYPE);
enterMgrHashMap.put(ip,enterMgr); enterMgrHashMap.put(ip,enterMgr);
enterMgr.start(); enterMgr.start();
...@@ -89,11 +89,19 @@ public class ApiQuest { ...@@ -89,11 +89,19 @@ public class ApiQuest {
@Override @Override
public void getPassInfo(List<PersonEntity> passEntities, int type) { public void getPassInfo(List<PersonEntity> passEntities, int type) {
allEnterPass.addAll(passEntities); allEnterPass.addAll(passEntities);
Set<PersonEntity> mergeList = new LinkedHashSet<>(allEnterPass);
allEnterPass = new ArrayList<>(mergeList);
for (PersonEntity enterPass : allEnterPass) {
Log.i(TAG, "getPassInfo: name="+enterPass.getPerson_name());
}
if (upperDevicesCallback != null) {
upperDevicesCallback.getAllPassInfo(allEnterPass,type);
}
} }
@Override @Override
public void onConnectStatus(boolean isConnect, int type) { public void onConnectStatus(boolean isConnect, int type) {
if (isLastConnect!=isConnect){ Log.i(TAG, "onConnectStatus: 接收到的连接状态:isConnect="+isConnect+",ip="+ip);
ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> { ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
List<ConfigEntity> configEntities = ConfigHelper.getInstance().queryByTypeIp(type, ip); List<ConfigEntity> configEntities = ConfigHelper.getInstance().queryByTypeIp(type, ip);
for (ConfigEntity configEntity : configEntities) { for (ConfigEntity configEntity : configEntities) {
...@@ -105,7 +113,7 @@ public class ApiQuest { ...@@ -105,7 +113,7 @@ public class ApiQuest {
isEnterAllConnect = true; isEnterAllConnect = true;
for (ConfigEntity config : enterList) { for (ConfigEntity config : enterList) {
boolean connect = config.isConnect(); boolean connect = config.isConnect();
if (connect==false){ if (!connect){
isEnterAllConnect = false; isEnterAllConnect = false;
break; break;
} }
...@@ -115,31 +123,18 @@ public class ApiQuest { ...@@ -115,31 +123,18 @@ public class ApiQuest {
} }
}); });
} }
}
}); });
} }
public void startLeaveApi(List<ConfigEntity> configList){ private void startLeaveIp(String username, String password, String ip,boolean isLastConnect) {
if (configList != null) {
for (int i = 0; i < configList.size(); i++) {
ConfigEntity config = configList.get(i);
String username = config.getUsername();
String password = config.getPassword();
String serverIp = config.getServerIp();
startLeaveIp(username,password,serverIp);
}
}
}
private void startLeaveIp(String username, String password, String ip) {
//如果之前有过则停掉 //如果之前有过则停掉
if (leaveMgrHashMap.get(ip)!=null){ /*if (leaveMgrHashMap.get(ip)!=null){
ApiManager apiManager = leaveMgrHashMap.get(ip); ApiManager apiManager = leaveMgrHashMap.get(ip);
if (apiManager != null) { if (apiManager != null) {
apiManager.stop(); apiManager.stop();
} }
leaveMgrHashMap.remove(ip); leaveMgrHashMap.remove(ip);
} }*/
ApiManager leaveMgr = new ApiManager(username, password, ip, LEAVE_TYPE); ApiManager leaveMgr = new ApiManager(username, password, ip, LEAVE_TYPE);
leaveMgrHashMap.put(ip,leaveMgr); leaveMgrHashMap.put(ip,leaveMgr);
leaveMgr.start(); leaveMgr.start();
...@@ -171,11 +166,24 @@ public class ApiQuest { ...@@ -171,11 +166,24 @@ public class ApiQuest {
}*/ }*/
public void stopApi(){ public void stopApi(){
stopEnterApi(); stopApiByType(ENTER_TYPE);
stopLeaveApi(); stopApiByType(LEAVE_TYPE);
} }
public void stopEnterApi(){ public void stopApiByType(int type) {
LinkedHashMap<String, ApiManager> mgrHashMap = type == ENTER_TYPE ? enterMgrHashMap : leaveMgrHashMap;
for (Map.Entry<String, ApiManager> mgr : mgrHashMap.entrySet()) {
ApiManager apiManager = mgr.getValue();
if (apiManager != null) {
apiManager.stop();
apiManager.setOnDeviceCallback(null);
apiManager = null;
}
}
mgrHashMap.clear();
}
/*public void stopEnterApi(){
for (Map.Entry<String, ApiManager> enterMgr : enterMgrHashMap.entrySet()) { for (Map.Entry<String, ApiManager> enterMgr : enterMgrHashMap.entrySet()) {
ApiManager enter = enterMgr.getValue(); ApiManager enter = enterMgr.getValue();
if (enter!=null){ if (enter!=null){
...@@ -197,7 +205,7 @@ public class ApiQuest { ...@@ -197,7 +205,7 @@ public class ApiQuest {
} }
leaveMgrHashMap.remove(leaveMgr.getKey()); leaveMgrHashMap.remove(leaveMgr.getKey());
} }
} }*/
/*private void stopEnterApi(){ /*private void stopEnterApi(){
if (enterMgr != null) { if (enterMgr != null) {
......
...@@ -34,20 +34,20 @@ import com.srthinker.statinfo.R; ...@@ -34,20 +34,20 @@ import com.srthinker.statinfo.R;
import com.srthinker.statinfo.adapter.EnterAdapter; import com.srthinker.statinfo.adapter.EnterAdapter;
import com.srthinker.statinfo.adapter.GroupAdapter; import com.srthinker.statinfo.adapter.GroupAdapter;
import com.srthinker.statinfo.adapter.LeaveAdapter; import com.srthinker.statinfo.adapter.LeaveAdapter;
import com.srthinker.statinfo.bean.ConfigBean;
import com.srthinker.statinfo.bean.GroupBean; import com.srthinker.statinfo.bean.GroupBean;
import com.srthinker.statinfo.bean.TimeBean; import com.srthinker.statinfo.bean.TimeBean;
import com.srthinker.statinfo.database.PersonMgr; 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.PersonHelper; import com.srthinker.statinfo.database.helper.PersonHelper;
import com.srthinker.statinfo.databinding.ActivityMainBinding; 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.ConfigCallback;
import com.srthinker.statinfo.listener.DeviceCallback;
import com.srthinker.statinfo.listener.OnTimeUpdateListener; import com.srthinker.statinfo.listener.OnTimeUpdateListener;
import com.srthinker.statinfo.listener.QueryPersonCallback; import com.srthinker.statinfo.listener.QueryPersonCallback;
import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.presenter.ApiManager; 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.RealTimeClock;
...@@ -73,7 +73,7 @@ import java.util.List; ...@@ -73,7 +73,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
public class MainActivity extends BaseActivity implements OnTimeUpdateListener, MDownloadCallBack, UpperDownloadCallback, DeviceCallback, NetworkIPMonitor.OnIPChangeCallback, ConfigCallback, QueryPersonCallback { public class MainActivity extends BaseActivity implements OnTimeUpdateListener, MDownloadCallBack, UpperDownloadCallback, NetworkIPMonitor.OnIPChangeCallback, ConfigCallback, QueryPersonCallback, UpperDevicesCallback {
private static final String TAG = "MainActivity"; private static final String TAG = "MainActivity";
private com.srthinker.statinfo.databinding.ActivityMainBinding mBinding; private com.srthinker.statinfo.databinding.ActivityMainBinding mBinding;
...@@ -156,7 +156,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -156,7 +156,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
showConfigDialog(LEAVE_TYPE); showConfigDialog(LEAVE_TYPE);
}); });
mBinding.btnGroupDetail.setOnClickListener(v->{ mBinding.btnGroupDetail.setOnClickListener(v->{
ApiQuest.queryPersons(this); ApiQuest.getInstance().queryPersons(this);
ClickUtil.disableClick(mBinding.btnGroupDetail); ClickUtil.disableClick(mBinding.btnGroupDetail);
}); });
} }
...@@ -190,7 +190,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -190,7 +190,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
@Override @Override
protected void onDestroy() { protected void onDestroy() {
Log.i(TAG, "onDestroy: Main--destroy"); Log.i(TAG, "onDestroy: Main--destroy");
super.onDestroy();
networkIPMonitor.stopMonitoring(); networkIPMonitor.stopMonitoring();
mRealTimeClock.stop(); mRealTimeClock.stop();
//关闭循环拉取 //关闭循环拉取
...@@ -198,7 +198,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -198,7 +198,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
/*if (enterMgr != null) { /*if (enterMgr != null) {
enterMgr.stop(); enterMgr.stop();
}*/ }*/
ApiQuest.stopApi(); ApiQuest.getInstance().stopApi();
super.onDestroy();
} }
private void detectUpgrade() { private void detectUpgrade() {
...@@ -359,23 +360,19 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -359,23 +360,19 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
@Override
public void getPassInfo(List<PersonEntity> passEntities, int type) {
runOnUiThread(()->{
updatePassInfo(passEntities, type);
});
}
private void updatePassInfo(List<PersonEntity> passEntities, int type) { private void updatePassInfo(List<PersonEntity> passEntities, int type) {
for (PersonEntity passEntity : passEntities) {
Log.i(TAG, "updatePassInfo: 获取到的name="+passEntity.getPerson_name());
}
if (type ==ENTER_TYPE){ if (type ==ENTER_TYPE){
enterBeans = passEntities; enterBeans = passEntities;
if (enterBeans != null) { if (enterBeans != null) {
if (enterAdapter != null) { if (enterAdapter != null) {
int size = passEntities.size(); int size = enterBeans.size();
Log.i(TAG, "updatePassInfo: 进来的人数="+size);
if (size!=lastEnterSize){ if (size!=lastEnterSize){
//更新进出情况 //更新进出情况
enterAdapter.setDateList(enterBeans); enterAdapter.setDataList(enterBeans);
//更新人员情况(是否要根据id去重) //更新人员情况(是否要根据id去重)
if (NEED_NO_REPET) { if (NEED_NO_REPET) {
List<PersonEntity> enterListNo = StatSize.filterList(enterBeans); List<PersonEntity> enterListNo = StatSize.filterList(enterBeans);
...@@ -421,13 +418,9 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -421,13 +418,9 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
} }
} }
} }
@NonNull @NonNull
private HashMap<Integer, Integer> getGroupSizeHashMap(List<PersonEntity> personEntityList) { private HashMap<Integer, Integer> getGroupSizeHashMap(List<PersonEntity> personEntityList) {
HashMap<Integer, Integer> groupSizeHashMap = new HashMap<>(); HashMap<Integer, Integer> groupSizeHashMap = new HashMap<>();
...@@ -511,25 +504,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -511,25 +504,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
} }
@Override
public void onConnectStatus(boolean isConnect, int type) {
runOnUiThread(()->{
if (type==ENTER_TYPE){
if (!isConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{
mBinding.tvEnterError.setVisibility(View.GONE);
}
}else if (type == LEAVE_TYPE){
if (!isConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{
mBinding.tvLeaveError.setVisibility(View.GONE);
}
}
});
}
@Override @Override
public void onQueryStatus(String desc, boolean status) { public void onQueryStatus(String desc, boolean status) {
...@@ -564,26 +539,97 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -564,26 +539,97 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
public void OnIPChange(String ipAddress, String networkType) { public void OnIPChange(String ipAddress, String networkType) {
Log.i(TAG, "OnIPChange: change==>"); Log.i(TAG, "OnIPChange: change==>");
//questApi(); //questApi();
List<ConfigBean> enterConfigList = SharedUtil.getInstance(this).readSharedList(ENTER_TYPE, ConfigBean.class, ""); /*List<ConfigBean> enterConfigList = SharedUtil.getInstance(this).readSharedList(ENTER_TYPE, ConfigBean.class, "");
ApiQuest.startEnterApi(enterConfigList,this); ApiQuest.startEnterApi(enterConfigList,this);
List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, ""); List<ConfigBean> leaveConfigList = SharedUtil.getInstance(this).readSharedList(LEAVE_TYPE, ConfigBean.class, "");
ApiQuest.startLeaveApi(leaveConfigList,this); ApiQuest.startLeaveApi(leaveConfigList,this);*/
runOnUiThread(() -> {
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 @Override
public void OnIPLost(String error) { public void OnIPLost(String error) {
ApiQuest.stopApi(); ApiQuest.getInstance().stopApi();
} }
@Override @Override
public void onUpdateConfig(List<ConfigEntity> configList, int type) { public void onUpdateConfig(List<ConfigEntity> configList, int type) {
//配置改变,更新接口 //配置改变,更新接口
//Log.i(TAG, "onUpdateConfig: config="+configBean.toString()+",type="+type); //Log.i(TAG, "onUpdateConfig: config="+configBean.toString()+",type="+type);
if (type==ENTER_TYPE){ /*if (type==ENTER_TYPE){
ApiQuest.getInstance().startEnterApi(configList); ApiQuest.getInstance().startEnterApi(configList);
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
ApiQuest.getInstance().startLeaveApi(configList); ApiQuest.getInstance().startLeaveApi(configList);
}*/
for (ConfigEntity config : configList) {
Log.i(TAG, "onUpdateConfig: pass="+config.getPassword());
Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp());
} }
runOnUiThread(()->{
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
});
} }
@Override
public void getAllPassInfo(List<PersonEntity> passAllEntities, int type) {
runOnUiThread(()->{
updatePassInfo(passAllEntities, type);
});
}
@Override
public void onAllConnectStatus(boolean hasDisConnect, int type) {
runOnUiThread(()->{
if (type==ENTER_TYPE){
if (!hasDisConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{
mBinding.tvEnterError.setVisibility(View.GONE);
}
}else if (type == LEAVE_TYPE){
if (!hasDisConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{
mBinding.tvLeaveError.setVisibility(View.GONE);
}
}
});
}
/*@Override
public void getPassInfo(List<PersonEntity> passEntities, int type) {
runOnUiThread(()->{
updatePassInfo(passEntities, type);
});
}
@Override
public void onConnectStatus(boolean isConnect, int type) {
runOnUiThread(()->{
if (type==ENTER_TYPE){
if (!isConnect) {
mBinding.tvEnterError.setVisibility(View.VISIBLE);
}else{
mBinding.tvEnterError.setVisibility(View.GONE);
}
}else if (type == LEAVE_TYPE){
if (!isConnect) {
mBinding.tvLeaveError.setVisibility(View.VISIBLE);
}else{
mBinding.tvLeaveError.setVisibility(View.GONE);
}
}
});
}*/
} }
\ No newline at end of file
...@@ -117,6 +117,9 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -117,6 +117,9 @@ public class ConfigDlgFragment extends DialogFragment {
mBinding.btnConfirm.setOnClickListener(v->{ mBinding.btnConfirm.setOnClickListener(v->{
updateConfig(); updateConfig();
}); });
mBinding.tvAddNewIp.setOnClickListener(v->{
addDeviceIpView();
});
} }
private void updateConfig() { private void updateConfig() {
...@@ -154,6 +157,7 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -154,6 +157,7 @@ public class ConfigDlgFragment extends DialogFragment {
config.setServerIp(ip); config.setServerIp(ip);
config.setType(type); config.setType(type);
configEntities.add(config); configEntities.add(config);
if (mLastConfig != null&&mLastConfig.size()>i) {
ConfigEntity mLastEntity = mLastConfig.get(i); ConfigEntity mLastEntity = mLastConfig.get(i);
try { try {
String newConfigString = GsonUtil.toJsonString(config); String newConfigString = GsonUtil.toJsonString(config);
...@@ -164,10 +168,9 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -164,10 +168,9 @@ public class ConfigDlgFragment extends DialogFragment {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
if (isUpdate || allDeviceIps.size()!=mLastConfig.size()){ }
if (isUpdate || mLastConfig!=null&&allDeviceIps.size()!=mLastConfig.size()){
/*if (callback != null) { /*if (callback != null) {
SharedUtil.getInstance(context).writeShared(type,configBeanList); SharedUtil.getInstance(context).writeShared(type,configBeanList);
callback.onUpdateConfig(configBeanList,type); callback.onUpdateConfig(configBeanList,type);
...@@ -245,7 +248,7 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -245,7 +248,7 @@ public class ConfigDlgFragment extends DialogFragment {
} }
private void addDeviceIpView(){ private void addDeviceIpView(){
EditView editView = new EditView(context); EditView editView = new EditView(context,null);
int number = devicesIpList.size() + 1; int number = devicesIpList.size() + 1;
editView.initItem("设备"+number+"的IP:","输入设备"+number+"的IP"); editView.initItem("设备"+number+"的IP:","输入设备"+number+"的IP");
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
......
...@@ -16,6 +16,8 @@ public class EditView extends LinearLayout { ...@@ -16,6 +16,8 @@ public class EditView extends LinearLayout {
public EditView(Context context) { public EditView(Context context) {
super(context,null); super(context,null);
this.context = context;
initView(context);
} }
public EditView(Context context, @Nullable AttributeSet attrs) { public EditView(Context context, @Nullable AttributeSet attrs) {
......
...@@ -11,17 +11,17 @@ ...@@ -11,17 +11,17 @@
android:id="@+id/tv_title" android:id="@+id/tv_title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="3" android:layout_weight="5"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="@dimen/text_12_5" android:textSize="@dimen/text_12_5"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="" android:text=""
android:gravity="center|right"/> android:gravity="center|left"/>
<EditText <EditText
android:id="@+id/et_content" android:id="@+id/et_content"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="7" android:layout_weight="5"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="@dimen/text_12_5" android:textSize="@dimen/text_12_5"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
......
package com.srthinker.statinfo; package com.srthinker.statinfo;
import com.srthinker.statinfo.bean.ConfigBean; import com.srthinker.statinfo.bean.ConfigBean;
import com.srthinker.statinfo.database.entity.PersonEntity;
import org.junit.Test; import org.junit.Test;
import java.util.Arrays; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
public class EqualTest { public class EqualTest {
@Test
public void equalTest(){
ConfigBean configBean = new ConfigBean("1", "2", Arrays.asList("2","3"));
ConfigBean configBean1 = new ConfigBean("1", "2", Arrays.asList("2","3"));
System.out.println("内容是否相等="+configBean1.equals(configBean));
ConfigBean configBean2 = new ConfigBean("1", "2", Arrays.asList("2","3")); @Test
configBean2.setPassword("4"); public void repeatTest(){
ConfigBean configBean3 = new ConfigBean("1", "2", Arrays.asList("2","3")); List<PersonEntity> allPersonList = new ArrayList<>();
configBean3.setPassword("5"); List<PersonEntity> personEntities = new ArrayList<>();
System.out.println("内容是否相等="+configBean2.equals(configBean3)); List<PersonEntity> personEntities1 = new ArrayList<>();
PersonEntity personEntity = new PersonEntity();
personEntity.setId("1");
personEntity.setPerson_name("chen");
personEntity.setTimestamp("17:00");
PersonEntity personEntity2 = new PersonEntity();
personEntity2.setId("1");
personEntity2.setPerson_name("chen");
personEntity2.setTimestamp("17:00");
personEntities.add(personEntity);
personEntities1.add(personEntity2);
allPersonList.addAll(personEntities);
allPersonList.addAll(personEntities1);
Set<PersonEntity> mergeSet = new LinkedHashSet<>(allPersonList);
allPersonList = new ArrayList<>(mergeSet);
for (PersonEntity entity : allPersonList) {
System.out.println("遍历:name="+entity.getPerson_name());
}
}
@Test
public void configTest(){
List<ConfigBean> allConfigList = new ArrayList<>();
List<ConfigBean> configBeanList = new ArrayList<>();
ConfigBean configBean = new ConfigBean();
configBean.setUsername("admin");
configBean.setServerIp("111");
ConfigBean configBean1 = new ConfigBean();
configBean1.setUsername("admin");
configBean1.setServerIp("111");
configBeanList.add(configBean);
configBeanList.add(configBean1);
allConfigList.addAll(configBeanList);
/*LinkedHashSet<ConfigBean> linkedHashSet = new LinkedHashSet<>(allConfigList);
allConfigList = new ArrayList<>(linkedHashSet);*/
for (ConfigBean bean : allConfigList) {
System.out.println("遍历bean的:name="+bean.getUsername());
}
} }
} }
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