TestHomeHttpImpl.kt 1.55 KB
Newer Older
konghaorui committed
1 2
package com.yidianling.tests.home.http

konghaorui committed
3 4 5
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
import com.ydl.ydlnet.YDLHttpUtils
konghaorui committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
import com.yidianling.tests.home.bean.TestHomeDataBean
import com.yidianling.tests.home.param.TestHomeParam
import io.reactivex.Observable

/**
 * @author yuanwai
 * @描述:
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/7/26
 */
class TestHomeHttpImpl private constructor() : ITestHomeHttp {

    companion object {
        fun getInstance(): TestHomeHttpImpl {
            return Holder.INSTANCE
        }

        fun clearTestHomeApi() {
            Holder.INSTANCE.testHomeApi = null
        }
    }

    object Holder {
        val INSTANCE = TestHomeHttpImpl()
    }

    private var testHomeApi: TestHomeApi? = null

    private fun getTestHomeApi(): TestHomeApi {
        if (testHomeApi == null){
konghaorui committed
37
            testHomeApi=YDLHttpUtils.obtainApi(TestHomeApi::class.java)
konghaorui committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        }
        return  testHomeApi!!
    }

    override fun newHomeRequest(testHomeParam: TestHomeParam): Observable<BaseResponse<List<TestHomeDataBean>>> {
        return RxUtils.mapObservable(testHomeParam)
                .flatMap {
                    getTestHomeApi().newHome(it)
                }
    }

    override fun dailyChange(testHomeParam: TestHomeParam): Observable<BaseResponse<TestHomeDataBean>> {
        return RxUtils.mapObservable(testHomeParam)
                .flatMap {
                    getTestHomeApi().dailySelection(it)
                }
    }

    fun fetchMaxCoupon(){

    }


}