package com.bc_chat.bc_base.presenter

import com.bc_chat.bc_base.contract.WebContract
import com.bc_chat.bc_base.task.WebPageTask
import com.zhaohaoting.framework.abs.presenter.BasePresenter
import com.zhaohaoting.framework.requset.NetWorkCallBack
import java.lang.Exception

/**
 * author：Created by zhaohaoting on 2019/3/22
 * email：526309416@qq.com
 * desc：
 */
open class WebPresenter<VIEW : WebContract.View> constructor(view: VIEW) : BasePresenter<VIEW>(view), WebContract.Presenter {

    override fun loadWebPage(type: Int) {
        taskHelper.execute<Any>(WebPageTask(type), object : NetWorkCallBack<String>() {
            override fun onPreExecute(task: Any?) {
                super.onPreExecute(task)
                view.showLoading(task)
            }

            override fun onPostExecuteFailure(task: Any?, exception: Exception?) {
                super.onPostExecuteFailure(task, exception)
                view.dismissLoading(task)
            }

            override fun onPostExecuteSuccess(task: Any?, data: String?) {
                view.dismissLoading(task)
                view.loadWebPageSuccess(data!!)
            }
        })
    }
}
