Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
SuZhouAvp
Commits
816a069a
Commit
816a069a
authored
Jun 10, 2025
by
p x
Browse files
添加websocket
parent
1ccbc004
Changes
30
Expand all
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/sd/cavphmi/viewmodels/MainVm.kt
0 → 100644
View file @
816a069a
package
com.sd.cavphmi.viewmodels
import
android.content.Context
import
androidx.lifecycle.viewModelScope
import
com.sd.cavphmi.base.MyBaseViewModel
import
com.sd.cavphmi.bean.SpaceNoBean
import
com.sd.cavphmi.bean.VToXImgBean
import
com.sd.cavphmi.net.MyResult
import
com.sd.cavphmi.repositorys.SpaceNoRepo
import
com.sd.cavphmi.utils.MyContants
import
com.sd.cavphmi.utils.ToastHelper
import
com.sd.cavphmi.websockets.MyWebSocketClient
import
dagger.hilt.android.lifecycle.HiltViewModel
import
dagger.hilt.android.qualifiers.ApplicationContext
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
org.java_websocket.client.WebSocketClient
import
java.net.URI
import
javax.inject.Inject
@HiltViewModel
class
MainVm
@Inject
constructor
(
@ApplicationContext
var
context
:
Context
,
var
spaceNoRepo
:
SpaceNoRepo
)
:
MyBaseViewModel
()
{
private
var
client
:
MyWebSocketClient
?
=
null
fun
startWS
()
{
val
httpHeaders
=
mutableMapOf
<
String
,
String
>()
httpHeaders
.
put
(
"Cookie"
,
"username=nemo"
)
client
=
MyWebSocketClient
(
URI
(
MyContants
.
WS_HOST
))
client
?.
connect
()
}
fun
closeWS
()
{
if
(
client
?.
isOpen
?:
false
)
{
client
?.
close
()
}
}
fun
showVToTip
()
{
var
imgs
=
VToXImgBean
.
imgs
ToastHelper
.
showCustViewShort
(
context
,
imgs
.
get
(
"2"
)
!!
)
}
fun
getSpaceData
()
{
viewModelScope
.
launch
{
var
result
=
spaceNoRepo
.
getSpaceData
()
when
(
result
)
{
is
MyResult
.
Success
<
SpaceNoBean
>
->
{
var
a
=
0
}
else
->
{
var
b
=
0
}
}
}
}
}
\ No newline at end of file
app/src/main/java/com/sd/cavphmi/websockets/MyWebSocketClient.kt
0 → 100644
View file @
816a069a
This diff is collapsed.
Click to expand it.
app/src/main/res/drawable-xhdpi/abnormal.png
0 → 100644
View file @
816a069a
6.66 KB
app/src/main/res/drawable-xhdpi/admission.png
0 → 100644
View file @
816a069a
6.97 KB
app/src/main/res/drawable-xhdpi/advance.png
0 → 100644
View file @
816a069a
6.6 KB
app/src/main/res/drawable-xhdpi/change_lanes.png
0 → 100644
View file @
816a069a
6.63 KB
app/src/main/res/drawable-xhdpi/intersection.png
0 → 100644
View file @
816a069a
7.46 KB
app/src/main/res/drawable-xhdpi/weak.png
0 → 100644
View file @
816a069a
9.1 KB
app/src/main/res/layout/activity_main.xml
View file @
816a069a
This diff is collapsed.
Click to expand it.
app/src/main/res/layout/toast_tip.xml
0 → 100644
View file @
816a069a
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
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