ThankHeadView.kt 7.64 KB
Newer Older
konghaorui committed
1 2 3
package com.yidianling.dynamic.thank.view

import android.app.Activity
严久程 committed
4
import android.text.TextUtils
konghaorui committed
5 6 7 8
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_image.transform.GlideCircleTransform
严久程 committed
9
import com.ydl.ydl_router.manager.YDLRouterManager
konghaorui committed
10
import com.ydl.ydlcommon.base.BaseActivity
严久程 committed
11 12
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
konghaorui committed
13 14 15 16 17 18 19 20 21
import com.ydl.ydlcommon.view.RoundCornerButton
import com.yidianling.common.tools.LogUtil
import com.yidianling.common.tools.ToastUtil
import com.yidianling.dynamic.R
import com.yidianling.dynamic.common.net.DynamicApiUtils
import com.yidianling.dynamic.event.ThankReplyUpdateEvent
import com.yidianling.dynamic.model.Command
import com.yidianling.dynamic.router.DynamicIn
import com.yidianling.dynamic.thank.ShowIntroduceDialogFragment
严久程 committed
22
import com.yidianling.dynamic.thank.ThankActivity
konghaorui committed
23 24
import com.yidianling.dynamic.thank.WorryDetailAnswer
import com.yidianling.dynamic.thank.data.ThxData
严久程 committed
25
import com.yidianling.ydl_pay.CommonPayDialog
konghaorui committed
26 27 28
import de.greenrobot.event.EventBus
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
konghaorui committed
29
import kotlinx.android.synthetic.main.dynamic_ui_thank_head.view.*
konghaorui committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

/**
 * Created by softrice on 15/11/25.
 */
class ThankHeadView(activity: Activity) : LinearLayout(activity) {

    private val activity: BaseActivity
    open var rcb_msg_submit: RoundCornerButton? = null

    internal var thxData: ThxData? = null
    internal var worryDetailAnswer: WorryDetailAnswer? = null


    internal var answerId = 0

    internal var listNum = 0

    val selectId: Int
        get() = tsv_select!!.getSelectId()

    val content: String
        get() = et_msg!!.text.toString()

    fun setAnswerId(answerId: Int) {
        this.answerId = answerId
    }

    fun setlistNum(listNum: Int) {
        this.listNum = listNum
    }

    fun setWorryDetailAnswer(worryDetailAnswer: WorryDetailAnswer) {
        this.worryDetailAnswer = worryDetailAnswer
    }


    init {
konghaorui committed
67
        View.inflate(activity, R.layout.dynamic_ui_thank_head, this)
konghaorui committed
68 69 70 71 72 73 74
        this.activity = activity as BaseActivity
    }

