package com.quansu.heifengwuliu.vmodel

import com.quansu.heifengwuliu.model.Todo
import com.quansu.heifengwuliu.utils.net.NetEngine
import com.ysnows.base.base.BRRepository
import com.ysnows.base.base.BRViewModel

class TodoListVModel : BRViewModel<BRRepository>() {
    fun check(item: Todo, position: Int) {
        repository()
                .lreq(NetEngine.service.taskChecked(item.id))
                .doOnNext {
                    if (it.ok(true)) {
                        item.checked = if (item.checked == 1) 0 else 1
                        view()?.adapter()?.notifyItemChanged(position)
                    }
                }
                .subscribe()
    }
}