Commit 8c32f10e authored by chenyuling's avatar chenyuling

优化代码

parent 1b2f9938
...@@ -60,4 +60,8 @@ public class LeaveAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> ...@@ -60,4 +60,8 @@ public class LeaveAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
//Log.i(TAG, "setDataList: size="+this.peopleBeans.size()); //Log.i(TAG, "setDataList: size="+this.peopleBeans.size());
this.notifyDataSetChanged(); this.notifyDataSetChanged();
} }
public List<PersonEntity> getDataList(){
return this.peopleBeans;
}
} }
...@@ -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 ConfigEntity extends BaseModel { public class ConfigEntity extends BaseModel {
@PrimaryKey(autoincrement = true) @PrimaryKey(autoincrement = true)
...@@ -69,4 +71,17 @@ public class ConfigEntity extends BaseModel { ...@@ -69,4 +71,17 @@ public class ConfigEntity extends BaseModel {
public void setType(int type) { public void setType(int type) {
this.type = type; this.type = type;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ConfigEntity config = (ConfigEntity) o;
return id == config.id && isConnect == config.isConnect && type == config.type && Objects.equals(username, config.username) && Objects.equals(password, config.password) && Objects.equals(serverIp, config.serverIp);
}
@Override
public int hashCode() {
return Objects.hash(id, username, password, serverIp, isConnect, type);
}
} }
...@@ -29,6 +29,7 @@ import java.util.concurrent.ScheduledExecutorService; ...@@ -29,6 +29,7 @@ import java.util.concurrent.ScheduledExecutorService;
public class ApiManager { public class ApiManager {
private static final String TAG = "ApiManager"; private static final String TAG = "ApiManager";
private static final long GET_PASS_TIME = 60000;
private final String username; private final String username;
private final String password; private final String password;
private final String serverIp; private final String serverIp;
...@@ -42,6 +43,7 @@ public class ApiManager { ...@@ -42,6 +43,7 @@ public class ApiManager {
private PassApiImpl passApi; private PassApiImpl passApi;
private boolean isRunning = false; // 标记任务是否正在执行 private boolean isRunning = false; // 标记任务是否正在执行
private boolean isFirstStatus = false; private boolean isFirstStatus = false;
private int lastPassTotal;
private AuthApi authApi; private AuthApi authApi;
private PersonApiImpl personApi; private PersonApiImpl personApi;
private boolean lastConnect = false; private boolean lastConnect = false;
...@@ -76,6 +78,7 @@ public class ApiManager { ...@@ -76,6 +78,7 @@ public class ApiManager {
isRunning = true; isRunning = true;
isFirstStatus = true; isFirstStatus = true;
lastConnect = false; lastConnect = false;
lastPassTotal = 0;
handler.post(authThreadRunnable); handler.post(authThreadRunnable);
//ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable); //ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable);
handler.post(passThreadRunnable); handler.post(passThreadRunnable);
...@@ -103,6 +106,7 @@ public class ApiManager { ...@@ -103,6 +106,7 @@ public class ApiManager {
//只要连接成功都传避免出现意外,因为鉴权成功后也只访问一次 //只要连接成功都传避免出现意外,因为鉴权成功后也只访问一次
if (callback != null) { if (callback != null) {
lastConnect = true; lastConnect = true;
isFirstStatus = false;
callback.onConnectStatus(true, type); callback.onConnectStatus(true, type);
} }
//updateLastConnect(true); //updateLastConnect(true);
...@@ -164,9 +168,14 @@ public class ApiManager { ...@@ -164,9 +168,14 @@ public class ApiManager {
totalPassLists = new ArrayList<>(); totalPassLists = new ArrayList<>();
pass_offset = 0; pass_offset = 0;
queryPass(); queryPass();
if (callback != null) { //Log.i(TAG, "run: totalPassLists.size()="+totalPassLists.size());
callback.getPassInfo(totalPassLists,type); //Log.i(TAG, "run: lastPassTotal="+lastPassTotal);
if (totalPassLists.size()!=0&&totalPassLists.size()!= lastPassTotal){
if (callback != null) {
callback.getPassInfo(totalPassLists,type);
}
} }
lastPassTotal = totalPassLists.size();
/*handler.postDelayed(this,60000);*/ /*handler.postDelayed(this,60000);*/
} }
}; };
...@@ -179,7 +188,7 @@ public class ApiManager { ...@@ -179,7 +188,7 @@ public class ApiManager {
return; return;
} }
ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable); ThreadPool.getInstance().getThreadPoolExecutor().execute(passRecordRunnable);
handler.postDelayed(this,60000); handler.postDelayed(this,GET_PASS_TIME);
} }
}; };
......
...@@ -14,6 +14,7 @@ import com.srthinker.statinfo.listener.upper.UpperDevicesCallback; ...@@ -14,6 +14,7 @@ import com.srthinker.statinfo.listener.upper.UpperDevicesCallback;
import com.srthinker.statinfo.util.common.ThreadPool; import com.srthinker.statinfo.util.common.ThreadPool;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
...@@ -47,27 +48,39 @@ public class ApiQuest { ...@@ -47,27 +48,39 @@ public class ApiQuest {
this.upperDevicesCallback = upperDevicesCallback; this.upperDevicesCallback = upperDevicesCallback;
} }
private void initData(int type){
if (type==ENTER_TYPE){
isEnterAllConnect = false;
allEnterPass = new ArrayList<>();
}else if (type==LEAVE_TYPE){
isLeaveAllConnect = false;
allLeavePass = new ArrayList<>();
}
}
public void startApi(List<ConfigEntity> configList,int type){ public void startApi(List<ConfigEntity> configList,int type){
if (configList != null) { if (configList != null) {
//把之前的所有的停掉 synchronized (this){
stopApiByType(type); //把之前的所有的停掉
for (int i = 0; i < configList.size(); i++) { stopApiByType(type);
ConfigEntity config = configList.get(i); initData(type);
String username = config.getUsername(); for (int i = 0; i < configList.size(); i++) {
String password = config.getPassword(); ConfigEntity config = configList.get(i);
String serverIp = config.getServerIp(); String username = config.getUsername();
if (i==0&&type==ENTER_TYPE){ String password = config.getPassword();
oneEnterIp = serverIp; String serverIp = config.getServerIp();
} if (i==0&&type==ENTER_TYPE){
if (type==ENTER_TYPE){ oneEnterIp = serverIp;
startEnterIp(username,password,serverIp); }
}else if (type==LEAVE_TYPE){ if (type==ENTER_TYPE){
startLeaveIp(username,password,serverIp); startEnterIp(username,password,serverIp);
} }else if (type==LEAVE_TYPE){
startLeaveIp(username,password,serverIp);
}
}
} }
} }
} }
private void startEnterIp(String username, String password, String ip) { private void startEnterIp(String username, String password, String ip) {
...@@ -86,20 +99,22 @@ public class ApiQuest { ...@@ -86,20 +99,22 @@ public class ApiQuest {
enterMgr.setOnDeviceCallback(new DeviceCallback() { enterMgr.setOnDeviceCallback(new DeviceCallback() {
@Override @Override
public void getPassInfo(List<PersonEntity> passEntities, int type) { public void getPassInfo(List<PersonEntity> passEntities, int type) {
allEnterPass.addAll(passEntities); synchronized (allEnterPass){
for (PersonEntity enterPass : allEnterPass) { allEnterPass.addAll(passEntities);
Log.i(TAG, "去重前getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name()); /*for (PersonEntity enterPass : allEnterPass) {
} Log.i(TAG, "去重前getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name());
LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allEnterPass); }*/
allEnterPass = new ArrayList<>(mergeList); PersonEntityComparator comparator = new PersonEntityComparator();
for (PersonEntity enterPass : allEnterPass) { Collections.sort(allEnterPass,comparator);
Log.i(TAG, "去重后getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name()); LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allEnterPass);
} allEnterPass = new ArrayList<>(mergeList);
/*for (PersonEntity enterPass : allEnterPass) { /*for (PersonEntity enterPass : allEnterPass) {
Log.i(TAG, "getPassInfo: name="+enterPass.getPerson_name()); Log.i(TAG, "去重后getPassInfo: enterPass.time="+enterPass.getTimestamp()+",name="+enterPass.getPerson_name());
}*/ }*/
if (upperDevicesCallback != null) { ArrayList<PersonEntity> allPassList = new ArrayList<>(allEnterPass);
upperDevicesCallback.getAllPassInfo(allEnterPass,type); if (upperDevicesCallback != null) {
upperDevicesCallback.getAllPassInfo(allPassList,type);
}
} }
} }
...@@ -153,14 +168,16 @@ public class ApiQuest { ...@@ -153,14 +168,16 @@ public class ApiQuest {
leaveMgr.setOnDeviceCallback(new DeviceCallback() { leaveMgr.setOnDeviceCallback(new DeviceCallback() {
@Override @Override
public void getPassInfo(List<PersonEntity> passEntities, int type) { public void getPassInfo(List<PersonEntity> passEntities, int type) {
allLeavePass.addAll(passEntities); synchronized (allLeavePass){
LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allLeavePass); allLeavePass.addAll(passEntities);
allLeavePass = new ArrayList<>(mergeList); PersonEntityComparator comparator = new PersonEntityComparator();
/*for (PersonEntity leavePass : allLeavePass) { Collections.sort(allLeavePass,comparator);
Log.i(TAG, "getPassInfo: name="+leavePass.getPerson_name()); LinkedHashSet<PersonEntity> mergeList = new LinkedHashSet<>(allLeavePass);
}*/ allLeavePass = new ArrayList<>(mergeList);
if (upperDevicesCallback != null) { ArrayList<PersonEntity> allPassList = new ArrayList<>(allLeavePass);
upperDevicesCallback.getAllPassInfo(allLeavePass,type); if (upperDevicesCallback != null) {
upperDevicesCallback.getAllPassInfo(allPassList,type);
}
} }
} }
...@@ -221,8 +238,10 @@ public class ApiQuest { ...@@ -221,8 +238,10 @@ public class ApiQuest {
public void queryPersons(QueryPersonCallback callback){ public void queryPersons(QueryPersonCallback callback){
if (enterMgrHashMap.size()>0){ if (enterMgrHashMap.size()>0){
ApiManager oneEnterMgr = enterMgrHashMap.get(oneEnterIp); ApiManager oneEnterMgr = enterMgrHashMap.get(oneEnterIp);
oneEnterMgr.queryPersons(); if (oneEnterMgr != null) {
oneEnterMgr.setOnQueryPersonsCallback(callback); oneEnterMgr.queryPersons();
oneEnterMgr.setOnQueryPersonsCallback(callback);
}
} }
} }
} }
package com.srthinker.statinfo.presenter; package com.srthinker.statinfo.presenter;
import com.srthinker.statinfo.database.entity.PersonEntity; import com.srthinker.statinfo.database.entity.PersonEntity;
import com.srthinker.statinfo.util.common.DateUtil;
import java.util.Comparator; import java.util.Comparator;
public class PersonEntityComparator implements Comparator<PersonEntity> { public class PersonEntityComparator implements Comparator<PersonEntity> {
@Override @Override
public int compare(PersonEntity p1, PersonEntity p2) { public int compare(PersonEntity p1, PersonEntity p2) {
long time1 = DateUtil.getTime(p1.getTimestamp(), "HH:mm");
//return time2.compareTo(time1); long time2 = DateUtil.getTime(p2.getTimestamp(), "HH:mm");
return 0; //从大到小排列
if (time1>time2){
return -1;
}else if (time1<time2){
return 1;
}else{
return 0;
}
} }
} }
...@@ -362,14 +362,14 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -362,14 +362,14 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
private void updatePassInfo(List<PersonEntity> passEntities, int type) { private void updatePassInfo(List<PersonEntity> passEntities, int type) {
Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size()); Log.i(TAG, "updatePassInfo: 获取的总数="+passEntities.size());
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) { 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();
...@@ -390,6 +390,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -390,6 +390,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
groupEnterHashMap = getGroupSizeHashMap(passEntities); groupEnterHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap); updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
/* Log.i(TAG, "updatePassInfo: enterBeans.size="+enterBeans.size());
Log.i(TAG, "updatePassInfo: adapter.size="+enterAdapter.getDataList().size());*/
} }
} }
...@@ -399,7 +401,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -399,7 +401,7 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
if (leaveAdapter != 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);
//更新进出情况 //更新进出情况
...@@ -419,6 +421,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -419,6 +421,8 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
groupLeaveHashMap = getGroupSizeHashMap(passEntities); groupLeaveHashMap = getGroupSizeHashMap(passEntities);
updatePresentSize(groupEnterHashMap,groupLeaveHashMap); updatePresentSize(groupEnterHashMap,groupLeaveHashMap);
} }
/*Log.i(TAG, "updatePassInfo: leaveBeans.size="+leaveBeans.size());
Log.i(TAG, "updatePassInfo: adapter.size="+leaveAdapter.getDataList().size());*/
} }
} }
...@@ -548,22 +552,6 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -548,22 +552,6 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
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);
});*/
/*ThreadPool.getInstance().getThreadPoolExecutor().execute(() -> {
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);
});*/
List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE); List<ConfigEntity> enterConfigList = ConfigHelper.getInstance().queryByType(ENTER_TYPE);
ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE); ApiQuest.getInstance().startApi(enterConfigList,ENTER_TYPE);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); ApiQuest.getInstance().setOnUpperDevicesCallback(this);
...@@ -586,18 +574,10 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -586,18 +574,10 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
}else if (type == LEAVE_TYPE){ }else if (type == LEAVE_TYPE){
ApiQuest.getInstance().startLeaveApi(configList); ApiQuest.getInstance().startLeaveApi(configList);
}*/ }*/
for (ConfigEntity config : configList) { /*for (ConfigEntity config : configList) {
Log.i(TAG, "onUpdateConfig: pass="+config.getPassword()); Log.i(TAG, "onUpdateConfig: pass="+config.getPassword());
Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp()); Log.i(TAG, "onUpdateConfig: ip="+config.getServerIp());
} }*/
/*runOnUiThread(()->{
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
});*/
/*ThreadPool.getInstance().getThreadPoolExecutor().execute(()->{
ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this);
});*/
ApiQuest.getInstance().startApi(configList,type); ApiQuest.getInstance().startApi(configList,type);
ApiQuest.getInstance().setOnUpperDevicesCallback(this); ApiQuest.getInstance().setOnUpperDevicesCallback(this);
} }
...@@ -629,32 +609,4 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener, ...@@ -629,32 +609,4 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
} }
}); });
} }
/*@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
...@@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable; ...@@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -34,6 +35,7 @@ import java.util.stream.Collectors; ...@@ -34,6 +35,7 @@ import java.util.stream.Collectors;
public class ConfigDlgFragment extends DialogFragment { public class ConfigDlgFragment extends DialogFragment {
private static final String TAG = "ConfigDlgFragment";
private Context context; private Context context;
private int type; private int type;
private com.srthinker.statinfo.databinding.DialogConfigBinding mBinding; private com.srthinker.statinfo.databinding.DialogConfigBinding mBinding;
...@@ -98,12 +100,15 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -98,12 +100,15 @@ public class ConfigDlgFragment extends DialogFragment {
ConfigEntity config = mLastConfig.get(i); ConfigEntity config = mLastConfig.get(i);
if (config != null) { if (config != null) {
String serverIp = config.getServerIp(); String serverIp = config.getServerIp();
boolean connect = config.isConnect();
if (i==0){ if (i==0){
mBinding.evServerip.setContent(serverIp); mBinding.evServerip.setContent(serverIp);
mBinding.evServerip.setStatus(connect);
}else{ }else{
addDeviceIpView(); addDeviceIpView();
EditView editView = devicesIpList.get(i); EditView editView = devicesIpList.get(i);
editView.setContent(serverIp); editView.setContent(serverIp);
editView.setStatus(connect);
} }
} }
} }
...@@ -156,21 +161,29 @@ public class ConfigDlgFragment extends DialogFragment { ...@@ -156,21 +161,29 @@ public class ConfigDlgFragment extends DialogFragment {
config.setPassword(password); config.setPassword(password);
config.setServerIp(ip); config.setServerIp(ip);
config.setType(type); config.setType(type);
configEntities.add(config);
if (mLastConfig != null&&mLastConfig.size()>i) { if (mLastConfig != null&&mLastConfig.size()>i) {
ConfigEntity mLastEntity = mLastConfig.get(i); ConfigEntity mLastEntity = mLastConfig.get(i);
try { if (TextUtils.equals(mLastEntity.getServerIp(),ip)){
config.setId(mLastEntity.getId());
config.setConnect(mLastEntity.isConnect());
}
/*try {
String newConfigString = GsonUtil.toJsonString(config); String newConfigString = GsonUtil.toJsonString(config);
String lastConfigString = GsonUtil.toJsonString(mLastEntity); String lastConfigString = GsonUtil.toJsonString(mLastEntity);
Log.i(TAG, "updateConfig: newConfigString="+newConfigString);
Log.i(TAG, "updateConfig: lastConfigString="+lastConfigString);
if (!TextUtils.equals(newConfigString,lastConfigString)){ if (!TextUtils.equals(newConfigString,lastConfigString)){
isUpdate = true; isUpdate = true;
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }*/
} }
configEntities.add(config);
} }
if (isUpdate || mLastConfig!=null&&allDeviceIps.size()!=mLastConfig.size()){ Log.i(TAG, "updateConfig: mLastConfig="+ GsonUtil.ListToJson(mLastConfig));
Log.i(TAG, "updateConfig: configEntity="+GsonUtil.ListToJson(configEntities));
if (mLastConfig!=null&&!mLastConfig.equals(configEntities)){
/*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);
......
...@@ -108,6 +108,7 @@ public class DateUtil { ...@@ -108,6 +108,7 @@ public class DateUtil {
return sdf.format(d_date); return sdf.format(d_date);
} }
public static String getAddDate(String str, long day_num) { public static String getAddDate(String str, long day_num) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date old_date; Date old_date;
...@@ -137,6 +138,17 @@ public class DateUtil { ...@@ -137,6 +138,17 @@ public class DateUtil {
} }
} }
public static long getTime(String str,String formatStr){
SimpleDateFormat sdf = new SimpleDateFormat(formatStr);
try {
Date date = sdf.parse(str);
return date.getTime();
} catch (ParseException e) {
e.printStackTrace();
return 0;
}
}
//计算某天是星期几 //计算某天是星期几
public static int getWeekIndex(String s_date) { public static int getWeekIndex(String s_date) {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
......
...@@ -61,4 +61,11 @@ public class EditView extends LinearLayout { ...@@ -61,4 +61,11 @@ public class EditView extends LinearLayout {
mBinding.etContent.setInputType(type); mBinding.etContent.setInputType(type);
} }
public void setStatus(boolean status){
if (status){
mBinding.tvStatus.setVisibility(INVISIBLE);
}else{
mBinding.tvStatus.setVisibility(VISIBLE);
}
}
} }
...@@ -26,7 +26,16 @@ ...@@ -26,7 +26,16 @@
android:textSize="@dimen/text_12_5" android:textSize="@dimen/text_12_5"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:gravity="center|right" android:gravity="center|right"
android:text=""
android:singleLine="true" android:singleLine="true"
android:background="@null" android:background="@null"
android:outlineProvider="none"/> android:outlineProvider="none"/>
<TextView
android:id="@+id/tv_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_0287F9"
android:text="!"
android:paddingLeft="5dp"
android:visibility="invisible"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
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.ConfigEntity;
import com.srthinker.statinfo.database.entity.PersonEntity; import com.srthinker.statinfo.database.entity.PersonEntity;
import org.junit.Test; import org.junit.Test;
...@@ -55,4 +56,19 @@ public class EqualTest { ...@@ -55,4 +56,19 @@ public class EqualTest {
System.out.println("遍历bean的:name="+bean.getUsername()); System.out.println("遍历bean的:name="+bean.getUsername());
} }
} }
@Test
public void configTest1(){
List<ConfigEntity> configList1 = new ArrayList<>();
List<ConfigEntity> configList2 = new ArrayList<>();
ConfigEntity configBean = new ConfigEntity();
configBean.setUsername("admin");
configBean.setServerIp("111");
ConfigEntity configBean1 = new ConfigEntity();
configBean1.setUsername("admin");
configBean1.setServerIp("111");
configList1.add(configBean);
configList2.add(configBean1);
System.out.println("是否相等="+configList1.equals(configList2));
}
} }
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