package com.wasu.cs.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wasu.cs.model.CatData;
import com.wasu.frescoimagefetchermodule.FrescoImageFetcherModule;

import cn.com.wasu.main.IntentMap;
import cn.com.wasu.main.R;

/**
 * Created by LiuYang on 7/13/15.
 */
public class SpecialTpItem extends LinearLayout implements View.OnClickListener {

    private TextView mTextView;
    private ImageView mImageView;
    private CatData.BaseElement mData;

    public SpecialTpItem(Context context) {
        super(context);
        init(context);
    }

    public SpecialTpItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public SpecialTpItem(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(context);
    }

    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.item_special_tp, this);

        mTextView = (TextView) findViewById(R.id.name);
        mImageView = (ImageView) findViewById(R.id.ivPic);

        setOnClickListener(this);
    }

    public void setFocusEnable(boolean enable) {
        setFocusable(enable);
        setFocusableInTouchMode(enable);
        setClickable(enable);
    }

    public void setData(CatData.BaseElement element) {
        this.mData = element;
        mTextView.setText(element.getName());
        FrescoImageFetcherModule.getInstance().attachImage(element.getPicUrl(), mImageView, getResources().getDimensionPixelSize(R.dimen.d_5dp));
    }

    @Override
    public void onClick(View view) {
        IntentMap.startIntent(getContext(),null,mData.getLayout(),mData.getJsonUrl(),null);
    }
}
