You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.1 KiB

package com.gyf.csams.activity.model
import android.app.Application
import androidx.lifecycle.viewModelScope
import com.google.gson.reflect.TypeToken
import com.gyf.csams.module.ActivityVo
import com.gyf.csams.module.ApiResponse
import com.gyf.csams.module.FindTendencyVo
import com.gyf.csams.module.TendencyType
import com.gyf.lib.model.ScrollViewModel
import com.gyf.lib.util.*
import kotlinx.coroutines.launch
class TendencyViewModel(application: Application) :
ScrollViewModel<ActivityVo>(application = application) {
fun load(type: TendencyType) {
viewModelScope.launch {
HttpClient.post(
url = Api.buildUrl(ActivityApi.FindTendency),
callback = HttpCallback<MutableList<ActivityVo>>(
action = "加载${type.desc}活动",
onSuccess = {
it.body?.apply { _data.postValue(this) }
},
typeToken = object : TypeToken<ApiResponse<MutableList<ActivityVo>>>() {}.type
),
jsonParam = FindTendencyVo(type = type, token = TokenManager.getToken())
)
}
}
}