package cn.flightfeather.thirdapp.module.common
|
|
import android.arch.lifecycle.MutableLiveData
|
import cn.flightfeather.thirdapp.bean.entity.Userinfo
|
import cn.flightfeather.thirdapp.common.net.ResultCallBack
|
import cn.flightfeather.thirdapp.module.base.BaseViewModel
|
import cn.flightfeather.thirdapp.repository.UserInfoRepository
|
|
/**
|
* @author riku
|
* Date: 2021/7/21
|
*/
|
class UserInfoViewModel : BaseViewModel() {
|
|
private val userInfoRepository = UserInfoRepository.instance
|
|
// 用户账户
|
val aName = MutableLiveData<String>()
|
|
/**
|
* 自动创建或获取场景账户
|
*/
|
fun createAccount(sceneId: String) {
|
userInfoRepository.createAccount(sceneId, object : ResultCallBack<Userinfo> {
|
override fun onSuccess(result: Userinfo?) {
|
aName.value = result?.acountname
|
}
|
|
override fun onFailure() {
|
aName.value = null
|
}
|
})
|
}
|
|
fun getByScene(sceneId: String) {
|
userInfoRepository.getByScene(sceneId, object : ResultCallBack<Userinfo?> {
|
override fun onSuccess(result: Userinfo?) {
|
aName.value = result?.acountname
|
}
|
|
override fun onFailure() {
|
aName.value = null
|
}
|
})
|
}
|
}
|