package com.wasu.cs.ui;

import com.wasu.cs.model.DemandProgram;

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

public class DetailResTitle extends LinearLayout {
	private TextView mResNameTextView;
	private TextView mResScore;
	private TextView mResyear;
	private TextView updateTextView;
	public DetailResTitle(Context context) {
		super(context);
		init(context);
	}
	public DetailResTitle(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}
	public DetailResTitle(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	public void init(Context context){
		View view=LayoutInflater.from(context).inflate(R.layout.detail_resource_title, null);
		mResNameTextView = (TextView) view.findViewById(R.id.detail_resourcename);
		mResScore = (TextView) view.findViewById(R.id.detail_score);
		mResyear=(TextView)view.findViewById(R.id.detail_year);
		updateTextView=(TextView)view.findViewById(R.id.detail_serialupdate);
		addView(view);
	}
	public void setData(DemandProgram data){
		if(data==null){
			return;
		}
		//名称
		if (data.getTitle().trim().equals("")) {
			mResNameTextView.setText("");
		} else {
			mResNameTextView.setText(data.getTitle());
		}
		//上映时间
		if (data.getYear().trim().equals("")) {
			mResyear.setText("");
		} else {
			mResyear.setText("("+data.getYear()+")");
		}
		//豆瓣评分
		TextView scoreTextView=(TextView)findViewById(R.id.detail_scoretext);
		if (data.getPoints().trim().equals("")) {
			mResScore.setVisibility(View.GONE);
			scoreTextView.setVisibility(View.GONE);
		} else {
			scoreTextView.setVisibility(View.VISIBLE);
			mResScore.setVisibility(View.VISIBLE);
			mResScore.setText(data.getPoints());
		}
		//电视剧的更新信息
		if(data.getAssetType()==DemandProgram.SHOWTYPE_TV_SERIES){
			if(data.getNowItem()==data.getItemNum()){
				updateTextView.setText("共"+data.getItemNum()+"集完"); 
			}else{
				updateTextView.setText("更新至"+data.getNowItem()+"集,共"+data.getItemNum()+"集");
			} 
			updateTextView.setVisibility(View.VISIBLE); 
		}else{
			updateTextView.setVisibility(View.GONE); 
		}
	}
}
