ThankHeadView.kt 7.58 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 9
import android.view.View
import android.widget.LinearLayout
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_image.transform.GlideCircleTransform
import com.ydl.ydlcommon.base.BaseActivity
严久程 committed
10 11
import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
konghaorui committed
12 13 14 15 16 17 18 19 20
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
21
import com.yidianling.dynamic.thank.ThankActivity
konghaorui committed
22 23
import com.yidianling.dynamic.thank.WorryDetailAnswer
import com.yidianling.dynamic.thank.data.ThxData
24
import com.yidianling.ydl_pay.common.CommonPayDialog
konghaorui committed
25 26 27
import de.greenrobot.event.EventBus
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
konghaorui committed
28
import kotlinx.android.synthetic.main.dynamic_ui_thank_head.view.*
konghaorui committed
29 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

/**
 * 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
66
        View.inflate(activity, R.layout.dynamic_ui_thank_head, this)
konghaorui committed
67 68 69 70 71 72 73
        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
74
        GlideApp.with(activity)
konghaorui committed
75
            .load(thxData.userInfo.head)
严久程 committed
76
            .transform(GlideCircleTransform(activity))
konghaorui committed
77 78
            .placeholder(R.drawable.dynamic_head_place_hold_pic)
            .error(R.drawable.dynamic_head_place_hold_pic)
konghaorui committed
79 80
            .into(sdv_head!!)

严久程 committed
81 82 83 84 85 86 87 88 89
        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
90 91 92 93
            submitWithMoney()
        }
    }

严久程 committed
94 95 96 97 98 99 100 101 102 103
//    @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
104 105 106 107 108 109 110 111 112 113 114 115 116
    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
117
        val disposable = DynamicApiUtils.submitZan(cmd)
konghaorui committed
118 119 120 121 122 123 124 125 126 127 128 129
            .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
130
                    toPay(sendThxWithMoney.payId, sendThxWithMoney.money)
konghaorui committed
131 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
                } 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
167
                        ToastUtil.toastImg(context, R.drawable.dynamic_dialog_send_thx_success)
konghaorui committed
168 169
                        EventBus.getDefault().post(ThankReplyUpdateEvent())
                    } else {
konghaorui committed
170
                        ToastUtil.toastImg(context, R.drawable.dynamic_dialog_send_thx_success)
konghaorui committed
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
                        EventBus.getDefault().post(ThankReplyUpdateEvent())
                        //通知更新
                    }
                } else {
                    ToastUtil.toastShort(resp.msg)
                }
            }, { throwable ->
                DynamicApiUtils.handleError(context, throwable)
                activity.dismissProgressDialog()
            })

    }


    fun toPay(payId: String, money: Float) {
严久程 committed
186 187
        val userInfo = DynamicIn.getUserInfo()
        if (userInfo == null || TextUtils.isEmpty(userInfo.uid)) {
188
            DynamicIn.loginByOneKeyLogin(activity,true)
严久程 committed
189 190
            return
        }
konghaorui committed
191
//
严久程 committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        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
211 212 213
    }

}