package com.partynetwork.iparty.iparty;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.baidu.mobstat.StatService;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.partynetwork.dataprovider.DataProvider.IJsonResultListener;
import com.partynetwork.dataprovider.json.NetworkEntity;
import com.partynetwork.dataprovider.json.struct.Comment_getCommentRequest;
import com.partynetwork.dataprovider.json.struct.Comment_getCommentResponse;
import com.partynetwork.dataprovider.json.struct.Comment_setCommentRequest;
import com.partynetwork.dataprovider.json.struct.Comment_setCommentResponse;
import com.partynetwork.dataprovider.util.StringUtil;
import com.partynetwork.dataprovider.util.Util;
import com.partynetwork.iparty.R;
import com.partynetwork.iparty.app.AppContext;
import com.partynetwork.iparty.app.common.BitmapManager;
import com.partynetwork.iparty.info.CommentInfo;
import com.partynetwork.iparty.info.UserInfo;
import com.partynetwork.myview.myimageview.CircularImage;
public class IpartyCommentActivity extends Activity implements
IJsonResultListener {
public static final String PARTY_ID = "ipartyId";
public static final String PARTY_NAME = "ipartyName";
public static final String PARTY_FONT = "ipartyFont";
/**
* 返回按钮
*/
@ViewInject(R.id.menu_head_left)
private LinearLayout backBtn;
/**
* 显示的ichoose消息体
*/
@ViewInject(R.id.ishare_info_top_ll)
private LinearLayout body;
@ViewInject(R.id.title_tv)
private TextView title;
@ViewInject(R.id.title_iv)
private ImageView font;
/**
* 评论框
*/
@ViewInject(R.id.ishare_info_discuss_et)
private EditText et_discuss;
/**
* 发表评论按钮
*/
@ViewInject(R.id.ishare_info_discuss_btn)
private Button btn_discuss;
/**
* 评论列表
*/
@ViewInject(R.id.ishare_info_discuss_ll)
private LinearLayout ll_content;
/** iPartyId */
private int ipartyId;
/** iPartyName */
private String ipartyName;
/** iPartyFont */
private String ipartyFont;
/** 最后一条数据的id */
private int lastId;
/** 页码编号 */
private int pageNumber = 0;
/** 每页的数据大小 */
private int pageSize = 0;
private BitmapManager bitmapManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.iparty_comment);
ViewUtils.inject(this);
init();
}
private void init() {
ipartyId = getIntent().getIntExtra(PARTY_ID, 0);
ipartyName = getIntent().getStringExtra(PARTY_NAME);
ipartyFont = getIntent().getStringExtra(PARTY_FONT);
// 获取评论
getComment();
// 获取基本数据
initData();
}
/**
* 发送请求
*/
private void initData() {
bitmapManager = new BitmapManager();
StringUtil.setText(title, ipartyName);
bitmapManager.loadBitmap(ipartyFont, font);
}
/**
* 发送获取评论的请求
*/
private void getComment() {
AppContext context = (AppContext) getApplication();
Comment_getCommentRequest request = new Comment_getCommentRequest();
request.setType(0);
request.setContentId(ipartyId);
request.setLastId(lastId);
request.setPageSize(pageSize);
request.setPageNumber(pageNumber);
context.getmDataProvider().getJsonFromNetwork(request, this);
}
/**
* 点击事件监听
*
* @param v
*/
@OnClick({ R.id.menu_head_left, R.id.ishare_info_discuss_btn,
R.id.ishare_info_discuss_ll })
public void btnClick(View v) {
switch (v.getId()) {
case R.id.menu_head_left:
// 返回
finish();
break;
case R.id.ishare_info_discuss_btn:
// 发送评论
sendComment();
break;
default:
break;
}
}
/**
* 发送评论
*/
private void sendComment() {
String str = et_discuss.getText().toString();
if (str.equals("") || str.equals("")) {
return;
}
AppContext context = (AppContext) getApplication();
Comment_setCommentRequest request = new Comment_setCommentRequest();
request.setUserId(context.getLoginUid());
request.setType(0);
request.setContentId(ipartyId);
request.setCommentMessage(str);
context.getmDataProvider().getJsonFromNetwork(request, this);
}
/**
* 添加留言
*/
private void addComment(CommentInfo c) {
View view = LayoutInflater.from(this).inflate(
R.layout.ishare_info_item, null);
CircularImage image = (CircularImage) view.findViewById(R.id.iv_head);
bitmapManager.loadBitmap(c.getUserHeadUrl(), image);
TextView say = (TextView) view.findViewById(R.id.tv_say);
say.setText(c.getCommentMessage());
TextView time = (TextView) view.findViewById(R.id.tv_time);
time.setText(c.getCommentTime());
TextView name = (TextView) view.findViewById(R.id.tv_name);
name.setText(c.getUserName());
ll_content.addView(view, 0);
}
public void onNetworkRequest() {
}
public void onResultSuccess(NetworkEntity entity) {
if (entity.getRequest().getAction()
.equals(new Comment_getCommentRequest().getAction())) {
ll_content.removeAllViews();
CommentInfo[] comments = ((Comment_getCommentResponse) entity
.getResponse()).getDetails();
for (int i = comments.length; i > 0; i--) {
addComment(comments[i - 1]);
}
} else if (entity.getRequest().getAction()
.equals(new Comment_setCommentRequest().getAction())) {
CommentInfo[] comments = ((Comment_setCommentResponse) entity
.getResponse()).getDetails();
if (comments != null) {
addComment(comments[0]);
et_discuss.setText("");
}
}
}
public void onResultFail(String result) {
Util.showMsg(this, result);
}
@Override
protected void onResume() {
StatService.onResume(this);
super.onResume();
}
@Override
protected void onPause() {
StatService.onPause(this);
super.onPause();
}
}