ConfideHomePresenterImpl.kt 3.11 KB
Newer Older
洪国微 committed
1 2 3 4 5
package com.ydl.confide.home.presenter

import com.ydl.confide.home.contract.IConfideHomeContract
import com.ydl.confide.home.http.ConfideRecommendParam
import com.ydl.confide.home.model.ConfideHomeModelImpl
洪国微 committed
6
import com.ydl.ydlcommon.data.http.RxUtils
洪国微 committed
7 8
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.ydl.ydlcommon.mvp.base.BasePresenter
9 10
import com.ydl.ydlcommon.mvp.base.IView
import com.yidianling.common.tools.RxNetTool
洪国微 committed
11 12 13 14 15 16 17 18 19 20
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer

/**
 * @author yuanwai
 * @描述:倾诉首页逻辑实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/8/10
 */
万齐军 committed
21 22
class ConfideHomePresenterImpl : BasePresenter<IConfideHomeContract.View, IConfideHomeContract.Model>(),
    IConfideHomeContract.Presenter {
洪国微 committed
23 24 25 26 27 28 29 30

    override fun createModel(): IConfideHomeContract.Model {
        return ConfideHomeModelImpl()
    }

    /**
     * 请求首页数据
     */
万齐军 committed
31 32
    override fun confideHomeRequest(isRefresh: Boolean) {
        if (!RxNetTool.isConnected(mView.getContext())) {
洪国微 committed
33 34 35 36
            mView.confideHomeRequestFail()
            return
        }
        val disposable = mModel.confideHomeRequest()
万齐军 committed
37 38 39 40 41 42 43 44 45 46 47
            .map { it }
            .filter { it != null }
            .compose(RxUtils.applySchedulers(mView as IView))
            .doFinally { mView.hideLoading() }
            .subscribe(Consumer {
                mView.confideHomeResponse(it)
            }, object : ThrowableConsumer() {
                override fun accept(msg: String) {
                    mView.confideHomeRequestFail()
                }
            })
洪国微 committed
48 49 50 51 52
    }

    /**
     * 为你推荐列表(筛选调用)
     */
万齐军 committed
53 54
    override fun recommendList(param: ConfideRecommendParam) {
        if (!RxNetTool.isConnected(mView.getContext())) {
洪国微 committed
55
            mView.showError1("网络不给力")
洪国微 committed
56 57 58
            return
        }
        val disposable = mModel.recommendList(param)
万齐军 committed
59 60 61 62 63 64 65 66 67 68 69
            .map { it }
            .filter { it != null }
            .compose(RxUtils.applySchedulers(mView as IView))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(Consumer {
                mView.recommendListResponse(it)
            }, object : ThrowableConsumer() {
                override fun accept(msg: String) {
                    mView.showError1(msg)
                }
            })
洪国微 committed
70 71 72 73 74 75
    }

    /**
     * 为你推荐列表(翻页时调用)
     */
    override fun recommendListMore(param: ConfideRecommendParam) {
万齐军 committed
76
        if (!RxNetTool.isConnected(mView.getContext())) {
洪国微 committed
77
            mView.showError1("网络不给力")
洪国微 committed
78 79 80
            return
        }
        val disposable = mModel.recommendList(param)
万齐军 committed
81 82 83 84 85 86 87 88 89 90 91 92
            .map { it }
            .filter { it != null }
            .compose(RxUtils.applySchedulers(mView as IView))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(Consumer {
                mView.recommendListMoreResponse(it)
            }, object : ThrowableConsumer() {
                override fun accept(msg: String) {
                    mView.showError(msg)
                    mView.showError1(msg)
                }
            })
洪国微 committed
93 94
    }
}