package com.example.firstapp.ui.home
|
|
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.ViewModel
|
import com.example.firstapp.core.Core
|
import com.example.firstapp.database.entity.Code
|
|
class HomeViewModel : ViewModel() {
|
|
private val _text = MutableLiveData<String>().apply {
|
value = "短信主页面"
|
}
|
val text: LiveData<String> = _text
|
|
private val _codeList = MutableLiveData<List<Code>>()
|
|
val codeList: LiveData<List<Code>> get() = _codeList
|
|
init {
|
// 初始化时加载数据
|
loadData()
|
}
|
|
// 加载数据的方法
|
fun loadData() {
|
// 获取数据,并更新 LiveData
|
_codeList.value = Core.code.getAllDesc() // 假设这是获取最新的 data 的方法
|
}
|
|
// 如果需要手动更新数据,可以调用这个方法
|
fun updateData() {
|
_codeList.value = Core.code.getAllDesc() // 重新获取并更新数据
|
}
|
|
}
|