package com.partynetwork.iparty.iparty;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.partynetwork.dataprovider.DataProvider.IJsonResultListener;
import com.partynetwork.dataprovider.json.NetworkEntity;
import com.partynetwork.dataprovider.json.struct.Iparty_getIpartyRequst;
import com.partynetwork.dataprovider.json.struct.Iparty_getIpartyResponse;
import com.partynetwork.dataprovider.json.struct.Iparty_setOperatingForIpartyRequest;
import com.partynetwork.dataprovider.util.ActionUtil;
import com.partynetwork.dataprovider.util.StringUtil;
import com.partynetwork.dataprovider.util.T;
import com.partynetwork.iparty.R;
import com.partynetwork.iparty.app.AppContext;
import com.partynetwork.iparty.app.bean.BLogin;
import com.partynetwork.iparty.app.common.BitmapManager;
import com.partynetwork.iparty.app.common.UIHelper;
import com.partynetwork.iparty.helper.IntentHelper;
import com.partynetwork.iparty.info.IpartyFreeComboInfo;
import com.partynetwork.iparty.info.IpartyInfo;
import com.partynetwork.myview.myimageview.CircularImage;
import com.partynetwork.myview.mytoast.OkPopup;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
public class IpartyInfoActivity extends Activity implements IJsonResultListener {
/** 传输的IpartyInfo数据实体 */
// public static final String INFO = "info";
public static final String PARTY_ID = "partyId";
/** 正在举办 */
public static final int PARTY_STATE_PARTING = 0;
/** 成功举办 */
public static final int PARTY_STATE_SUCCESS = 1;
/** 举办失败 */
public static final int PARTY_STATE_FAIL = 2;
/** 预热 */
public static final int PARTY_STATE_PREHEAT = 3;
/**
* 背景ImageView
*/
@ViewInject(R.id.bg_iv)
private ImageView bg;
/**
* 预热中图片
*/
@ViewInject(R.id.state_iv)
private ImageView state;
/**
* party标题
*/
@ViewInject(R.id.title_tv)
private TextView title;
/**
* 主题按钮
*/
@ViewInject(R.id.theme_tv)
private TextView theme;
/**
* party内容文本
*/
@ViewInject(R.id.content_tv)
private TextView content;
/**
* 时间文本
*/
@ViewInject(R.id.time_tv)
private TextView time;
/**
* 地址文本
*/
@ViewInject(R.id.adrress_tv)
private TextView adrress;
/**
* 目标资金
*/
@ViewInject(R.id.goalmoney_tv)
private TextView goalMoney;
/**
* 当前资金
*/
@ViewInject(R.id.currentmoney_tv)
private TextView currentMoney;
/**
* 目标资金的布局
*/
@ViewInject(R.id.money_rl)
private RelativeLayout moneyRL;
/**
* 金额的竖线
*/
@ViewInject(R.id.money_line_ll)
private LinearLayout moneyLine;
/**
* 参加提示文本
*/
@ViewInject(R.id.attention_explain_tv)
private TextView attentionExplain;
/**
* 参加人数
*/
@ViewInject(R.id.attention_tv)
private TextView attention;
/**
* 剩余天数提示文本
*/
@ViewInject(R.id.day_explain_tv)
private TextView dayExplain;
/**
* 剩余天数
*/
@ViewInject(R.id.day_tv)
private TextView day;
/**
* 感兴趣提示文本
*/
@ViewInject(R.id.praise_explain_tv)
private TextView praiseExplain;
/**
* 感兴趣人数
*/
@ViewInject(R.id.praise_tv)
private TextView praise;
/**
* 说明文字
*/
@ViewInject(R.id.explain_tv)
private TextView explain;
/**
* 头像
*/
@ViewInject(R.id.head_iv)
private CircularImage head;
/**
* 名字
*/
@ViewInject(R.id.name_tv)
private TextView name;
/**
* 性别
*/
@ViewInject(R.id.sex_iv)
private ImageView sex;
/**
* 发布者信息
*/
@ViewInject(R.id.userinfo_tv)
private TextView userinfo;
/**
* 发布者信息布局
*/
@ViewInject(R.id.user_rl)
private RelativeLayout userRL;
/**
* 参加者信息布局
*/
@ViewInject(R.id.join_rl)
private RelativeLayout joinRL;
/**
* 参加者数量
*/
@ViewInject(R.id.join_number_tv)
private TextView joinNumber;
/**
* 评论信息布局
*/
@ViewInject(R.id.comment_rl)
private RelativeLayout commentRL;
/**
* 评论数量
*/
@ViewInject(R.id.comment_number_tv)
private TextView commentNumber;
/**
* 照片数量
*/
@ViewInject(R.id.photo_number_tv)
private TextView photoNumber;
/**
* 照片的布局
*/
@ViewInject(R.id.photo_ll)
private LinearLayout photo;
/**
* 套餐布局
*/
@ViewInject(R.id.combo_ll)
private LinearLayout combo;
/**
* 免费套餐布局
*/
@ViewInject(R.id.freecombo_ll)
private LinearLayout freecombo;
/**
* 返回按钮
*/
@ViewInject(R.id.back_rl)
private RelativeLayout back;
/**
* 我要参加按钮布局
*/
@ViewInject(R.id.iparty_info_join_rl)
private RelativeLayout joinBtnRL;
/**
* 我要参加按钮
*/
@ViewInject(R.id.iparty_info_join_tv)
private TextView joinTv;
/**
* 赞操作
*/
@ViewInject(R.id.praise_rl)
private RelativeLayout interestedRL;
/**
* 赞的图标
*/
@ViewInject(R.id.praise_iv)
private ImageView praiseIv;
/**
* 数据源
*/
private IpartyInfo info;
/** 当前iPartyId */
private int partyId;
/**
* 当前登陆用户
*/
private BLogin user;
/** 消息提示框 */
private OkPopup mOkPopup;
private BitmapManager bitmapManager;
/**
*
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.iparty_info);
ViewUtils.inject(this);
initView();
initDate();
}
private void initView() {
}
private void initDate() {
partyId = getIntent().getIntExtra(PARTY_ID, 0);
AppContext context = (AppContext) this.getApplication();
user = context.getLoginInfo();
mOkPopup = new OkPopup(this);
bitmapManager = new BitmapManager();
sendRequest();
}
/**
* 发送获取数据请求
*/
private void sendRequest() {
AppContext context = (AppContext) getApplication();
Iparty_getIpartyRequst requst = new Iparty_getIpartyRequst();
requst.setUserId(user.getUid());
requst.setIpartyId(partyId);
context.getmDataProvider().getJsonFromNetwork(requst, this);
}
/**
* 事件监听
*
* @param v
*/
@OnClick({ R.id.back_rl, R.id.moreinfo_tv, R.id.iparty_info_join_rl,
R.id.praise_rl, R.id.user_rl, R.id.join_rl, R.id.comment_rl })
public void btnClick(View v) {
switch (v.getId()) {
case R.id.back_rl:
// 返回
finish();
break;
case R.id.moreinfo_tv:
// 更多详情
Intent intent = new Intent(this, IpartyInfoMoreActivity.class);
intent.putExtra(IpartyInfoMoreActivity.INFO, info);
startActivity(intent);
break;
case R.id.iparty_info_join_rl:
// 参加
clickJoinBtn();
break;
case R.id.praise_rl:
// 赞操作
sendPraiseRequest();
break;
case R.id.user_rl:
// 头像点击事件
if (info != null) {
IntentHelper.goPersonalCenterActivity(this, info.getUserId());
}
break;
case R.id.join_rl:
// 参加人数
if (info != null) {
UIHelper.showPartyJoin(this, info.getIpartyId());
}
break;
case R.id.comment_rl:
// 评论人数
if (info != null) {
Intent intent3 = new Intent(this, IpartyCommentActivity.class);
intent3.putExtra(IpartyCommentActivity.PARTY_ID,
info.getIpartyId());
intent3.putExtra(IpartyCommentActivity.PARTY_NAME,
info.getEventTitle());
intent3.putExtra(IpartyCommentActivity.PARTY_FONT,
info.getEventFrontCoverUrl());
startActivity(intent3);
}
break;
default:
break;
}
}
/**
* 感兴趣操作
*/
private void sendPraiseRequest() {
if (info == null) {
return;
}
AppContext context = (AppContext) getApplication();
Iparty_setOperatingForIpartyRequest request = new Iparty_setOperatingForIpartyRequest();
request.setIpartyId(info.getIpartyId());
request.setUserId(user.getUid());
request.setOperatingType(1);
context.getmDataProvider().getJsonFromNetwork(request, this);
}
/**
* 设置数据
*/
private void initPage() {
if (info == null) {
return;
}
AppContext context = (AppContext) getApplication();
/* party状态 */
if (info.getEventStatus() == PARTY_STATE_PREHEAT) {
/* 预热中 */
state.setVisibility(View.VISIBLE);
moneyLine.setVisibility(View.GONE);
moneyRL.setVisibility(View.GONE);
attentionExplain.setText("感兴趣");
dayExplain.setText("已预热");
} else {
state.setVisibility(View.GONE);
moneyLine.setVisibility(View.VISIBLE);
moneyRL.setVisibility(View.VISIBLE);
attentionExplain.setText("已参加");
dayExplain.setText("剩余");
}
/* 图片 */
if (info.getEventFrontCoverUrl() != null) {
bitmapManager.loadBitmap(info.getEventFrontCoverUrl(), bg);
}
/* party标题 */
title.setText(info.getEventTitle());
/* 设置主题 */
String[] theme = info.getEventThemeArray();
if (theme != null && theme.length != 0) {
this.theme.setText("#"+theme[0]);
}
/* 设置标题 */
content.setText(info.getEventContent());
/* 设置时间 */
if (info.getEventTime() != null && info.getEventTime().length != 0) {
time.setText(StringUtil.getStrTime(info.getEventTime()[0]
.getStartTime()));
}
/* 设置地点 */
adrress.setText(info.getEventAddress());
/* 设置金额 */
// goalMoney.setText("目标:¥" + info.getEventGoalMoney());
goalMoney.setText("已付款");
currentMoney.setText("¥" + info.getEventCurrentMoney());
/* 设置参加人数 */
if (info.getEventStatus() == PARTY_STATE_PREHEAT) {
attention.setText(info.getEventInterestedPersons() + "人");
} else {
attention.setText(info.getEventJoinPeople() + "人");
}
/* 设置剩余天数 */
day.setText(info.getEventDaysRemaining() + "天");
/* 设置赞人数 */
praise.setText(info.getEventPraiseNumber() + "人");
/* 设置提示文字 */
if (info.getEventModel() == 0) {
explain.setText("本次Party需在"
+ StringUtil.getStrTime(info.getEventTime()[0]
.getStartTime()) + "之前筹集到"
+ info.getEventGoalMoney()
+ "元以上才能成功进行,否则,所有筹集资金将原路返回到参加者账户中。");
} else {
explain.setText("预定Party是一定会举办的,并且支持Party开始前可全额退款。");
}
/* 加载头像 */
bitmapManager.loadBitmap(info.getUserHeadUrl(), head);
/* 设置用户昵称 */
name.setText(info.getUserName());
/* 设置用户性别 */
if (info.getUserSex() == 0) {
sex.setImageResource(R.drawable.list_man);
} else if (info.getUserSex() == 1) {
sex.setImageResource(R.drawable.list_woman);
} else {
sex.setImageResource(R.drawable.list_neutral);
}
StringUtil.setText(
userinfo,
info.getUserState() + " " + info.getUserAge() + " "
+ info.getUserCity());
/* 参加者 */
joinNumber.setText("参加者(" + info.getEventJoinPeople() + ")");
/* 评论 */
commentNumber.setText("评论(" + info.getEventNumberOfComments() + ")");
/* 设置照片数量 */
int photoNum = 0;
if (info.getEventPhotoArray() != null) {
photoNum = info.getEventPhotoArray().length;
}
photoNumber.setText("Party照片(" + photoNum + ")");
/* 添加照片 */
if (photoNum != 0) {
photo.removeAllViews();
}
for (int i = 0; i < photoNum; i++) {
ImageView iv = new ImageView(this);
bitmapManager.loadBitmap(info.getEventPhotoArray()[i], iv);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
130, LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(params);
iv.setScaleType(ScaleType.CENTER_CROP);
photo.addView(iv);
}
/* 添加照片 */
int comboNum = 0;
if (info.getEventCombo() != null) {
comboNum = info.getEventCombo().length;
}
for (int i = 0; i < comboNum; i++) {
View view = LayoutInflater.from(this).inflate(
R.layout.iparty_info_combo, null);
TextView money = (TextView) view.findViewById(R.id.combo_money_tv);
TextView tip = (TextView) view.findViewById(R.id.combo_tip_tv);
TextView attend = (TextView) view
.findViewById(R.id.combo_attend_tv);
final TextView introduce = (TextView) view
.findViewById(R.id.introduce_tv);
final ImageView image = (ImageView) view
.findViewById(R.id.image_iv);
LinearLayout more_ll = (LinearLayout) view
.findViewById(R.id.more_ll);
money.setText("预付 ¥" + info.getEventCombo()[i].getMoney() + "+");
tip.setText(info.getEventCombo()[i].getAttendNum() + "/"
+ info.getEventCombo()[i].getMaxNum());
attend.setText(info.getEventCombo()[i].getAttendNum() + "人已参加");
introduce.setText(info.getEventCombo()[i].getIntroduce());
if (info.getEventCombo()[i].getComboPhotoUrl() != null) {
bitmapManager.loadBitmap(
info.getEventCombo()[i].getComboPhotoUrl(), image);
more_ll.setVisibility(View.VISIBLE);
} else {
more_ll.setVisibility(View.GONE);
}
more_ll.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (image.getVisibility() == View.GONE) {
introduce.setMaxLines(10);
image.setVisibility(View.VISIBLE);
} else {
introduce.setMaxLines(2);
image.setVisibility(View.GONE);
}
}
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.topMargin = -2;
if (i == 0) {
if (comboNum == 1) {
view.setBackgroundResource(R.drawable.stroke_single);
} else {
view.setBackgroundResource(R.drawable.stroke_top);
}
} else if (i == comboNum - 1) {
view.setLayoutParams(params);
view.setBackgroundResource(R.drawable.stroke_bottom);
} else {
view.setLayoutParams(params);
view.setBackgroundResource(R.drawable.stroke_center);
}
combo.addView(view);
}
/* 添加免费套餐 */
if (info.getEventFreeCombo() != null) {
View view = LayoutInflater.from(this).inflate(
R.layout.iparty_info_free, null);
final LinearLayout body = (LinearLayout) view
.findViewById(R.id.body);
TextView tip = (TextView) view.findViewById(R.id.combo_tip_tv);
TextView attend = (TextView) view
.findViewById(R.id.combo_attend_tv);
TextView introduce = (TextView) view
.findViewById(R.id.introduce_tv);
TextView sex_tv = (TextView) view.findViewById(R.id.sex_tv);
TextView age_tv = (TextView) view.findViewById(R.id.age_tv);
TextView needphoto_tv = (TextView) view
.findViewById(R.id.needphoto_tv);
TextView remark_tv = (TextView) view.findViewById(R.id.remark_tv);
TextView apply_tv = (TextView) view.findViewById(R.id.apply_tv);
Button moreBtn = (Button) view
.findViewById(R.id.more_btn);
ImageView image = (ImageView) view.findViewById(R.id.image_iv);
if (info.getEventFreeCombo().getComboPhotoUrl() != null) {
bitmapManager.loadBitmap(info.getEventFreeCombo()
.getComboPhotoUrl(), image);
} else {
image.setVisibility(View.GONE);
}
IpartyFreeComboInfo free = info.getEventFreeCombo();
attend.setText(free.getAttendNum() + "人已参加");
tip.setText(free.getAttendNum() + "/" + free.getMaxNum());
introduce.setText(free.getIntroduce());
if (free.getSex() == ActionUtil.user.MALE) {
sex_tv.setText("性别:男");
} else if (free.getSex() == ActionUtil.user.FEMALE) {
sex_tv.setText("性别:女");
} else if (free.getSex() == ActionUtil.user.NEUTER) {
sex_tv.setText("性别:其他");
} else {
sex_tv.setText("性别:不限");
}
age_tv.setText("年龄:" + free.getMinAge() + "~" + free.getMaxAge());
if (free.getNeedPhoto() == 0) {
needphoto_tv.setText("需提交真实照片验证");
} else {
needphoto_tv.setText("不需提交真实照片验证");
}
if(free.getRemark()==null){
remark_tv.setText("备注:无");
}else{
remark_tv.setText("备注:" + free.getRemark());
}
/* 免费申请操作 */
apply_tv.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 判断用户是否满足条件
if ((user.getSex() == info.getEventFreeCombo().getSex() || info
.getEventFreeCombo().getSex() == 3)
&& user.getAge() <= info.getEventFreeCombo()
.getMaxAge()
&& user.getAge() >= info.getEventFreeCombo()
.getMinAge()) {
// 满足条件
Intent intent = new Intent(IpartyInfoActivity.this,
IpartyPayActivity.class);
intent.putExtra(IpartyPayActivity.INFO, info);
intent.putExtra(IpartyPayActivity.TYPE,
IpartyPayActivity.FREE);
IpartyInfoActivity.this.startActivity(intent);
} else {
// 不满足参加条件
T.showTips(IpartyInfoActivity.this,
R.drawable.tips_error, "抱歉,你不符合申请条件!");
}
}
});
moreBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (body.getVisibility() == View.GONE) {
body.setVisibility(View.VISIBLE);
((Button)v).setText("收起");
} else {
body.setVisibility(View.GONE);
((Button)v).setText("更多");
}
}
});
body.setVisibility(View.GONE);
freecombo.addView(view);
}
/* 更改底部参加按钮状态 */
if (info.getUserId() == context.getLoginUid()) {
joinBtnRL.setBackgroundColor(this.getResources().getColor(
R.color.gray));
} else if (info.getEventStatus() == PARTY_STATE_PREHEAT) {
if (info.getEventIsInterested() == 0) {
joinTv.setText("感兴趣");
joinBtnRL.setBackgroundColor(this.getResources().getColor(
R.color.blue_text));
} else {
joinTv.setText("已感兴趣");
joinTv.setTextColor(this.getResources().getColor(R.color.gray));
joinBtnRL.setBackgroundColor(0);
}
} else if (info.getEventStatus() == PARTY_STATE_PARTING) {
joinTv.setText("我要参加");
joinBtnRL.setBackgroundColor(this.getResources().getColor(
R.color.red));
} else {
joinTv.setText("已结束");
joinBtnRL.setBackgroundColor(this.getResources().getColor(
R.color.gray));
}
/** 赞的按钮状态 */
if (info.getEventIsPraise() == 0) {
praiseIv.setImageResource(R.drawable.image_details_praise_pressed);
} else {
praiseIv.setImageResource(R.drawable.image_details_praise_seleted);
}
}
/**
* 参加按钮点击事件
*/
private void clickJoinBtn() {
if (info == null) {
return;
}
AppContext context = (AppContext) getApplication();
if (info.getUserId() == context.getLoginUid()) {
} else if (info.getEventStatus() == PARTY_STATE_PREHEAT) {
// 预热期间
if (info.getEventIsInterested() == 0) {
Iparty_setOperatingForIpartyRequest request = new Iparty_setOperatingForIpartyRequest();
request.setIpartyId(info.getIpartyId());
request.setOperatingType(0);
request.setUserId(context.getLoginUid());
context.getmDataProvider().getJsonFromNetwork(request, this);
}
} else if (info.getEventStatus() == PARTY_STATE_PARTING) {
// 正在举办
if (info.getEventCombo() == null
|| info.getEventCombo().length == 0) {
mOkPopup.setTitle("该派对无可参加套餐,请申请免费参加!");
mOkPopup.showAtLocation(bg);
} else {
Intent intent = new Intent(IpartyInfoActivity.this,
IpartyPayActivity.class);
intent.putExtra(IpartyPayActivity.INFO, info);
intent.putExtra(IpartyPayActivity.TYPE,
IpartyPayActivity.NEED_MONEY);
IpartyInfoActivity.this.startActivity(intent);
}
} else {
// 已结束
}
}
public void onNetworkRequest() {
}
/**
* 网络请求返回成功 覆盖方法
*
* @see com.partynetwork.dataprovider.DataProvider.IJsonResultListener#onResultSuccess(com.partynetwork.dataprovider.json.CommonResponse)
*/
public void onResultSuccess(NetworkEntity entity) {
if (entity.getRequest().getAction()
.equals(new Iparty_getIpartyRequst().getAction())) {
Iparty_getIpartyResponse response = (Iparty_getIpartyResponse) entity
.getResponse();
info = response.getDetails();
initPage();
}
if (entity.getRequest().getAction()
.equals(new Iparty_setOperatingForIpartyRequest().getAction())) {
/** 赞的按钮状态 */
Iparty_setOperatingForIpartyRequest request = (Iparty_setOperatingForIpartyRequest) entity
.getRequest();
if (request.getOperatingType() == 1) {
// 赞
if (info.getEventIsPraise() == 0) {
praiseIv.setImageResource(R.drawable.image_details_praise_seleted);
info.setEventIsPraise(1);
info.setEventPraiseNumber(info.getEventPraiseNumber() + 1);
praise.setText(info.getEventPraiseNumber() + "人");
} else {
praiseIv.setImageResource(R.drawable.image_details_praise_pressed);
info.setEventIsPraise(0);
info.setEventPraiseNumber(info.getEventPraiseNumber() - 1);
praise.setText(info.getEventPraiseNumber() + "人");
}
} else if (request.getOperatingType() == 0) {
// 感兴趣
joinTv.setText("已感兴趣");
joinTv.setTextColor(this.getResources().getColor(R.color.gray));
joinBtnRL.setBackgroundColor(0);
}
}
}
public void onResultFail(String result) {
T.showTips(this, R.drawable.tips_error, result);
}
}