package com.example.jetpacksample

import android.os.Handler
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.mayi.fastdevelop.util.DateUtil
import java.lang.System.currentTimeMillis

class MainViewModel : ViewModel() {

    val liveData = MutableLiveData<DataBean>()
    val h = Handler()

    fun requestData(parameter: String) {
        h.postDelayed(Runnable {
            //模拟网络访问
            val data = DataBean()
            if (currentTimeMillis() % 2 == 0L) {
                data.ok = true
                val item = ItemDataBean()
                item.time = DateUtil.getCurrentTime()
                data.data = listOf(item)
            } else {
                data.ok = false
                data.msg = "请求失败"
            }
            liveData.setValue(data)
        }, 1000)
    }

}