package com.wasu.cs.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.com.wasu.main.R;

import com.wasu.cs.model.SearchModel.AssetsItem;
import com.wasu.frescoimagefetchermodule.FrescoImageFetcherModule;

public class SearchResultItem extends FrameLayout {
	
	private RelativeLayout mWarperRelLay;
	private ImageView mImageV, mZiXunImageV;
	private TextView mTV, mZiXunTV;
	private LinearLayout mWarperLinLay;

	private AssetsItem mAssetsItem;
	
	public SearchResultItem(Context context) {
		super(context);
		initLayout(context);
	}

	public SearchResultItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		initLayout(context);
	}

	public SearchResultItem(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		initLayout(context);
	}

	private void initLayout(Context context) {
		LayoutInflater.from(context).inflate(R.layout.item_search_result, this, true);
		
		mWarperRelLay = (RelativeLayout) findViewById(R.id.item_search_warper_relLay);
		mImageV = (ImageView) findViewById(R.id.item_search_result_imgv);
		mTV = (TextView) findViewById(R.id.item_search_name_tv);
		mWarperLinLay = (LinearLayout) findViewById(R.id.item_search_zixun_warper_relLay);
		mZiXunImageV = (ImageView) findViewById(R.id.item_search_zixun_imgv);
		mZiXunTV = (TextView) findViewById(R.id.item_search_zixun_name_tv);
	}
	
	/**
	 * show result item
	 * @param assetsItem result data
	 */
	public void show(AssetsItem assetsItem) {
		if (null == assetsItem) {
			return;
		}

		mAssetsItem = assetsItem;
		if (mAssetsItem.isMovieOrSeries()||mAssetsItem.isUnion()||mAssetsItem.isUnknow()) {
			mWarperRelLay.setVisibility(VISIBLE);
			mWarperLinLay.setVisibility(GONE);
			FrescoImageFetcherModule.getInstance().attachImage(mAssetsItem.getPicUrl(), mImageV);
			mTV.setText(mAssetsItem.getTitle());
		} else {
			mWarperRelLay.setVisibility(GONE);
			mWarperLinLay.setVisibility(VISIBLE);
			FrescoImageFetcherModule.getInstance().attachImage(mAssetsItem.getPicUrl(), mZiXunImageV, 0);
			mZiXunTV.setText(mAssetsItem.getTitle());
		}
	}
}
