1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
            }
        })
    }
}