package com.partynetwork.iparty.ishare; 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.json.struct.Ishare_getIshareRequest; import com.partynetwork.dataprovider.json.struct.Ishare_getIshareResponse; 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.IshareInfo; import com.partynetwork.myview.myimageview.CircularImage; 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 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.LinearLayout; import android.widget.TextView; public class IshareInfoActivity extends Activity implements IJsonResultListener { public static final String SHARE_ID = "shareId"; /** * 返回按钮 */ @ViewInject(R.id.menu_head_left) private LinearLayout backBtn; /** * 显示的ichoose消息体 */ @ViewInject(R.id.ishare_info_top_ll) private LinearLayout body; /** * 评论框 */ @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; /** * 当前页的数据 */ private IshareInfo info; /** i分享Id */ private int ishareId; /** * 当前页展示的view */ private IshareView view; AppContext context; private BitmapManager bitmapManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.ishare_info); ViewUtils.inject(this); context = (AppContext) this.getApplication(); init(); } private void init() { bitmapManager=new BitmapManager(); ishareId = getIntent().getIntExtra(SHARE_ID, 0); // 获取基本数据 sendRequest(); // 获取评论 getComment(); } /** * 发送请求 */ private void sendRequest() { Ishare_getIshareRequest request = new Ishare_getIshareRequest(); request.setUserId(context.getLoginUid()); request.setIshareId(ishareId); context.getmDataProvider().getJsonFromNetwork(request, this); } /** * 发送获取评论的请求 */ private void getComment() { Comment_getCommentRequest request = new Comment_getCommentRequest(); request.setType(2); request.setContentId(ishareId); request.setLastId(0); request.setPageNumber(0); 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; } Comment_setCommentRequest request = new Comment_setCommentRequest(); request.setUserId(context.getLoginUid()); request.setType(2); request.setContentId(ishareId); 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() { // TODO 自动生成的方法存根 } 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(""); } } else if (entity.getRequest().getAction() .equals(new Ishare_getIshareRequest().getAction())) { Ishare_getIshareResponse response = (Ishare_getIshareResponse) entity .getResponse(); info = response.getDetails(); body.removeAllViews(); view = new IshareView(this,bitmapManager); view.setInfo(info); body.addView(view); } } 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(); } }