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
043dd808
authored
Jun 02, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、优化debug模式下服务器地址等信息的显示逻辑
2、现在重新进入app会将所有未完成的指令设置为已完成
parent
bf416e36
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
30 deletions
+56
-30
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+33
-26
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
No files found.
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
043dd808
...
...
@@ -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
->
{
...
...
@@ -469,11 +445,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 @
043dd808
...
...
@@ -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 @
043dd808
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 @
043dd808
...
...
@@ -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
;
...
...
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