package com.bc_chat.contacts.view

import android.content.Context
import android.support.v4.view.ViewPager
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import com.bc_chat.circle.entity.Emoji
import com.bc_chat.contacts.R
import com.bc_chat.contacts.adapter.EmojiViewPagerAdapter
import com.zhaohaoting.framework.view.indicator.FixedIndicatorView
import com.zhaohaoting.framework.view.indicator.IndicatorViewPager

/**
 * author：Created by zhaohaoting on 2019/8/28
 * email：526309416@qq.com
 * desc：
 */
class EmojiPickerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : RelativeLayout(context, attrs, defStyleAttr) {

    private var emojiViewPagerAdapter: EmojiViewPagerAdapter? = null

    private var emojiClickListener: EmojiViewPagerAdapter.EmojiClickListener? = null

    init {
        val inflater = LayoutInflater.from(context)
        val inflate = inflater.inflate(R.layout.emoji_picker_view, this, true)
        val viewPager = inflate.findViewById<ViewPager>(R.id.view_pager)
        val indicator = inflate.findViewById<FixedIndicatorView>(R.id.indicator)
        val indicatorViewPager = IndicatorViewPager(indicator, viewPager)
        emojiViewPagerAdapter = EmojiViewPagerAdapter()
        indicatorViewPager.adapter = emojiViewPagerAdapter
        emojiViewPagerAdapter?.setEmojiClickListener(object : EmojiViewPagerAdapter.EmojiClickListener {
            override fun clickEmoji(emoji: Emoji?) {
                emojiClickListener?.clickEmoji(emoji)
            }

            override fun deleteEmoji() {
                emojiClickListener?.deleteEmoji()
            }
        })
    }

    fun setEmojiClickListener(emojiClickListener: EmojiViewPagerAdapter.EmojiClickListener) {
        this.emojiClickListener = emojiClickListener
    }
}
