package cn.flightfeather.thirdappmodule.module.common
|
|
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
|
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
|
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
|
import cn.flightfeather.thirdappmodule.repository.SearchRepository
|
import cn.flightfeather.thirdappmodule.view.recyclerview.DataLoadModel
|
|
/**
|
* @author riku
|
* Date: 2022/2/17
|
* 查询界面viewModel
|
*/
|
class SearchViewModel : BaseViewModel() {
|
private val searchRepository = SearchRepository()
|
|
// 搜索子任务
|
var keyword = ""// 搜索关键字
|
val subtaskResult = object : DataLoadModel<Subtask>(application) {
|
override fun loadDataByRefresh() {
|
searchSubtask(keyword, 1, this)
|
}
|
|
override fun loadDataByLoadMore(page: Int) {
|
searchSubtask(keyword, page, this)
|
}
|
}
|
|
/**
|
* 根据关键字搜索子任务
|
* @param keyword 关键词
|
* @param page 分页数
|
* @param callBack 结果回调函数
|
*/
|
fun searchSubtask(keyword: String, page: Int, callBack: ResultCallBack<List<Subtask>>) {
|
if (keyword.isEmpty()) {
|
callBack.onSuccess(emptyList())
|
} else {
|
searchRepository.searchSubtask(application.currentUser.guid, keyword, page, callBack)
|
}
|
}
|
}
|