    fun setData(thxData: ThxData) {
        this.thxData = thxData
        tsv_select!!.setData(thxData.star_money)
        LogUtil.d("thank userInfo head: " + thxData.userInfo.head)
严久程 committed
75
        GlideApp.with(activity)
konghaorui committed
76
            .load(thxData.userInfo.head)
严久程 committed
77
            .transform(GlideCircleTransform(activity))
konghaorui committed
78 79
            .placeholder(R.drawable.dynamic_head_place_hold_pic)
            .error(R.drawable.dynamic_head_place_hold_pic)
konghaorui committed
80 81
            .into(sdv_head!!)

严久程 committed
82 83 84 85 86 87 88 89 90
        rcb_submit.setOnClickListener {
            if (answerId == 0)
                return@setOnClickListener
            if (thxData == null || thxData!!.userInfo == null || thxData!!.userInfo.uid == null)
                return@setOnClickListener
            if (thxData!!.userInfo.uid == DynamicIn.getUserInfo()!!.uid) {
                ToastUtil.toastShort("不能给自己点赞")
                return@setOnClickListener
            }
konghaorui committed
91 92 93 94
            submitWithMoney()
        }
    }

严久程 committed
95 96 97 98 99 100 101 102 103 104
//    @OnClick(R2.id.rcb_submit, R2.id.rcb_msg_submit)
//    internal fun click(view: View) {
//
//        if (view.id == R.id.rcb_submit) {
//            submitWithMoney()
//        } else if (view.id == R.id.rcb_msg_submit) {
//            submitWithoutMoney()
//        }
//    }

konghaorui committed
105 106 107 108 109 110 111 112 113 114 115 116 117
    internal fun submitWithMoney() {
        var starNum = 0
        if (selectId == -1) {
            ToastUtil.toastShort("请选择你的心意")
            return
        } else {
            starNum = thxData!!.star_money[selectId].star_num
        }
        activity.showProgressDialog(null)
        val cmd = Command.SubmitZan(
            Integer.parseInt(thxData!!.userInfo.uid),
            starNum, content, answerId, 1
        )
严久程 committed
118
        val disposable = DynamicApiUtils.submitZan(cmd)
konghaorui committed
119 120 121 122 123 124 125 126 127 128 129 130
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ resp ->
                activity.dismissProgressDialog()
                if (resp.code == 0) {
                    val sendThxWithMoney = resp.data
//                    val payParams = PayParams()
//                    payParams.setTitle("送感谢")
//                    payParams.setPayId(sendThxWithMoney.payId)
//                    payParams.setNeedPay(sendThxWithMoney.money)
//                    YdlCommonOut.startPayActivity(context as Activity, payParams, 0)

严久程 committed
131
                    toPay(sendThxWithMoney.payId, sendThxWithMoney.money)
konghaorui committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
                } else {
                    ToastUtil.toastShort(resp.msg)
                }
            }, { throwable ->
                DynamicApiUtils.handleError(context, throwable)
                activity.dismissProgressDialog()
            })
    }

    internal fun submitWithoutMoney() {
        val starNum = 0
        activity.showProgressDialog(null)
        val cmd = Command.SubmitZan(
            Integer.parseInt(thxData!!.userInfo.uid),
            starNum, content, answerId, 2
        )
        val disposable = DynamicApiUtils.submitZan(cmd)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ resp ->
                activity.dismissProgressDialog()
                if (resp.code == 0) {
                    if (worryDetailAnswer != null) {
                        val showIntroduceDialogFragment = ShowIntroduceDialogFragment()
                            .setPamrams(
                                worryDetailAnswer!!.pDoctorId.toString(),
                                worryDetailAnswer!!.pUid.toString(),
                                worryDetailAnswer!!.listener_id.toString(),
                                worryDetailAnswer!!.pName,
                                worryDetailAnswer!!.pHead,
                                ""
                            )
                        showIntroduceDialogFragment.show(
                            (context as Activity).fragmentManager,
                            showIntroduceDialogFragment.javaClass.name
                        )
konghaorui committed
168
                        ToastUtil.toastImg(context, R.drawable.dynamic_dialog_send_thx_success)
konghaorui committed
169 170
                        EventBus.getDefault().post(ThankReplyUpdateEvent())
                    } else {
konghaorui committed
171
                        ToastUtil.toastImg(context, R.drawable.dynamic_dialog_send_thx_success)
konghaorui committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
                        EventBus.getDefault().post(ThankReplyUpdateEvent())
                        //通知更新
                    }
                } else {
                    ToastUtil.toastShort(resp.msg)
                }
            }, { throwable ->
                DynamicApiUtils.handleError(context, throwable)
                activity.dismissProgressDialog()
            })

    }


    fun toPay(payId: String, money: Float) {
严久程 committed
187 188 189 190 191
        val userInfo = DynamicIn.getUserInfo()
        if (userInfo == null || TextUtils.isEmpty(userInfo.uid)) {
            YDLRouterManager.router(IYDLRouterConstant.ROUTER_MINE_LOGIN)
            return
        }
konghaorui committed
192
//
严久程 committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
        val build = CommonPayDialog.Build(activity)
            .setPayId(payId)
            .setPayMoney(money)
            .setToken(userInfo.accessToken!!)
            .setUid(userInfo.uid)
            .setFfrom(PlatformDataManager.getRam().getChannelName())
            .setListener(object : CommonPayDialog.OnPayResultListener {
                override fun onSuccesed() {
                    //刷新界面

                    (activity as ThankActivity).getData(false)
                }

                override fun onFailed() {

                }
            })
            .setIsTestEnvironment(false)
        build.build().show()
konghaorui committed
212 213 214
    }

}