|
@@ -2,6 +2,7 @@ package com.nova.brain.glass.viewmodel
|
|
|
|
|
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import com.nova.brain.glass.repository.Service
|
|
import com.nova.brain.glass.repository.Service
|
|
|
|
|
+import com.xuqm.base.App
|
|
|
import com.xuqm.base.di.manager.HttpManager
|
|
import com.xuqm.base.di.manager.HttpManager
|
|
|
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel
|
|
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel
|
|
|
import io.reactivex.schedulers.Schedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
@@ -11,23 +12,9 @@ import okhttp3.RequestBody
|
|
|
class WelcomeVM : BaseViewModel() {
|
|
class WelcomeVM : BaseViewModel() {
|
|
|
|
|
|
|
|
val result = MutableLiveData<String>()
|
|
val result = MutableLiveData<String>()
|
|
|
-
|
|
|
|
|
- companion object {
|
|
|
|
|
- // 修改为运行 server/app.py 的机器在局域网中的 IP
|
|
|
|
|
- const val DEMO_SERVER_URL = "http://192.168.27.248:8080/"
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val demoComponent by lazy {
|
|
|
|
|
- HttpManager.getAppComponent(DEMO_SERVER_URL)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private val service by lazy {
|
|
|
|
|
- HttpManager.getApi(demoComponent, Service::class.java)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
fun demoGet() {
|
|
fun demoGet() {
|
|
|
result.value = "GET 请求中..."
|
|
result.value = "GET 请求中..."
|
|
|
- service.demoGet()
|
|
|
|
|
|
|
+ HttpManager.getApi(Service::class.java).demoGet()
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.subscribe({ body ->
|
|
.subscribe({ body ->
|
|
|
result.postValue("GET 响应:\n${body.string()}")
|
|
result.postValue("GET 响应:\n${body.string()}")
|
|
@@ -40,7 +27,7 @@ class WelcomeVM : BaseViewModel() {
|
|
|
result.value = "POST 请求中..."
|
|
result.value = "POST 请求中..."
|
|
|
val json = """{"demo":"post","from":"glass"}"""
|
|
val json = """{"demo":"post","from":"glass"}"""
|
|
|
val body = RequestBody.create(MediaType.parse("application/json"), json)
|
|
val body = RequestBody.create(MediaType.parse("application/json"), json)
|
|
|
- service.demoPost(body)
|
|
|
|
|
|
|
+ HttpManager.getApi(Service::class.java).demoPost(body)
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.subscribe({ resp ->
|
|
.subscribe({ resp ->
|
|
|
result.postValue("POST 响应:\n${resp.string()}")
|
|
result.postValue("POST 响应:\n${resp.string()}")
|
|
@@ -51,7 +38,7 @@ class WelcomeVM : BaseViewModel() {
|
|
|
|
|
|
|
|
fun demoPostSse() {
|
|
fun demoPostSse() {
|
|
|
result.postValue("SSE 连接中...")
|
|
result.postValue("SSE 连接中...")
|
|
|
- service.demoStream(5)
|
|
|
|
|
|
|
+ HttpManager.getApi(Service::class.java).demoStream(5)
|
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
|
.subscribe({ body ->
|
|
.subscribe({ body ->
|
|
|
val sb = StringBuilder("SSE 流式响应:\n")
|
|
val sb = StringBuilder("SSE 流式响应:\n")
|