HomeImageBannerView.kt 2.63 KB
Newer Older
ydl committed
1 2 3
package com.yidianling.home.ui.view

import android.content.Context
YKai committed
4
import androidx.recyclerview.widget.RecyclerView
ydl committed
5 6
import android.view.View
import android.view.ViewGroup
7
import android.widget.FrameLayout
ydl committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import android.widget.LinearLayout
import com.ydl.ydlcommon.utils.YdlBuryPointUtil
import com.ydl.ydlcommon.view.banner.GlideImageLoader
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.HomeHeaderBean
import com.yidianling.home.model.bean.HomePagerDataBean
import kotlinx.android.synthetic.xlzx.home_image_banner_view.view.*

class HomeImageBannerView(val mContext: Context, val homeEvent: IHomeBaseEvent) : LinearLayout(mContext) {

    init {
        initView()
    }

    fun initView() {
        val params = LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
28
            ViewGroup.LayoutParams.WRAP_CONTENT
ydl committed
29 30 31 32 33 34 35
        ) as MarginLayoutParams

        params.topMargin = RxImageTool.dp2px(12f)

        layoutParams = params
        View.inflate(mContext, R.layout.home_image_banner_view, this)

36
        initBannerLayout()
ydl committed
37

38 39 40 41 42 43 44 45 46
    }

    private fun initBannerLayout() {
        val bannerWidth = RxDeviceTool.getScreenWidth(mContext) - RxImageTool.dp2px(16f) * 2
        val bannerLayoutParams = FrameLayout.LayoutParams(
            bannerWidth,
            (bannerWidth * 131 / 343)
        )
        banner_search.layoutParams = bannerLayoutParams
ydl committed
47

ydl committed
48
//        banner_search.setIndicatorBottomPadding(5)
ydl committed
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
    }

    fun initData(bean: HomePagerDataBean) {
        var headerBean = bean.headerBean
        var focusListBean = headerBean?.focusList
        //临时缓存集合
        val cacheList = ArrayList<HomeHeaderBean.FocusListBean>()
        if (null != focusListBean && focusListBean.isNotEmpty()) {
            var imageViews = ArrayList<String>()
            //产品说取前8个
            if (focusListBean.size > 8) {
                cacheList.addAll(focusListBean.subList(0, 8))
            } else {
                cacheList.addAll(focusListBean)
            }
            for (item in cacheList) {
                imageViews.add(item.imageUrl!!)
            }
            banner_search.setImageLoader(GlideImageLoader(R.drawable.home_image_default_back))
                .setImages(imageViews).start()
            banner_search.setOnBannerListener {
                homeEvent?.bannerClick(cacheList!![it])
                YdlBuryPointUtil.sendClick(
                    "ydl-xinlizixun-home-banner$it",
                    "${cacheList[it].imageUrl}"
                )
            }
        }
    }

}