CoursePosterTemplate.kt 3.37 KB
Newer Older
严久程 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package com.yidianling.course.widget

import android.annotation.SuppressLint
import android.app.Activity
import android.graphics.Paint
import android.support.v7.widget.CardView
import android.text.TextUtils
import android.util.Base64
import android.view.View
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.ydl.ydl_image.module.GlideApp
import com.ydl.ydl_image.transform.GlideRoundTopTransform
import com.yidianling.course.R
import com.yidianling.course.bean.PostersShareBean
16
import kotlinx.android.synthetic.main.course_view_course_poster_template.view.*
严久程 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
import java.util.concurrent.Executors


/**
 * @author jiucheng
 * @描述:课程海报模板
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2019/8/6
 */
@SuppressLint("ViewConstructor")
class CoursePosterTemplate(var mContext: Activity) : CardView(mContext) {

    init {
        initView()
    }

    /**
     * 界面初始化
     */
    private fun initView() {
//        radius = RxImageTool.dp2px(10f).toFloat()
39
        View.inflate(context, R.layout.course_view_course_poster_template, this)
严久程 committed
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    }

    @SuppressLint("SetTextI18n")
    fun setData(bean: PostersShareBean, isDefault: Boolean) {
        setType(isDefault)
        val myOptions = RequestOptions()
                .transform(GlideRoundTopTransform(mContext, 10))

        GlideApp.with(mContext)
                .load(bean.pic)
                .apply(myOptions)
                .disallowHardwareConfig()
                .into(iv_pic)
        tv_title.text = bean.title
        tv_intro.text = bean.desc
        tv_price.text = bean.applyFee
        if (TextUtils.equals("1", bean.isPromotion) || TextUtils.equals("3", bean.isPromotion)) {
            tv_price.text = bean.promotionApplyFee
        }
        tv_original_price.text = "原价" + bean.originalApplyFee
        tv_original_price.paint.flags = Paint.STRIKE_THRU_TEXT_FLAG

        tv_course_num.text = bean.subCourseNum
        tv_view_count.text = bean.readNums

        if (bean.shareUser != null) {
            if (!TextUtils.isEmpty(bean.shareUser!!.nickName)) {
                tv_user_name.text = bean.shareUser!!.nickName
            }
            if (!TextUtils.isEmpty(bean.shareUser!!.head)) {
                GlideApp.with(mContext)
                        .load(bean.shareUser!!.head)
                        .disallowHardwareConfig()
                        .into(iv_head)
            }
        }

        if (!TextUtils.isEmpty(bean.qrCodeByte)) {
            if (bean.qrCodeByte.contains(",")) {
                bean.qrCodeByte = bean.qrCodeByte.split(",")[1]
            }
            Executors.newCachedThreadPool().execute {
                var imageByte = Base64.decode(bean.qrCodeByte, Base64.DEFAULT)
                mContext!!.runOnUiThread {
                    GlideApp.with(this)
                            .load(imageByte)
                            .diskCacheStrategy(DiskCacheStrategy.NONE)
                            .disallowHardwareConfig()
                            .into(iv_qrc_code)
                }
            }
        }
    }

    private fun setType(isDefault: Boolean) {
95
        root_layout.setBackgroundResource(if (isDefault) R.drawable.course_poster_one else R.drawable.course_poster_two)
严久程 committed
96 97 98 99 100
        view_line.isEnabled = isDefault
        iv_poster_one.isEnabled = isDefault
        iv_poster_two.isEnabled = isDefault
    }
}