Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StatInfo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenyuling
StatInfo
Commits
02ad91e1
Commit
02ad91e1
authored
Aug 23, 2023
by
chenyuling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加ConfigEntity
parent
100eeedc
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
714 additions
and
89 deletions
+714
-89
ConfigBean.java
...src/main/java/com/srthinker/statinfo/bean/ConfigBean.java
+21
-4
ConfigEntity.java
.../com/srthinker/statinfo/database/entity/ConfigEntity.java
+72
-0
ConfigHelper.java
.../com/srthinker/statinfo/database/helper/ConfigHelper.java
+163
-0
ConfigCallback.java
.../java/com/srthinker/statinfo/listener/ConfigCallback.java
+4
-2
UpperDevicesCallback.java
...thinker/statinfo/listener/upper/UpperDevicesCallback.java
+10
-0
ApiQuest.java
.../main/java/com/srthinker/statinfo/presenter/ApiQuest.java
+176
-19
MainActivity.java
...rc/main/java/com/srthinker/statinfo/uis/MainActivity.java
+8
-7
ConfigDlgFragment.java
...om/srthinker/statinfo/uis/fragment/ConfigDlgFragment.java
+158
-31
MathUtil.java
...ain/java/com/srthinker/statinfo/util/common/MathUtil.java
+10
-0
SharedUtil.java
...n/java/com/srthinker/statinfo/util/common/SharedUtil.java
+42
-4
custom_edit.xml
app/src/main/res/layout/custom_edit.xml
+5
-3
dialog_config.xml
app/src/main/res/layout/dialog_config.xml
+39
-15
EqualTest.java
app/src/test/java/com/srthinker/statinfo/EqualTest.java
+6
-4
No files found.
app/src/main/java/com/srthinker/statinfo/bean/ConfigBean.java
View file @
02ad91e1
...
...
@@ -6,6 +6,7 @@ public class ConfigBean {
private
String
username
;
private
String
password
;
private
String
serverIp
;
private
boolean
isConnect
;
public
String
getUsername
()
{
return
username
;
...
...
@@ -31,13 +32,28 @@ public class ConfigBean {
this
.
serverIp
=
serverIp
;
}
public
ConfigBean
(
String
username
,
String
password
,
String
serverIp
)
{
public
boolean
isConnect
()
{
return
isConnect
;
}
public
void
setConnect
(
boolean
connect
)
{
isConnect
=
connect
;
}
public
ConfigBean
()
{
}
public
ConfigBean
(
String
username
,
String
password
,
String
serverIp
,
boolean
isConnect
)
{
this
.
username
=
username
;
this
.
password
=
password
;
this
.
serverIp
=
serverIp
;
this
.
isConnect
=
isConnect
;
}
public
ConfigBean
()
{
public
ConfigBean
(
String
username
,
String
password
,
String
serverIp
)
{
this
.
username
=
username
;
this
.
password
=
password
;
this
.
serverIp
=
serverIp
;
}
@Override
...
...
@@ -45,12 +61,12 @@ public class ConfigBean {
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
ConfigBean
that
=
(
ConfigBean
)
o
;
return
Objects
.
equals
(
username
,
that
.
username
)
&&
Objects
.
equals
(
password
,
that
.
password
)
&&
Objects
.
equals
(
serverIp
,
that
.
serverIp
);
return
isConnect
==
that
.
isConnect
&&
Objects
.
equals
(
username
,
that
.
username
)
&&
Objects
.
equals
(
password
,
that
.
password
)
&&
Objects
.
equals
(
serverIp
,
that
.
serverIp
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
username
,
password
,
serverIp
);
return
Objects
.
hash
(
username
,
password
,
serverIp
,
isConnect
);
}
@Override
...
...
@@ -59,6 +75,7 @@ public class ConfigBean {
"username='"
+
username
+
'\''
+
", password='"
+
password
+
'\''
+
", serverIp='"
+
serverIp
+
'\''
+
", isConnect="
+
isConnect
+
'}'
;
}
}
app/src/main/java/com/srthinker/statinfo/database/entity/ConfigEntity.java
0 → 100644
View file @
02ad91e1
package
com
.
srthinker
.
statinfo
.
database
.
entity
;
import
com.raizlabs.android.dbflow.annotation.Column
;
import
com.raizlabs.android.dbflow.annotation.PrimaryKey
;
import
com.raizlabs.android.dbflow.annotation.Table
;
import
com.raizlabs.android.dbflow.structure.BaseModel
;
import
com.srthinker.statinfo.database.AppDB
;
@Table
(
database
=
AppDB
.
class
)
public
class
ConfigEntity
extends
BaseModel
{
@PrimaryKey
(
autoincrement
=
true
)
@Column
private
int
id
;
@Column
private
String
username
;
@Column
private
String
password
;
@Column
private
String
serverIp
;
@Column
private
boolean
isConnect
;
@Column
private
int
type
;
//是进设备还是出设备
public
int
getId
()
{
return
id
;
}
public
void
setId
(
int
id
)
{
this
.
id
=
id
;
}
public
String
getUsername
()
{
return
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getServerIp
()
{
return
serverIp
;
}
public
void
setServerIp
(
String
serverIp
)
{
this
.
serverIp
=
serverIp
;
}
public
boolean
isConnect
()
{
return
isConnect
;
}
public
void
setConnect
(
boolean
connect
)
{
isConnect
=
connect
;
}
public
int
getType
()
{
return
type
;
}
public
void
setType
(
int
type
)
{
this
.
type
=
type
;
}
}
app/src/main/java/com/srthinker/statinfo/database/helper/ConfigHelper.java
0 → 100644
View file @
02ad91e1
package
com
.
srthinker
.
statinfo
.
database
.
helper
;
import
com.raizlabs.android.dbflow.config.DatabaseDefinition
;
import
com.raizlabs.android.dbflow.config.FlowManager
;
import
com.raizlabs.android.dbflow.sql.language.SQLite
;
import
com.raizlabs.android.dbflow.structure.database.DatabaseWrapper
;
import
com.raizlabs.android.dbflow.structure.database.transaction.ITransaction
;
import
com.srthinker.statinfo.database.AppDB
;
import
com.srthinker.statinfo.database.entity.ConfigEntity
;
import
com.srthinker.statinfo.database.entity.ConfigEntity_Table
;
import
com.srthinker.statinfo.util.common.Mutex
;
import
java.util.List
;
public
class
ConfigHelper
{
private
static
ConfigHelper
configHelper
;
private
Mutex
locker
=
new
Mutex
();
public
static
ConfigHelper
getInstance
(){
if
(
configHelper
==
null
)
{
synchronized
(
ConfigHelper
.
class
){
configHelper
=
new
ConfigHelper
();
}
}
return
configHelper
;
}
public
boolean
save
(
ConfigEntity
entity
){
boolean
result
=
false
;
locker
.
lock
(
0
);
result
=
entity
.
save
();
locker
.
unlock
();
return
result
;
}
public
long
add
(
ConfigEntity
entity
)
{
long
result
=
-
1
;
locker
.
lock
(
0
);
result
=
entity
.
insert
();
locker
.
unlock
();
return
result
;
}
public
void
add
(
List
<
ConfigEntity
>
entities
){
locker
.
lock
(
0
);
DatabaseDefinition
database
=
FlowManager
.
getDatabase
(
AppDB
.
class
);
database
.
beginTransactionAsync
(
new
ITransaction
()
{
@Override
public
void
execute
(
DatabaseWrapper
databaseWrapper
)
{
for
(
ConfigEntity
entity
:
entities
)
{
entity
.
insert
(
databaseWrapper
);
}
}
}).
build
().
execute
();
locker
.
unlock
();
}
public
void
save
(
List
<
ConfigEntity
>
entities
){
locker
.
lock
(
0
);
DatabaseDefinition
database
=
FlowManager
.
getDatabase
(
AppDB
.
class
);
database
.
beginTransactionAsync
(
new
ITransaction
()
{
@Override
public
void
execute
(
DatabaseWrapper
databaseWrapper
)
{
for
(
ConfigEntity
entity
:
entities
)
{
entity
.
save
(
databaseWrapper
);
}
}
}).
build
().
execute
();
locker
.
unlock
();
}
public
boolean
delete
(
ConfigEntity
entity
)
{
boolean
result
=
false
;
locker
.
lock
(
0
);
result
=
entity
.
delete
();
locker
.
unlock
();
return
result
;
}
public
void
delete
(
List
<
ConfigEntity
>
entities
){
locker
.
lock
(
0
);
DatabaseDefinition
database
=
FlowManager
.
getDatabase
(
AppDB
.
class
);
database
.
beginTransactionAsync
(
new
ITransaction
()
{
@Override
public
void
execute
(
DatabaseWrapper
databaseWrapper
)
{
for
(
ConfigEntity
entity
:
entities
)
{
entity
.
delete
(
databaseWrapper
);
}
}
}).
build
().
execute
();
locker
.
unlock
();
}
public
void
update
(
List
<
ConfigEntity
>
entities
){
locker
.
lock
(
0
);
DatabaseDefinition
database
=
FlowManager
.
getDatabase
(
AppDB
.
class
);
database
.
beginTransactionAsync
(
new
ITransaction
()
{
@Override
public
void
execute
(
DatabaseWrapper
databaseWrapper
)
{
for
(
ConfigEntity
entity
:
entities
)
{
entity
.
update
(
databaseWrapper
);
}
}
}).
build
().
execute
();
locker
.
unlock
();
}
public
boolean
update
(
ConfigEntity
entity
)
{
boolean
result
=
false
;
locker
.
lock
(
0
);
result
=
entity
.
update
();
locker
.
unlock
();
return
result
;
}
public
void
clear
()
{
locker
.
lock
(
0
);
SQLite
.
delete
(
ConfigEntity
.
class
).
execute
();
locker
.
unlock
();
}
public
List
<
ConfigEntity
>
queryAll
(){
List
<
ConfigEntity
>
configEntityList
=
null
;
locker
.
lock
(
0
);
configEntityList
=
SQLite
.
select
().
from
(
ConfigEntity
.
class
).
queryList
();
locker
.
unlock
();
return
configEntityList
;
}
public
List
<
ConfigEntity
>
queryByType
(
int
type
){
List
<
ConfigEntity
>
configEntityList
=
null
;
locker
.
lock
(
0
);
configEntityList
=
SQLite
.
select
().
from
(
ConfigEntity
.
class
).
where
(
ConfigEntity_Table
.
type
.
eq
(
type
)).
queryList
();
locker
.
unlock
();
return
configEntityList
;
}
public
List
<
ConfigEntity
>
queryByTypeIp
(
int
type
,
String
ip
){
List
<
ConfigEntity
>
configEntityList
=
null
;
locker
.
lock
(
0
);
configEntityList
=
SQLite
.
select
().
from
(
ConfigEntity
.
class
).
where
(
ConfigEntity_Table
.
type
.
eq
(
type
)).
and
(
ConfigEntity_Table
.
serverIp
.
eq
(
ip
)).
queryList
();
locker
.
unlock
();
return
configEntityList
;
}
public
ConfigEntity
queryById
(
int
id
){
ConfigEntity
entity
=
null
;
locker
.
lock
(
0
);
entity
=
SQLite
.
select
().
from
(
ConfigEntity
.
class
).
where
(
ConfigEntity_Table
.
id
.
eq
(
id
)).
querySingle
();
locker
.
unlock
();
return
entity
;
}
public
ConfigEntity
queryByIp
(
String
ip
){
ConfigEntity
entity
=
null
;
locker
.
lock
(
0
);
entity
=
SQLite
.
select
().
from
(
ConfigEntity
.
class
).
where
(
ConfigEntity_Table
.
serverIp
.
eq
(
ip
)).
querySingle
();
locker
.
unlock
();
return
entity
;
}
}
app/src/main/java/com/srthinker/statinfo/listener/ConfigCallback.java
View file @
02ad91e1
package
com
.
srthinker
.
statinfo
.
listener
;
import
com.srthinker.statinfo.bean.ConfigBean
;
import
com.srthinker.statinfo.database.entity.ConfigEntity
;
import
java.util.List
;
public
interface
ConfigCallback
{
void
onUpdateConfig
(
ConfigBean
configBean
,
int
type
);
void
onUpdateConfig
(
List
<
ConfigEntity
>
configList
,
int
type
);
}
app/src/main/java/com/srthinker/statinfo/listener/upper/UpperDevicesCallback.java
0 → 100644
View file @
02ad91e1
package
com
.
srthinker
.
statinfo
.
listener
.
upper
;
import
com.srthinker.statinfo.database.entity.PersonEntity
;
import
java.util.List
;
public
interface
UpperDevicesCallback
{
void
getAllPassInfo
(
List
<
PersonEntity
>
passAllEntities
,
int
type
);
void
onAllConnectStatus
(
boolean
hasDisConnect
,
int
type
);
}
app/src/main/java/com/srthinker/statinfo/presenter/ApiQuest.java
View file @
02ad91e1
...
...
@@ -3,17 +3,64 @@ package com.srthinker.statinfo.presenter;
import
static
com
.
srthinker
.
statinfo
.
constant
.
InOutType
.
ENTER_TYPE
;
import
static
com
.
srthinker
.
statinfo
.
constant
.
InOutType
.
LEAVE_TYPE
;
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.helper.ConfigHelper
;
import
com.srthinker.statinfo.listener.DeviceCallback
;
import
com.srthinker.statinfo.listener.QueryPersonCallback
;
import
com.srthinker.statinfo.listener.upper.UpperDevicesCallback
;
import
com.srthinker.statinfo.util.common.ThreadPool
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
ApiQuest
{
private
static
ApiManager
enterMgr
;
private
static
ApiManager
leaveMgr
;
// private static ApiManager enterMgr;
// private static ApiManager leaveMgr;
private
static
ApiQuest
apiQuest
;
private
static
boolean
isEnterAllConnect
=
false
;
private
static
boolean
isLeaveAllConnect
=
false
;
private
static
LinkedHashMap
<
String
,
Boolean
>
enterIpStatus
=
new
LinkedHashMap
<>();
private
static
LinkedHashMap
<
String
,
Boolean
>
leaveIpStatus
=
new
LinkedHashMap
<>();
private
static
List
<
PersonEntity
>
allEnterPass
=
new
ArrayList
<>();
private
static
List
<
PersonEntity
>
allLeavePass
=
new
ArrayList
<>();
private
UpperDevicesCallback
upperDevicesCallback
;
private
static
LinkedHashMap
<
String
,
ApiManager
>
enterMgrHashMap
=
new
LinkedHashMap
<>();
private
static
LinkedHashMap
<
String
,
ApiManager
>
leaveMgrHashMap
=
new
LinkedHashMap
<>();
private
String
oneEnterIp
;
public
static
void
startEnterApi
(
ConfigBean
configBean
,
DeviceCallback
callback
){
if
(
configBean
!=
null
)
{
public
static
ApiQuest
getInstance
(){
if
(
apiQuest
==
null
)
{
synchronized
(
ApiQuest
.
class
){
apiQuest
=
new
ApiQuest
();
}
}
return
apiQuest
;
}
public
void
setOnUpperDevicesCallback
(
UpperDevicesCallback
upperDevicesCallback
){
this
.
upperDevicesCallback
=
upperDevicesCallback
;
}
public
void
startEnterApi
(
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
();
boolean
isConnect
=
config
.
isConnect
();
if
(
i
==
0
){
oneEnterIp
=
serverIp
;
}
startEnterIp
(
username
,
password
,
serverIp
,
isConnect
);
}
}
/*if (configBean != null) {
//如果之前曾经有过的,则停掉之前的
if (enterMgr!=null){
stopEnterApi();
...
...
@@ -21,12 +68,95 @@ public class ApiQuest {
enterMgr = new ApiManager(configBean.getUsername(), configBean.getPassword(), configBean.getServerIp(), ENTER_TYPE);
if (enterMgr != null) {
enterMgr.start();
enterMgr
.
setOnDeviceCallback
(
callback
);
enterMgr.setOnDeviceCallback(
this
);
}
}*/
}
private
void
startEnterIp
(
String
username
,
String
password
,
String
ip
,
boolean
isLastConnect
)
{
//如果之前有过则停掉
if
(
enterMgrHashMap
.
get
(
ip
)!=
null
){
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
();
enterMgr
.
setOnDeviceCallback
(
new
DeviceCallback
()
{
@Override
public
void
getPassInfo
(
List
<
PersonEntity
>
passEntities
,
int
type
)
{
allEnterPass
.
addAll
(
passEntities
);
}
@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
);
}
});
}
}
});
}
public
static
void
startLeaveApi
(
ConfigBean
configBean
,
DeviceCallback
callback
){
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
)
{
//如果之前有过则停掉
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
();
leaveMgr
.
setOnDeviceCallback
(
new
DeviceCallback
()
{
@Override
public
void
getPassInfo
(
List
<
PersonEntity
>
passEntities
,
int
type
)
{
}
@Override
public
void
onConnectStatus
(
boolean
isConnect
,
int
type
)
{
}
});
}
/*public void startLeaveApi(ConfigBean configBean){
if (configBean != null) {
//如果之前曾经有过的,则停掉之前的
if (leaveMgr!=null){
...
...
@@ -35,40 +165,67 @@ public class ApiQuest {
leaveMgr = new ApiManager(configBean.getUsername(), configBean.getPassword(), configBean.getServerIp(), LEAVE_TYPE);
if (leaveMgr != null) {
leaveMgr.start();
leaveMgr
.
setOnDeviceCallback
(
callback
);
leaveMgr.setOnDeviceCallback(
this
);
}
}
}
}
*/
public
static
void
stopApi
(){
public
void
stopApi
(){
stopEnterApi
();
stopLeaveApi
();
}
public
static
void
stopEnterApi
(){
public
void
stopEnterApi
(){
for
(
Map
.
Entry
<
String
,
ApiManager
>
enterMgr
:
enterMgrHashMap
.
entrySet
())
{
ApiManager
enter
=
enterMgr
.
getValue
();
if
(
enter
!=
null
){
enter
.
stop
();
enter
.
setOnDeviceCallback
(
null
);
enter
=
null
;
}
enterMgrHashMap
.
remove
(
enterMgr
.
getKey
());
}
}
public
void
stopLeaveApi
(){
for
(
Map
.
Entry
<
String
,
ApiManager
>
leaveMgr
:
leaveMgrHashMap
.
entrySet
())
{
ApiManager
leave
=
leaveMgr
.
getValue
();
if
(
leave
!=
null
){
leave
.
stop
();
leave
.
setOnDeviceCallback
(
null
);
leave
=
null
;
}
leaveMgrHashMap
.
remove
(
leaveMgr
.
getKey
());
}
}
/*private void stopEnterApi(){
if (enterMgr != null) {
enterMgr.stop();
enterMgr.setOnDeviceCallback(null);
enterMgr.setOnQueryPersonsCallback(null);
enterMgr = null;
}
}
}
*/
public
static
void
stopLeaveApi
(){
/*private
void stopLeaveApi(){
if (leaveMgr != null) {
leaveMgr.stop();
leaveMgr.setOnDeviceCallback(null);
leaveMgr.setOnQueryPersonsCallback(null);
leaveMgr = null;
}
}
}
*/
public
static
void
queryPersons
(
QueryPersonCallback
callback
){
if
(
enterMgr
!=
null
){
public
void
queryPersons
(
QueryPersonCallback
callback
){
if
(
enterMgrHashMap
.
size
()>
0
){
ApiManager
oneEnterMgr
=
enterMgrHashMap
.
get
(
oneEnterIp
);
oneEnterMgr
.
queryPersons
();
oneEnterMgr
.
setOnQueryPersonsCallback
(
callback
);
}
/*if (enterMgr!=null){
enterMgr.queryPersons();
enterMgr.setOnQueryPersonsCallback(callback);
}
}*/
}
}
app/src/main/java/com/srthinker/statinfo/uis/MainActivity.java
View file @
02ad91e1
...
...
@@ -38,6 +38,7 @@ 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.PersonHelper
;
import
com.srthinker.statinfo.databinding.ActivityMainBinding
;
...
...
@@ -563,10 +564,10 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
public
void
OnIPChange
(
String
ipAddress
,
String
networkType
)
{
Log
.
i
(
TAG
,
"OnIPChange: change==>"
);
//questApi();
ConfigBean
enterConfig
=
SharedUtil
.
getInstance
(
this
).
readShared
(
ENTER_TYPE
,
ConfigBean
.
class
,
""
);
ApiQuest
.
startEnterApi
(
enterConfig
,
this
);
ConfigBean
leaveConfig
=
SharedUtil
.
getInstance
(
this
).
readShared
(
LEAVE_TYPE
,
ConfigBean
.
class
,
""
);
ApiQuest
.
startLeaveApi
(
leaveConfig
,
this
);
List
<
ConfigBean
>
enterConfigList
=
SharedUtil
.
getInstance
(
this
).
readSharedList
(
ENTER_TYPE
,
ConfigBean
.
class
,
""
);
ApiQuest
.
startEnterApi
(
enterConfig
List
,
this
);
List
<
ConfigBean
>
leaveConfigList
=
SharedUtil
.
getInstance
(
this
).
readSharedList
(
LEAVE_TYPE
,
ConfigBean
.
class
,
""
);
ApiQuest
.
startLeaveApi
(
leaveConfig
List
,
this
);
}
@Override
...
...
@@ -575,13 +576,13 @@ public class MainActivity extends BaseActivity implements OnTimeUpdateListener,
}
@Override
public
void
onUpdateConfig
(
ConfigBean
configBean
,
int
type
)
{
public
void
onUpdateConfig
(
List
<
ConfigEntity
>
configList
,
int
type
)
{
//配置改变,更新接口
//Log.i(TAG, "onUpdateConfig: config="+configBean.toString()+",type="+type);
if
(
type
==
ENTER_TYPE
){
ApiQuest
.
startEnterApi
(
configBean
,
this
);
ApiQuest
.
getInstance
().
startEnterApi
(
configList
);
}
else
if
(
type
==
LEAVE_TYPE
){
ApiQuest
.
startLeaveApi
(
configBean
,
this
);
ApiQuest
.
getInstance
().
startLeaveApi
(
configList
);
}
}
...
...
app/src/main/java/com/srthinker/statinfo/uis/fragment/ConfigDlgFragment.java
View file @
02ad91e1
...
...
@@ -14,28 +14,39 @@ import android.view.LayoutInflater;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
import
android.widget.LinearLayout
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.fragment.app.DialogFragment
;
import
com.srthinker.statinfo.bean.ConfigBean
;
import
com.srthinker.statinfo.database.entity.ConfigEntity
;
import
com.srthinker.statinfo.database.helper.ConfigHelper
;
import
com.srthinker.statinfo.databinding.DialogConfigBinding
;
import
com.srthinker.statinfo.listener.ConfigCallback
;
import
com.srthinker.statinfo.util.common.
Shared
Util
;
import
com.srthinker.statinfo.util.common.
Gson
Util
;
import
com.srthinker.statinfo.util.common.Utils
;
import
com.srthinker.statinfo.wedget.EditView
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
public
class
ConfigDlgFragment
extends
DialogFragment
{
private
Context
context
;
private
int
type
;
private
com
.
srthinker
.
statinfo
.
databinding
.
DialogConfigBinding
mBinding
;
private
ConfigBean
mLastConfig
;
//private List<ConfigBean>
mLastConfig;
private
ConfigCallback
callback
;
private
String
mLastAccount
;
private
String
mLastPassword
;
private
String
mLastServerIp
;
//
private String mLastServerIp;
private
String
username
;
private
List
<
EditView
>
devicesIpList
=
new
ArrayList
<>();
private
List
<
ConfigEntity
>
mLastConfig
;
private
boolean
isUpdate
=
false
;
//private List<String> mLastServerIpList = new ArrayList<>();
public
static
ConfigDlgFragment
getInstance
(
int
type
){
ConfigDlgFragment
configDlgFragment
=
new
ConfigDlgFragment
();
...
...
@@ -61,6 +72,7 @@ public class ConfigDlgFragment extends DialogFragment {
mBinding
.
evAccount
.
initItem
(
"设备账号:"
,
"输入设备账号"
);
mBinding
.
evPassword
.
initItem
(
"设备密码:"
,
"输入设备密码"
);
mBinding
.
evServerip
.
initItem
(
"设备1的IP:"
,
"输入设备1的IP"
);
devicesIpList
.
add
(
mBinding
.
evServerip
);
mBinding
.
evPassword
.
setInputType
(
InputType
.
TYPE_CLASS_TEXT
|
InputType
.
TYPE_TEXT_VARIATION_PASSWORD
);
if
(
type
==
ENTER_TYPE
){
mBinding
.
tvTitle
.
setText
(
"进去设备的配置信息"
);
...
...
@@ -77,8 +89,24 @@ public class ConfigDlgFragment extends DialogFragment {
if
(!
TextUtils
.
isEmpty
(
mLastPassword
)){
mBinding
.
evPassword
.
setContent
(
mLastPassword
);
}
if
(!
TextUtils
.
isEmpty
(
mLastServerIp
)){
/*
if (!TextUtils.isEmpty(mLastServerIp)){
mBinding.evServerip.setContent(mLastServerIp);
}*/
//如果有存储的,显示存储的ip
if
(
mLastConfig
!=
null
)
{
for
(
int
i
=
0
;
i
<
mLastConfig
.
size
();
i
++)
{
ConfigEntity
config
=
mLastConfig
.
get
(
i
);
if
(
config
!=
null
)
{
String
serverIp
=
config
.
getServerIp
();
if
(
i
==
0
){
mBinding
.
evServerip
.
setContent
(
serverIp
);
}
else
{
addDeviceIpView
();
EditView
editView
=
devicesIpList
.
get
(
i
);
editView
.
setContent
(
serverIp
);
}
}
}
}
mBinding
.
ivClose
.
setOnClickListener
(
v
->{
dismiss
();
...
...
@@ -87,39 +115,101 @@ public class ConfigDlgFragment extends DialogFragment {
dismiss
();
});
mBinding
.
btnConfirm
.
setOnClickListener
(
v
->{
String
account
=
mBinding
.
evAccount
.
getContent
();
String
password
=
mBinding
.
evPassword
.
getContent
();
String
serverIp
=
mBinding
.
evServerip
.
getContent
();
if
(
TextUtils
.
isEmpty
(
account
)){
Utils
.
showTips
(
context
,
"请输入账号名!"
);
return
;
}
if
(
TextUtils
.
isEmpty
(
password
)){
Utils
.
showTips
(
context
,
"请输入密码!"
);
return
;
}
if
(
TextUtils
.
isEmpty
(
serverIp
)){
updateConfig
();
});
}
private
void
updateConfig
()
{
String
account
=
mBinding
.
evAccount
.
getContent
();
String
password
=
mBinding
.
evPassword
.
getContent
();
String
serverIp
=
mBinding
.
evServerip
.
getContent
();
if
(
TextUtils
.
isEmpty
(
account
)){
Utils
.
showTips
(
context
,
"请输入账号名!"
);
return
;
}
if
(
TextUtils
.
isEmpty
(
password
)){
Utils
.
showTips
(
context
,
"请输入密码!"
);
return
;
}
/*if (TextUtils.isEmpty(serverIp)){
Utils.showTips(context,"请输入IP!");
return;
}
ConfigBean
configBean
=
new
ConfigBean
(
account
,
password
,
serverIp
);
if
(!
configBean
.
equals
(
mLastConfig
)){
if
(
callback
!=
null
)
{
SharedUtil
.
getInstance
(
context
).
writeShared
(
type
,
configBean
);
callback
.
onUpdateConfig
(
configBean
,
type
);
Utils
.
showTips
(
context
,
"已更新配置"
);
}*/
if
(!
checkAtLeastOneIp
()){
Utils
.
showTips
(
context
,
"请输入IP!"
);
return
;
}
//List<ConfigBean> configBeanList = new ArrayList<>();
List
<
ConfigEntity
>
configEntities
=
new
ArrayList
<>();
List
<
String
>
allDeviceIps
=
getAllDeviceIps
();
/*for (String deviceIp : allDeviceIps) {
ConfigBean configBean = new ConfigBean(account, password, deviceIp);
configBeanList.add(configBean);
}*/
for
(
int
i
=
0
;
i
<
allDeviceIps
.
size
();
i
++)
{
String
ip
=
allDeviceIps
.
get
(
i
);
ConfigEntity
config
=
new
ConfigEntity
();
config
.
setUsername
(
account
);
config
.
setPassword
(
password
);
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
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
dismiss
();
});
}
if
(
isUpdate
||
allDeviceIps
.
size
()!=
mLastConfig
.
size
()){
/*if (callback != null) {
SharedUtil.getInstance(context).writeShared(type,configBeanList);
callback.onUpdateConfig(configBeanList,type);
Utils.showTips(context,"已更新配置");
}*/
if
(
callback
!=
null
)
{
ConfigHelper
.
getInstance
().
delete
(
mLastConfig
);
ConfigHelper
.
getInstance
().
add
(
configEntities
);
callback
.
onUpdateConfig
(
configEntities
,
type
);
Utils
.
showTips
(
context
,
"已更新配置"
);
}
}
dismiss
();
}
private
void
initData
()
{
mLastConfig
=
SharedUtil
.
getInstance
(
context
).
readShared
(
type
,
ConfigBean
.
class
,
""
);
/*
private void initData() {
mLastConfig = SharedUtil.getInstance(context).readShared
List
(type, ConfigBean.class, "");
if (mLastConfig!=null){
mLastAccount
=
mLastConfig
.
getUsername
();
mLastPassword
=
mLastConfig
.
getPassword
();
mLastServerIp
=
mLastConfig
.
getServerIp
();
for (int i = 0; i < mLastConfig.size(); i++) {
ConfigBean configBean = mLastConfig.get(i);
if (configBean != null) {
if (i==0){
mLastAccount = configBean.getUsername();
mLastPassword = configBean.getPassword();
}
}
}
}
}*/
private
void
initData
(){
mLastConfig
=
ConfigHelper
.
getInstance
().
queryByType
(
type
);
if
(
this
.
mLastConfig
!=
null
){
for
(
int
i
=
0
;
i
<
this
.
mLastConfig
.
size
();
i
++)
{
ConfigEntity
config
=
this
.
mLastConfig
.
get
(
i
);
if
(
config
!=
null
)
{
if
(
i
==
0
){
mLastAccount
=
config
.
getUsername
();
mLastPassword
=
config
.
getPassword
();
}
}
}
}
}
...
...
@@ -127,6 +217,43 @@ public class ConfigDlgFragment extends DialogFragment {
this
.
username
=
username
;
}
//获取所有设备ip
private
List
<
String
>
getAllDeviceIps
(){
List
<
String
>
ips
=
new
ArrayList
<>();
for
(
EditView
editView
:
devicesIpList
)
{
String
ip
=
editView
.
getContent
();
if
(!
TextUtils
.
isEmpty
(
ip
)){
ips
.
add
(
ip
);
}
}
//去重,保证没有重复的Ip
ips
=
ips
.
stream
()
.
distinct
()
.
collect
(
Collectors
.
toList
());
return
ips
;
}
//检查至少一个ip不为空
private
boolean
checkAtLeastOneIp
(){
for
(
EditView
editView
:
devicesIpList
)
{
String
ip
=
editView
.
getContent
();
if
(!
TextUtils
.
isEmpty
(
ip
)){
return
true
;
}
}
return
false
;
}
private
void
addDeviceIpView
(){
EditView
editView
=
new
EditView
(
context
);
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
);
editView
.
setLayoutParams
(
layoutParams
);
mBinding
.
llIps
.
addView
(
editView
);
devicesIpList
.
add
(
editView
);
}
@Override
public
void
onResume
()
{
super
.
onResume
();
...
...
app/src/main/java/com/srthinker/statinfo/util/common/MathUtil.java
0 → 100644
View file @
02ad91e1
package
com
.
srthinker
.
statinfo
.
util
.
common
;
import
java.util.List
;
public
class
MathUtil
{
//想比较两个对象数组的内容是否相同,而不关心它们的顺序
public
static
<
T
>
boolean
areListsEqual
(
List
<
T
>
list1
,
List
<
T
>
list2
)
{
return
list1
.
containsAll
(
list2
)
&&
list2
.
containsAll
(
list1
);
}
}
app/src/main/java/com/srthinker/statinfo/util/common/SharedUtil.java
View file @
02ad91e1
...
...
@@ -5,6 +5,8 @@ import android.content.SharedPreferences;
import
android.text.TextUtils
;
import
android.util.Log
;
import
java.util.List
;
// 这是共享参数的工具类,统一对共享参数的读写操作
public
class
SharedUtil
{
private
static
final
String
TAG
=
"SharedUtil"
;
...
...
@@ -51,7 +53,11 @@ public class SharedUtil {
writeShared
(
String
.
valueOf
(
key
),
obj
);
}
//转化成String后保存
public
void
writeShared
(
int
key
,
List
<
Object
>
objectList
){
writeShared
(
String
.
valueOf
(
key
),
objectList
);
}
//对象转化成String后保存
public
void
writeShared
(
String
key
,
Object
obj
){
String
value
=
null
;
try
{
...
...
@@ -64,6 +70,19 @@ public class SharedUtil {
mEditor
.
commit
();
// 提交编辑器中的修改
}
//对象数组转化为String后保存
public
void
writeShared
(
String
key
,
List
<
Object
>
objectList
){
String
value
=
null
;
try
{
value
=
GsonUtil
.
ListToJson
(
objectList
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"readShared: e.message"
+
e
.
getMessage
());
}
mEditor
.
putString
(
key
,
value
);
mEditor
.
commit
();
}
// 根据键名到共享参数中查找对应的值对象
public
String
readShared
(
String
key
,
String
defaultValue
)
{
...
...
@@ -79,7 +98,7 @@ public class SharedUtil {
}
//将String转化回对象
public
<
T
extends
Object
>
T
readShared
(
String
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
public
<
T
extends
Object
>
T
readShared
Object
(
String
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
String
readString
=
readShared
(
key
,
defaultValue
);
if
(
TextUtils
.
isEmpty
(
readString
)){
return
null
;
...
...
@@ -93,7 +112,26 @@ public class SharedUtil {
return
null
;
}
public
<
T
extends
Object
>
T
readShared
(
int
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
return
readShared
(
String
.
valueOf
(
key
),
clazz
,
defaultValue
);
public
<
T
extends
Object
>
T
readSharedObject
(
int
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
return
readSharedObject
(
String
.
valueOf
(
key
),
clazz
,
defaultValue
);
}
//将String转化为数组对象
public
<
T
extends
Object
>
List
<
T
>
readSharedList
(
String
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
String
readString
=
readShared
(
key
,
defaultValue
);
if
(
TextUtils
.
isEmpty
(
readString
)){
return
null
;
}
try
{
return
GsonUtil
.
parserJsonToArrayBeans
(
readString
,
clazz
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Log
.
e
(
TAG
,
"readShared: e.message"
+
e
.
getMessage
());
}
return
null
;
}
public
<
T
extends
Object
>
List
<
T
>
readSharedList
(
int
key
,
Class
<
T
>
clazz
,
String
defaultValue
){
return
readSharedList
(
String
.
valueOf
(
key
),
clazz
,
defaultValue
);
}
}
app/src/main/res/layout/custom_edit.xml
View file @
02ad91e1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"
4
0dp"
android:layout_height=
"
3
0dp"
android:paddingLeft=
"20dp"
android:paddingRight=
"20dp"
android:gravity=
"center"
android:layout_marginBottom=
"5dp"
android:orientation=
"horizontal"
>
<TextView
android:id=
"@+id/tv_title"
...
...
@@ -11,7 +13,7 @@
android:layout_height=
"wrap_content"
android:layout_weight=
"3"
android:textColor=
"@color/black"
android:textSize=
"@dimen/text_1
3
"
android:textSize=
"@dimen/text_1
2_5
"
android:layout_gravity=
"center_vertical"
android:text=
""
android:gravity=
"center|right"
/>
...
...
@@ -21,7 +23,7 @@
android:layout_height=
"wrap_content"
android:layout_weight=
"7"
android:textColor=
"@color/black"
android:textSize=
"@dimen/text_1
3
"
android:textSize=
"@dimen/text_1
2_5
"
android:layout_gravity=
"center_vertical"
android:gravity=
"center|right"
android:singleLine=
"true"
...
...
app/src/main/res/layout/dialog_config.xml
View file @
02ad91e1
...
...
@@ -30,27 +30,51 @@
android:padding=
"15dp"
android:layout_centerVertical=
"true"
/>
</RelativeLayout>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_account"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/dlg_margin"
/>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_password"
android:layout_width=
"match_parent"
<TextView
android:id=
"@+id/tv_add_new_ip"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/dlg_margin"
/>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_serverip"
android:textSize=
"@dimen/text_11"
android:text=
"+添加设备IP"
android:textColor=
"@color/color_2D52E3"
android:layout_gravity=
"right|center"
android:layout_marginRight=
"15dp"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"8dp"
/>
<ScrollView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"@dimen/dlg_margin"
/>
android:layout_height=
"0dp"
android:layout_weight=
"1"
android:fillViewport=
"true"
>
<LinearLayout
android:id=
"@+id/ll_ips"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_account"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_password"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
<com.srthinker.statinfo.wedget.EditView
android:id=
"@+id/ev_serverip"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center"
android:layout_marginTop=
"1
5
dp"
android:layout_marginBottom=
"2
5
dp"
android:layout_marginTop=
"1
0
dp"
android:layout_marginBottom=
"2
0
dp"
android:orientation=
"horizontal"
>
<Button
android:id=
"@+id/btn_cancel"
...
...
app/src/test/java/com/srthinker/statinfo/EqualTest.java
View file @
02ad91e1
...
...
@@ -4,16 +4,18 @@ import com.srthinker.statinfo.bean.ConfigBean;
import
org.junit.Test
;
import
java.util.Arrays
;
public
class
EqualTest
{
@Test
public
void
equalTest
(){
ConfigBean
configBean
=
new
ConfigBean
(
"1"
,
"2"
,
"3"
);
ConfigBean
configBean1
=
new
ConfigBean
(
"1"
,
"2"
,
"3"
);
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"
,
"3"
);
ConfigBean
configBean2
=
new
ConfigBean
(
"1"
,
"2"
,
Arrays
.
asList
(
"2"
,
"3"
)
);
configBean2
.
setPassword
(
"4"
);
ConfigBean
configBean3
=
new
ConfigBean
(
"1"
,
"2"
,
"3"
);
ConfigBean
configBean3
=
new
ConfigBean
(
"1"
,
"2"
,
Arrays
.
asList
(
"2"
,
"3"
)
);
configBean3
.
setPassword
(
"5"
);
System
.
out
.
println
(
"内容是否相等="
+
configBean2
.
equals
(
configBean3
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment