package com.zxbw.modulemain.view

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.RelativeLayout
import android.widget.TextView
import com.zxbw.modulemain.R

/**
 * Created by gaoleichao on 2018/12/28
 */
class NavigationBottomView : RelativeLayout {
    constructor(context: Context?) : super(context) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
        init()
    }

    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        init()
    }

    private var mUserText: TextView? = null
    private var mShopText: TextView? = null
    private var navifationCallback: NavifationCallback? = null

    private fun init() {
        LayoutInflater.from(context).inflate(R.layout.view_navigation_bottom, this)
        mShopText = findViewById(R.id.id_view_navigation_bottom_box)
        mUserText = findViewById(R.id.id_view_navigation_bottom_user)
        mShopText?.setOnClickListener {
            mUserText?.setTextColor(resources.getColor(R.color.color_999999))
            mShopText?.setTextColor(resources.getColor(R.color.color_333333))
            val userDrawable = getResources().getDrawable(R.drawable.icon_bottom_my_default)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );

            val shopDrawable = getResources().getDrawable(R.drawable.icon_bottom_shop_click)
            shopDrawable.setBounds(
                0,
                0,
                shopDrawable.getMinimumWidth(),
                shopDrawable.getMinimumHeight()
            )

            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
        }
        mUserText?.setOnClickListener {
            mShopText?.setTextColor(resources.getColor(R.color.color_999999))
            mUserText?.setTextColor(resources.getColor(R.color.color_333333))
            val userDrawable = getResources().getDrawable(R.drawable.icon_bottom_my_click)
            userDrawable.setBounds(
                0,
                0,
                userDrawable.getMinimumWidth(),
                userDrawable.getMinimumHeight()
            );
            val shopDrawable = getResources().getDrawable(R.drawable.icon_bottom_shop_default)
            shopDrawable.setBounds(
                0,
                0,
                shopDrawable.getMinimumWidth(),
                shopDrawable.getMinimumHeight()
            )

            mUserText?.setCompoundDrawables(null, userDrawable, null, null)
            mShopText?.setCompoundDrawables(null, shopDrawable, null, null)
            navifationCallback?.onNavigationClick(it.id)
        }
    }


    fun setNavifationCallback(navifationCallback: NavifationCallback) {
        this.navifationCallback = navifationCallback
    }


    interface NavifationCallback {

        fun onNavigationClick(vId: Int)
    }

}