Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a4c8df6f
authored
Jun 02, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
4383580a
5477c597
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
43 deletions
+76
-43
app/build.gradle
+2
-2
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+35
-30
app/src/main/java/com/bgycc/smartcanteen/data/DatabaseManager.java
+1
-0
app/src/main/java/com/bgycc/smartcanteen/data/FinishCommand.java
+17
-0
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
+5
-4
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
+14
-4
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
+2
-3
No files found.
app/build.gradle
View file @
a4c8df6f
...
...
@@ -7,8 +7,8 @@ android {
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
22
targetSdkVersion
29
versionCode
1
6
versionName
"1.3.
6
"
versionCode
1
7
versionName
"1.3.
7
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
a4c8df6f
...
...
@@ -129,33 +129,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
initViews
();
SCWebSocketClient
.
get
Instance
().
get
ConnectStateEvent
().
observe
(
this
,
event
->
{
SCWebSocketClient
.
getConnectStateEvent
().
observe
(
this
,
event
->
{
if
(
debugLayoutIsNotInflate
())
return
;
String
msg
;
switch
(
event
.
getState
())
{
case
ConnectState
.
OFFLINE
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_offline
),
NetworkUtils
.
getTryingNetworkType
(
this
));
break
;
case
ConnectState
.
CONNECTING
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connecting
),
NetworkUtils
.
getNetworkType
(
this
));
break
;
case
ConnectState
.
CONNECTED
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connected
),
event
.
getHost
(),
NetworkUtils
.
getNetworkType
(
this
));
// socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo
();
refreshWifiInfo
();
break
;
case
ConnectState
.
RECONNECTING
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_reconnecting
),
event
.
getHost
());
break
;
case
ConnectState
.
CHANGE_NETWORK
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_change_network
),
NetworkUtils
.
getTryingNetworkType
(
this
));
break
;
default
:
msg
=
""
;
break
;
}
serverText
.
setText
(
msg
);
refreshServerInfo
();
});
payOnlineViewModel
.
getPayOnlineStateEvent
().
observe
(
this
,
event
->
{
...
...
@@ -349,8 +325,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel
.
initialize
();
handler
.
post
(
updateTimeRunnable
);
MonitorUtils
.
startLogFilesMonitor
(
this
);
MonitorUtils
.
startDatabaseMonitor
(
this
);
MonitorUtils
.
startMonitors
(
this
);
SCWebSocketClient
.
getInstance
().
tryConnect
();
}
...
...
@@ -424,8 +399,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper
.
release
();
SCWebSocketClient
.
getInstance
().
realClose
();
SCTaskExecutor
.
getInstance
().
quit
();
MonitorUtils
.
stopDatabaseMonitor
(
this
);
MonitorUtils
.
stopLogFilesMonitor
(
this
);
MonitorUtils
.
stopMonitors
(
this
);
}
private
void
initViews
()
{
...
...
@@ -469,11 +443,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
logoLayout
.
setVisibility
(
View
.
GONE
);
debugLayout
.
setOnClickListener
(
this
);
logoLayout
.
setOnClickListener
(
this
);
refreshServerInfo
();
refreshEthInfo
();
refreshWifiInfo
();
refreshPackageInfo
();
}
private
void
refreshServerInfo
()
{
ConnectState
event
=
SCWebSocketClient
.
getConnectStateEvent
().
getValue
();
if
(
event
==
null
)
return
;
String
msg
;
switch
(
event
.
getState
())
{
case
ConnectState
.
OFFLINE
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_offline
),
NetworkUtils
.
getTryingNetworkType
(
this
));
break
;
case
ConnectState
.
CONNECTING
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connecting
),
NetworkUtils
.
getNetworkType
(
this
));
break
;
case
ConnectState
.
CONNECTED
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_connected
),
event
.
getHost
(),
NetworkUtils
.
getNetworkType
(
this
));
// socket链接成功后刷新wifi及eth的ip地址信息
refreshEthInfo
();
refreshWifiInfo
();
break
;
case
ConnectState
.
RECONNECTING
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_reconnecting
),
event
.
getHost
());
break
;
case
ConnectState
.
CHANGE_NETWORK
:
msg
=
String
.
format
(
getString
(
R
.
string
.
connect_change_network
),
NetworkUtils
.
getTryingNetworkType
(
this
));
break
;
default
:
msg
=
""
;
break
;
}
serverText
.
setText
(
msg
);
}
private
void
refreshEthInfo
()
{
String
ethMac
=
NetworkUtils
.
getEthernetMacAddress
();
String
ethIP
=
NetworkUtils
.
getEthernetIpString
();
...
...
app/src/main/java/com/bgycc/smartcanteen/data/DatabaseManager.java
View file @
a4c8df6f
...
...
@@ -61,6 +61,7 @@ public abstract class DatabaseManager extends RoomDatabase {
DatabaseManager
.
class
,
DB_NAME
)
.
addCallback
(
new
OldDataCompatible
())
.
addCallback
(
new
FinishCommand
())
.
addCallback
(
new
ForceToPayOffline
())
.
addMigrations
(
new
_1To_2Migration
())
// 一旦版本不兼容则清空数据库
...
...
app/src/main/java/com/bgycc/smartcanteen/data/FinishCommand.java
0 → 100644
View file @
a4c8df6f
package
com
.
bgycc
.
smartcanteen
.
data
;
import
androidx.annotation.NonNull
;
import
androidx.room.RoomDatabase
;
import
androidx.sqlite.db.SupportSQLiteDatabase
;
import
com.bgycc.smartcanteen.entity.Command
;
/**
* 应用启动时,将所有未执行的指令设置为"已完成"
*/
public
class
FinishCommand
extends
RoomDatabase
.
Callback
{
@Override
public
void
onOpen
(
@NonNull
SupportSQLiteDatabase
db
)
{
db
.
execSQL
(
"update "
+
Command
.
TABLE_NAME
+
" set finish = 1 where finish == 0"
);
}
}
app/src/main/java/com/bgycc/smartcanteen/socket/SCWebSocketClient.java
View file @
a4c8df6f
...
...
@@ -57,10 +57,6 @@ public class SCWebSocketClient extends WebSocketClient {
private
MutableLiveData
<
ConnectState
>
connectState
=
new
MutableLiveData
<>();
public
LiveData
<
ConnectState
>
getConnectStateEvent
()
{
return
connectState
;
}
public
static
void
init
(
URI
serverUri
,
String
deviceSN
,
Gson
gson
)
{
if
(
instance
!=
null
)
return
;
instance
=
new
SCWebSocketClient
(
serverUri
,
deviceSN
,
gson
);
...
...
@@ -70,6 +66,11 @@ public class SCWebSocketClient extends WebSocketClient {
return
instance
;
}
public
static
LiveData
<
ConnectState
>
getConnectStateEvent
()
{
if
(
instance
==
null
)
return
null
;
return
instance
.
connectState
;
}
public
void
tryConnect
()
{
LogUtils
.
d
(
TAG
,
"尝试通过WebSocket链接服务器"
);
forceStop
=
false
;
...
...
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
View file @
a4c8df6f
...
...
@@ -17,8 +17,18 @@ public class MonitorUtils {
private
static
final
int
LOG_REPEAT_INTERVAL
=
4
;
private
static
final
int
DATABASE_REPEAT_INTERVAL
=
12
;
public
static
void
startMonitors
(
Context
context
)
{
startLogFilesMonitor
(
context
);
startDatabaseMonitor
(
context
);
}
public
static
void
stopMonitors
(
Context
context
)
{
stopLogFilesMonitor
(
context
);
stopDatabaseMonitor
(
context
);
}
// 每隔一定时间检查日志文件夹并进行清理
p
ublic
static
void
startLogFilesMonitor
(
Context
context
)
{
p
rivate
static
void
startLogFilesMonitor
(
Context
context
)
{
stopLogFilesMonitor
(
context
);
PeriodicWorkRequest
request
=
new
PeriodicWorkRequest
.
Builder
(
LogFileMonitor
.
class
,
LOG_REPEAT_INTERVAL
,
TimeUnit
.
HOURS
)
.
addTag
(
LOG_MONITOR_WORKER
)
...
...
@@ -27,13 +37,13 @@ public class MonitorUtils {
.
enqueue
(
request
);
}
p
ublic
static
void
stopLogFilesMonitor
(
Context
context
)
{
p
rivate
static
void
stopLogFilesMonitor
(
Context
context
)
{
WorkManager
.
getInstance
(
context
)
.
cancelAllWorkByTag
(
LOG_MONITOR_WORKER
);
}
// 每隔一定时间检查数据库并进行清理
p
ublic
static
void
startDatabaseMonitor
(
Context
context
)
{
p
rivate
static
void
startDatabaseMonitor
(
Context
context
)
{
stopDatabaseMonitor
(
context
);
PeriodicWorkRequest
request
=
new
PeriodicWorkRequest
.
Builder
(
DatabaseMonitor
.
class
,
DATABASE_REPEAT_INTERVAL
,
TimeUnit
.
HOURS
)
.
addTag
(
DATABASE_MONITOR_WORKER
)
...
...
@@ -42,7 +52,7 @@ public class MonitorUtils {
.
enqueue
(
request
);
}
p
ublic
static
void
stopDatabaseMonitor
(
Context
context
)
{
p
rivate
static
void
stopDatabaseMonitor
(
Context
context
)
{
WorkManager
.
getInstance
(
context
)
.
cancelAllWorkByTag
(
DATABASE_MONITOR_WORKER
);
}
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
View file @
a4c8df6f
...
...
@@ -18,7 +18,6 @@ import com.bgycc.smartcanteen.utils.SmartCanteenUtils;
import
com.blankj.utilcode.util.LogUtils
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.google.gson.JsonSyntaxException
;
import
java.util.concurrent.ScheduledFuture
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -99,8 +98,8 @@ public class QRCodeViewModel extends ViewModel {
JsonObject
jsonObject
;
try
{
jsonObject
=
JsonParser
.
parseString
(
scanData
).
getAsJsonObject
();
}
catch
(
JsonSyntaxException
js
e
)
{
LogUtils
.
e
(
TAG
,
"非法的指令格式: "
+
scanData
);
}
catch
(
Exception
e
)
{
LogUtils
.
e
(
TAG
,
"非法的指令格式: "
+
scanData
,
e
);
qrCodeState
.
postValue
(
new
QRCodeState
(
QRCodeState
.
FAILED
));
return
;
}
...
...
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