|
|
@@ -1,39 +1,7 @@
|
|
|
package com.nova.brain.glass.viewmodel
|
|
|
|
|
|
-import androidx.lifecycle.MutableLiveData
|
|
|
-import com.nova.brain.glass.repository.Service
|
|
|
-import com.xuqm.base.App
|
|
|
-import com.xuqm.base.di.manager.HttpManager
|
|
|
import com.xuqm.sdhbwfu.core.viewModel.BaseViewModel
|
|
|
-import io.reactivex.schedulers.Schedulers
|
|
|
-import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
|
|
-import okhttp3.RequestBody
|
|
|
|
|
|
class WelcomeVM : BaseViewModel() {
|
|
|
|
|
|
- val result = MutableLiveData<String>()
|
|
|
- fun demoGet() {
|
|
|
- result.value = "GET 请求中..."
|
|
|
- HttpManager.getApi(Service::class.java).demoGet()
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .subscribe({ body ->
|
|
|
- result.postValue("GET 响应:\n${body.string()}")
|
|
|
- }, { e ->
|
|
|
- result.postValue("GET 失败: ${e.message}")
|
|
|
- }).adds()
|
|
|
- }
|
|
|
-
|
|
|
- fun demoPost() {
|
|
|
- result.value = "POST 请求中..."
|
|
|
- val json = """{"demo":"post","from":"glass"}"""
|
|
|
- val body = RequestBody.create("application/json".toMediaTypeOrNull(), json)
|
|
|
- HttpManager.getApi(Service::class.java).demoPost(body)
|
|
|
- .subscribeOn(Schedulers.io())
|
|
|
- .subscribe({ resp ->
|
|
|
- result.postValue("POST 响应:\n${resp.string()}")
|
|
|
- }, { e ->
|
|
|
- result.postValue("POST 失败: ${e.message}")
|
|
|
- }).adds()
|
|
|
- }
|
|
|
-
|
|
|
}
|