ConfideHomeGoodPopupWindow.kt 3.04 KB
Newer Older
洪国微 committed
1 2 3 4 5 6 7 8 9 10 11 12 13
package com.ydl.confide.home.popwindow

import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.PopupWindow
import com.ydl.confide.R
import com.ydl.confide.home.bean.ConfideHomeFiterItemBean
import com.ydl.confide.home.popwindow.adapter.ConfideHomeGoodAdapter
import com.ydl.ydlcommon.view.SpaceItemDecorator
14 15
import com.yidianling.common.tools.RxImageTool
import kotlinx.android.synthetic.main.confide_good_popup_window.view.*
洪国微 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34



/**
 * @author yuanwai
 * @描述:倾诉首页--擅长方向popWindow
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/9/22
 */
class ConfideHomeGoodPopupWindow(context: Context, goodsList: ArrayList<ConfideHomeFiterItemBean>, selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>)
    : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) {
    var onGoodSelectedListener: OnGoodSelectedListener? = null
    //擅长方向列表数据
    private var goodsList: ArrayList<ConfideHomeFiterItemBean>? = null
    //已选择的擅长方向数据
    private var selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>? = null

    init {
35
        val view = LayoutInflater.from(context).inflate(R.layout.confide_good_popup_window, null)
洪国微 committed
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 67 68 69 70 71 72 73 74 75 76 77 78 79
        this.contentView = view
        this.isFocusable = true
        @Suppress("DEPRECATION")
        this.setBackgroundDrawable(BitmapDrawable())
        this.isOutsideTouchable = true
        val rvGood = view.rvGood
        val tvTitle = view.tv_title
        tvTitle.text = "擅长方向"
        if (null == this.goodsList){
            this.goodsList = ArrayList()
        }else{
            (this.goodsList as ArrayList).clear()
        }
        this.goodsList!!.addAll(goodsList)
        if (null == this.selectedGoodsList){
            this.selectedGoodsList = ArrayList()
        }else{
            (this.selectedGoodsList as ArrayList).clear()
        }
        this.selectedGoodsList!!.addAll(selectedGoodsList)
        var goodAdapter: ConfideHomeGoodAdapter? = null
        if (null == rvGood.adapter){
            goodAdapter = ConfideHomeGoodAdapter(context, this.goodsList!!, this.selectedGoodsList!!)
            rvGood.adapter = goodAdapter
            rvGood.layoutManager = GridLayoutManager(context, 3, LinearLayoutManager.VERTICAL, false)
            rvGood.addItemDecoration(SpaceItemDecorator(RxImageTool.dp2px(8f), 3))
        }
        inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
        view.btnConfirm.setOnClickListener {
            onGoodSelectedListener?.onGoodSelected(this.selectedGoodsList!!)
            dismiss()
        }
        view.btnReset.setOnClickListener {
            goodAdapter?.cleanSelectedGoods()
        }
        view.v_zhezhao.setOnClickListener {
            dismiss()
        }
    }

    interface OnGoodSelectedListener {
        fun onGoodSelected(selectedGoodsList: ArrayList<ConfideHomeFiterItemBean>)
    }
}