package com.example.smart.ui.item.popup
|
|
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.viewModelScope
|
import com.example.basecore.base.BaseContextViewModel
|
import com.example.basecore.net.http.Result
|
import com.example.smart.reqeust.RetrofitClient
|
import com.example.smart.ui.item.popup.data.DynamicBean
|
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.launch
|
|
|
class DynamicPopupViewModel : BaseContextViewModel() {
|
|
val optionsBean = MutableLiveData<String>()
|
|
val bean = MutableLiveData<DynamicBean>()
|
|
fun requestProjectInfo(projectId: Int) {
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
execute(RetrofitClient.api.requestProjectInfo(projectId))
|
}.apply {
|
if (this is Result.Success) {
|
bean.value = data
|
}
|
// 找得到信息就用,找不到就创建新的
|
// else if (this is Result.Error) {
|
// MyApp.app.toast(exception.message ?: "未知错误")
|
// }
|
}
|
}
|
}
|
|
|
fun addProjectInfo(bean: DynamicBean, fail:(String) -> Unit) {
|
viewModelScope.launch(Dispatchers.Main) {
|
safeCall {
|
// if (bean.isEdit) {
|
// callNoResult(RetrofitClient.api.editProjectInfo(bean))
|
// } else {
|
callNoResult(RetrofitClient.api.addProjectInfo(bean))
|
// }
|
}.apply {
|
if (this is Result.SuccessNone) {
|
optionsBean.value = status
|
} else if (this is Result.Error) {
|
fail(exception.message ?: "未知错误")
|
}
|
}
|
}
|
}
|
}
|