package com.wasu.cs.widget;

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

import com.wasu.cs.model.CatData.BaseElement;
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 ChannelMovieItem extends FrameLayout implements View.OnClickListener,IViewItem {

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

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

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

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

    /**
     * 初始化ChannelMovieItem
     * @param context
     */
    private void init(Context context) {
        LayoutInflater.from(context).inflate(R.layout.item_channel_movie, this);

        setFocusable(true);
        //setFocusableInTouchMode(true);
        setClickable(true);
        
        mTextView = (TextView) findViewById(R.id.name);
        mImageView = (ImageView) findViewById(R.id.ivPic);

        setOnClickListener(this);
    }

    @Override
    public void setData(BaseElement element) {
        this.mData = element;
        mTextView.setText(element.getName());
        FrescoImageFetcherModule.getInstance().attachImage(element.getPicUrl(), mImageView);
    }

    public BaseElement getData() {
        return mData;
    }
    /**
     * item点击监听器
     */
    @Override
    public void onClick(View view) {
        IntentMap.startIntent(getContext(),null,mData.getLayout(),mData.getJsonUrl(),null);
    }
}
