Commit 642df084 authored by chenyuling's avatar chenyuling

提交

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