HomeAssuageGriefItemView.kt 6.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
package com.yidianling.home.ui.view

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.text.*
import android.text.style.ForegroundColorSpan
import android.text.style.ImageSpan
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.ydl.ydl_image.manager.YDLImageCacheManager
import com.ydl.ydl_router.manager.YDLRouterManager
import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.router.IYDLRouterConstant
import com.ydl.ydlcommon.utils.MoonUtil
import com.ydl.ydlcommon.utils.Utils
import com.yidianling.common.tools.RxDeviceTool
import com.yidianling.common.tools.RxImageTool
import com.yidianling.home.R
import com.yidianling.home.event.IHomeBaseEvent
import com.yidianling.home.model.bean.HomeAskBean
import com.yidianling.user.api.service.IUserService
konghaorui committed
25
import kotlinx.android.synthetic.xlzx.home_assuage_grief_item_view.view.*
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47


/**
 * @author <a href="https://www.jianshu.com/u/c1e5310dd724">xujian</a>
 * @描述: 解忧*问答模块item
 * @Copyright Copyright (c) 2019
 * @Company 壹点灵
 * @date 2019/02/15
 */
class HomeAssuageGriefItemView(
    private val mContext: Context,
    private var homeEvent: IHomeBaseEvent?
) : LinearLayout(mContext) {

    private var homeAssuageGriefImageItemView: HomeAssuageGriefImageItemView? = null
    private var focusClick: Boolean = false;

    init {
        initView()
    }

    private fun initView() {
ydl committed
48
        val params = LayoutParams(
49 50 51 52
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
        )
        layoutParams = params
konghaorui committed
53
        View.inflate(mContext, R.layout.home_assuage_grief_item_view, this)
54 55 56 57


    }

ydl committed
58
    fun updateData(bean: HomeAskBean.DataBean, position: Int, index: Int, isBottomItem: Boolean) {
59 60 61 62 63 64 65 66 67 68 69
        this.setOnClickListener {
            homeEvent?.askItemClick(bean)
        }
        MoonUtil.identifyFaceExpression(
            mContext, homeModuleAssuageGriefViewContent,
            bean?.content, ImageSpan.ALIGN_BOTTOM
        )
        homeModuleAssuageGriefViewTag.text = bean?.askTag
        homeModuleAssuageGriefViewCommentsCount.text = bean?.commentsCount.toString()
        homeModuleAssuageGriefViewZanCount.text = bean?.zanCount.toString()

ydl committed
70 71 72 73 74 75 76 77 78 79 80
        if (isBottomItem) {
            homeModuleAssuageGriefViewBottomLine.visibility = View.GONE
            homeModuleAssuageGriefViewBottomBtn.visibility = View.VISIBLE
            homeModuleAssuageGriefViewBottomBtn.setOnClickListener {
                homeEvent?.askMoreClick()
            }
        } else {
            homeModuleAssuageGriefViewBottomLine.visibility = View.VISIBLE
            homeModuleAssuageGriefViewBottomBtn.visibility = View.GONE
        }

81 82 83 84 85 86 87 88 89 90 91 92 93

        /**
         * 点赞
         */
        ll_zan.setOnClickListener {
            if (!Utils.isFastClick()) {
                if (!ModularServiceManager.provide(IUserService::class.java).isLogin()) {
                    //跳转登录
                    YDLRouterManager.router(IYDLRouterConstant.ROUTER_MINE_LOGIN)
                    return@setOnClickListener
                }
                bean.isZan = if (bean.isZan == 1) 0 else 1
                if (bean.isZan == 1) {
konghaorui committed
94
                    homeModuleAssuageGriefViewZanState.setImageResource(R.drawable.home_assuage_grief_item_view_tab_warm_has_zan)
95
                } else {
konghaorui committed
96
                    homeModuleAssuageGriefViewZanState.setImageResource(R.drawable.home_assuage_grief_item_view_tab_warm)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                }
                bean.zanCount = if (bean.isZan == 1) bean.zanCount + 1 else bean.zanCount - 1
                homeModuleAssuageGriefViewZanCount.text = bean?.zanCount.toString()

                //防止连击
                homeEvent?.askItemZanClick(position, index, bean.id.toString())
            }
        }

        /**
         * 标题
         */
        if (!TextUtils.isEmpty(bean?.title)) {
            homeModuleAssuageGriefViewTitle.visibility = View.VISIBLE
            homeModuleAssuageGriefViewTitle.text = bean?.title
        }

        /**
         * 点赞
         */
        if (bean?.isZan == 1) {
konghaorui committed
118
            homeModuleAssuageGriefViewZanState.setImageResource(R.drawable.home_assuage_grief_item_view_tab_warm_has_zan)
119
        } else {
konghaorui committed
120
            homeModuleAssuageGriefViewZanState.setImageResource(R.drawable.home_assuage_grief_item_view_tab_warm)
121 122 123 124 125 126 127
        }

        /**
         * 图片
         */
        if (null != bean?.smallAttach && bean?.smallAttach!!.isNotEmpty()) {
            if (homeAssuageGriefImageItemView != null) {
ydl committed
128 129
                homeModuleAssuageGriefItemImageItemLL.removeAllViews()
                homeModuleAssuageGriefItemImageItemLL.visibility = View.GONE
130 131 132 133 134 135
            }
            homeAssuageGriefImageItemView = HomeAssuageGriefImageItemView(
                mContext,
                bean?.smallAttach as List<String>,
                homeEvent
            )
ydl committed
136 137
            homeModuleAssuageGriefItemImageItemLL.addView(homeAssuageGriefImageItemView)
            homeModuleAssuageGriefItemImageItemLL.visibility = View.VISIBLE
138 139
        } else {
            if (null != homeAssuageGriefImageItemView) {
ydl committed
140 141
                homeModuleAssuageGriefItemImageItemLL.removeAllViews()
                homeModuleAssuageGriefItemImageItemLL.visibility = View.GONE
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
            }
        }

        /**
         * 评论
         */
        initComment(bean)

    }

    private fun initComment(bean: HomeAskBean.DataBean) {
        if (bean?.commentsCount > 0) {
            homeModuleAssuageGriefViewComment.visibility = View.VISIBLE

            var index: Int = 0
            var commentBean = bean?.comments!![0]

ydl committed
159 160
            YDLImageCacheManager.showImage(mContext, commentBean.userHead, homeModuleAssuageGriefViewHotViewHeader)

161
            if (null != commentBean.name && commentBean.name!!.isNotEmpty())
ydl committed
162
                homeModuleAssuageGriefViewHotViewComment.text = commentBean.name?:""
163 164 165

            // userType为2 ,专家
            if (commentBean.userType == 2) {
ydl committed
166 167 168
                homeModuleAssuageGriefViewHotViewVip.visibility = View.VISIBLE
            } else {
                homeModuleAssuageGriefViewHotViewVip.visibility = View.GONE
169 170
            }

ydl committed
171
            homeModuleAssuageGriefViewHotViewCommentContent.text = commentBean.content?:""
172

ydl committed
173 174
        } else {
            homeModuleAssuageGriefViewComment.visibility = View.GONE
175 176 177
        }
    }
}