package com.partynetwork.iparty.iparty;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.partynetwork.dataprovider.util.StringUtil;
import com.partynetwork.iparty.R;
import com.partynetwork.iparty.app.common.BitmapManager;
import com.partynetwork.iparty.app.common.UIHelper;
import com.partynetwork.iparty.assistant.AssistantPage;
import com.partynetwork.iparty.helper.IntentHelper;
import com.partynetwork.iparty.info.IpartyInfo;
import com.partynetwork.iparty.info.TimeInfo;
import com.partynetwork.iparty.ishare.IshareReportActivity;
import com.partynetwork.myview.myimageview.CircularImage;
import com.partynetwork.myview.mytoast.MenuBottomPop;
public class IpartyView extends RelativeLayout implements OnClickListener {
/**
* 头像
*/
private CircularImage photo;
/**
* 名字
*/
private TextView name;
private ImageView more;
/**
* 用户等级
*/
private LinearLayout grade;
/**
* 发布时间
*/
private TextView time;
/**
* 主题
*/
private TextView theme;
/**
* 类别图片
*/
private ImageView type;
/**
* 状态
*/
private ImageView state;
/**
* 封面背景
*/
private ImageView bg;
/**
* 标题
*/
private TextView title;
/**
* 进度条
*/
private ProgressBar pro;
/**
* 进度文字
*/
private TextView percent;
/**
* 举办时间
*/
private TextView eventTime;
/**
* 举办地点
*/
private TextView adrress;
/**
* 套餐显示
*/
private TextView comboTv;
/**
* 钱数
*/
private TextView money;
/**
* 参加人数
*/
private TextView people;
/**
* 时间
*
*/
private TextView day;
/**
* 赞的人数
*/
private TextView praise;
/**
* 上下文对象
*/
private Context mContext;
/**
* 底部的弹窗
*/
private MenuBottomPop menuBottonPop;
/*
* 更多功能列表
*/
private String moreArray[] = new String[] { "举报不良信息" };
/**
* 数据源
*/
private IpartyInfo info;
private BitmapManager bitmapManager;
public IpartyView(Context context, BitmapManager manager) {
super(context);
this.mContext = context;
bitmapManager = manager;
View.inflate(mContext, R.layout.iparty_item, this);
init();
setOnClickListener();
}
/**
* 控件初始化
*/
private void init() {
menuBottonPop = new MenuBottomPop(mContext, moreArray, clickListener);
initView();
}
/**
* 初始化控件
*/
private void initView() {
photo = (CircularImage) this.findViewById(R.id.head_iv);
photo.setOnClickListener(this);
name = (TextView) this.findViewById(R.id.name_tv);
more = (ImageView) this.findViewById(R.id.iparty_item_more);
more.setOnClickListener(this);
grade = (LinearLayout) this.findViewById(R.id.user_grade_ll);
time = (TextView) this.findViewById(R.id.time_tv);
theme = (TextView) this.findViewById(R.id.theme_tv);
type = (ImageView) this.findViewById(R.id.type_iv);
state = (ImageView) this.findViewById(R.id.state_iv);
bg = (ImageView) this.findViewById(R.id.photo_iv);
title = (TextView) this.findViewById(R.id.title_tv);
pro = (ProgressBar) this.findViewById(R.id.body_pro);
percent = (TextView) this.findViewById(R.id.percent_tv);
eventTime = (TextView) this.findViewById(R.id.event_time_tv);
adrress = (TextView) this.findViewById(R.id.adrress_tv);
comboTv = (TextView) this.findViewById(R.id.combo_tv);
money = (TextView) this.findViewById(R.id.money_tv);
people = (TextView) this.findViewById(R.id.people_tv);
day = (TextView) this.findViewById(R.id.day_tv);
praise = (TextView) this.findViewById(R.id.praise_tv);
}
/**
* 底部弹窗的监听
*/
private OnClickListener clickListener = new OnClickListener() {
public void onClick(View v) {
if (v.getTag().equals(moreArray[0])) {
Intent intent = new Intent(mContext, IshareReportActivity.class);
intent.putExtra(IshareReportActivity.CONTENT_ID,
info.getIpartyId());
intent.putExtra(IshareReportActivity.REPORT_EVENT_TYPE, 1);
mContext.startActivity(intent);
}
menuBottonPop.dismiss();
}
};
/**
* 根据数据源初始化控件
*
* @param requst
*/
public void setInfo(IpartyInfo requst) {
this.info = requst;
setPhoto(requst.getUserHeadUrl());
setName(requst.getUserName());
setGrade(requst.getOrganizersCreditRating());
setTime(requst.getPublishedTime());
setTheme(requst.getEventThemeArray());
setType(requst.getEventModel());
setState(requst.getEventStatus());
setBg(requst.getEventFrontCoverUrl());
setTitle(requst.getEventTitle());
setEventTime(requst.getEventTime());
setAdrress(requst.getEventAddress());
setCombo();
// 设置金额
StringUtil.setText(money, "¥" + (int) info.getEventCurrentMoney());
StringUtil.setText(people, info.getEventJoinPeople() + "人");
StringUtil.setText(day, info.getEventDaysRemaining() + "天");
StringUtil.setText(praise, info.getEventPraiseNumber() + "人");
setPercent();
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.head_iv:
IntentHelper.goPersonalCenterActivity(mContext, info.getUserId());
break;
case R.id.iparty_item_more:
menuBottonPop.showAtLocation(photo);
break;
default:
break;
}
}
/**
* 设置监听
*/
private void setOnClickListener() {
this.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
UIHelper.showPartyInfo(mContext, info.getIpartyId());
}
});
}
/**
* 设置头像
*
* @param url
*/
private void setPhoto(String url) {
bitmapManager.loadBitmap(url, photo);
}
/**
* 设置背景图片
*
* @param urlArray
*/
private void setBg(String url) {
if (url != null && !url.equals("")) {
bitmapManager.loadBitmap(url, bg);
}
}
/**
* 设置姓名
*
* @param name
*/
private void setName(String name) {
this.name.setText(name);
}
/**
* 设置用户等级
*
* @param grade
*/
private void setGrade(int grade) {
this.grade.removeAllViews();
this.grade.addView(AssistantPage.getGradeLayout(mContext, grade,
AssistantPage.INITIATOR));
}
/**
* 设置主题
*
* @param theme
*/
private void setTheme(String[] theme) {
if (theme != null && theme.length != 0) {
this.theme.setText("#" + theme[0]);
}
}
/**
* 设置时间
*/
public void setTime(String time) {
this.time.setText(time);
}
/**
* 活动的类型 活动发布的类型:0 众筹;1 预定
*
* @param type
*/
private void setType(int type) {
if (type == 0) {
this.type.setImageResource(R.drawable.iparty_item_type_raise);
} else {
this.type.setImageResource(R.drawable.iparty_item_type_book);
}
}
/**
* 设置活动状态 活动当前状态:0 正在举办;1 成功举办;2 举办失败;3 预热中
*
* @param state
*/
private void setState(int state) {
this.state.setVisibility(View.GONE);
if (state == 1) {
this.state.setVisibility(View.VISIBLE);
this.state.setImageResource(R.drawable.iparty_item_state_success);
} else if (state == 2) {
this.state.setVisibility(View.VISIBLE);
this.state.setImageResource(R.drawable.iparty_item_state_fail);
} else if (state == 3) {
this.state.setVisibility(View.VISIBLE);
this.state.setImageResource(R.drawable.iparty_item_state_hot);
}
}
/**
* 设置标题
*
* @param title
*/
private void setTitle(String title) {
this.title.setText(title);
}
/**
* 设置当前的进度条进度
*/
private void setPercent() {
// int percent = 0;
float percent = info.getEventProgressRate();
// // 活动发布的类型:0 众筹;1 预定
if (info.getEventModel() == 0) {
this.pro.setVisibility(View.VISIBLE);
this.percent.setVisibility(View.VISIBLE);
// percent = (int) (info.getEventCurrentMoney()
// / (float) info.getEventGoalMoney() * 100);
} else {
this.pro.setVisibility(View.GONE);
this.percent.setVisibility(View.GONE);
}
this.pro.setProgress((int) percent);
this.percent.setText(StringUtil.formatFloat(percent) + "%");
}
/**
* 设置举办时间
*
* @param eventTime
*/
private void setEventTime(TimeInfo[] eventTime) {
if (eventTime != null && eventTime.length != 0) {
this.eventTime.setVisibility(View.VISIBLE);
this.eventTime.setText(StringUtil.getStrTime(eventTime[0]
.getStartTime()));
} else {
this.eventTime.setVisibility(View.GONE);
}
}
/**
* 设置活动举办地点
*
* @param adrress
*/
private void setAdrress(String adrress) {
if (adrress.equals("")) {
this.adrress.setVisibility(View.GONE);
} else {
this.adrress.setVisibility(View.VISIBLE);
this.adrress.setText(adrress);
}
}
/**
* 设置套餐展示文本
*/
private void setCombo() {
List<String> comboArray = new ArrayList<String>();
String comboText = "";
// 添加付费套餐
if (info.getEventCombo() != null) {
for (int i = 0; i < info.getEventCombo().length; i++) {
comboArray.add(StringUtil.formatFloat(info.getEventCombo()[i]
.getMoney()));
}
}
// 添加免费套餐
if (info.getEventFreeCombo() != null) {
comboArray.add("免费");
}
// 拼接套餐字符创
for (int i = 0; i < comboArray.size(); i++) {
if (i == comboArray.size() - 1) {
comboText += comboArray.get(i);
} else {
comboText += comboArray.get(i) + "/";
}
}
// 如果为众筹模式或者没有套餐则消失
if (info.getEventModel() == 0 || comboArray.size() == 0) {
this.comboTv.setVisibility(View.GONE);
} else if (info.getEventModel() == 1) {
this.comboTv.setVisibility(View.VISIBLE);
}
this.comboTv.setText(comboText);
}
}