MuseHttp.kt 3.11 KB
Newer Older
1 2
package com.yidianling.home.http

3
import com.google.gson.Gson
4
import com.ydl.ydlcommon.data.http.BaseAPIResponse
范玉宾 committed
5 6
import com.ydl.ydlcommon.data.http.BaseResponse
import com.ydl.ydlcommon.data.http.RxUtils
7
import com.ydl.ydlnet.YDLHttpUtils
8
import com.yidianling.muse.bean.*
范玉宾 committed
9
import com.yidianling.muse.http.MusePagerApi
10
import io.reactivex.Observable
11 12
import okhttp3.MediaType
import okhttp3.RequestBody
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

/**
 * @author jiucheng
 * @描述:首页接口实现类
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/8/22
 */
class MuseHttp {

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

    object Holder {
        val INSTANCE = MuseHttp()
    }

    private var museApi: MusePagerApi? = null

    private fun getMusePagerApi(): MusePagerApi {
        if (museApi == null) {
            museApi = YDLHttpUtils.obtainApi(MusePagerApi::class.java)
        }
        return museApi!!
    }

    //壹点冥想
    fun newMuseRequest(): Observable<BaseAPIResponse<MuseModuleBean>> {
        return getMusePagerApi().getMuseData()
    }
范玉宾 committed
46 47 48 49 50 51 52

    fun getPureMusicPlayDetail(
        meditionType: Int,
        meditationId: Long
    ): Observable<BaseAPIResponse<MeditationPlayModuleBean>> {
        return getMusePagerApi().getPureMusicPlayDetail(
            meditionType = meditionType,
范玉宾 committed
53
            meditationId = meditationId
范玉宾 committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        )
    }

    fun getMeditationPlayDetail(
        meditionType: Int,
        mediaId: Long,
        meditationId: Long
    ): Observable<BaseAPIResponse<MeditationPlayModuleBean>> {
        return getMusePagerApi().getMeditationPlayDetail(
            meditionType = meditionType,
            mediaId = mediaId,
            meditationId = meditationId
        )
    }

范玉宾 committed
69 70 71 72 73 74 75 76 77 78 79 80
    fun collectMeditation(
        meditationId: Long,
        mediaId: Long,
        status: Int,
        businessType: Int
    ): Observable<BaseAPIResponse<CollectResultModule>> {
        val params = MeditationCollectRequestModule(
            meditationId = meditationId,
            mediaId = mediaId,
            status = status,
            businessType = businessType
        )
81 82 83 84 85 86
        var str = Gson().toJson(params)
        val body = RequestBody.create(
            MediaType.parse("application/json; charset=utf-8"),
            str
        ) as RequestBody
        return RxUtils.mapObservable(params).flatMap { getMusePagerApi().collectMeditation(body) }
范玉宾 committed
87 88
    }

范玉宾 committed
89 90 91 92 93 94 95 96 97 98
    fun postMeditationPlayRecord(
        meditationId: Int,
        isQuit: Int,
        mediaId: Long,
        playTime: Int, isComplete: Int
    ): Observable<BaseAPIResponse<MeditationPlayRecordResponseModule>> {
        val params = MeditationPlayRecordRequestModule(
            meditationId = meditationId,
            isQuit = isQuit, mediaId = mediaId, playTime = playTime, isComplete = isComplete
        )
99 100 101 102 103
        var str = Gson().toJson(params)
        val body = RequestBody.create(
            MediaType.parse("application/json; charset=utf-8"),
            str
        ) as RequestBody
范玉宾 committed
104 105
        return RxUtils.mapObservable(params)
            .flatMap { getMusePagerApi().meditationPlayRecord(body) }
106 107 108
    }


109
}