@Override public void parseJson(int code, JSONObject respanse, String tag, int pos, Object data) throws JSONException { if (tag.equals(URI_COMMENT)) { swipeRefreshLayout.setRefreshing(false); if (code == 0) { mData.clear(); JSONArray jsonArray = respanse.getJSONObject("data").getJSONArray("list"); for (int i = 0; i < jsonArray.length(); ++i) { Maopao.Comment comment = new Maopao.Comment(jsonArray.getJSONObject(i)); mData.add(comment); } if (mModifyComment) { mMaopaoObject.comments = mData.size(); mMaopaoObject.comment_list = mData; Intent intent = new Intent(); intent.putExtra(ListModify.DATA, mMaopaoObject); intent.putExtra(ListModify.TYPE, ListModify.Edit); setResult(Activity.RESULT_OK, intent); } adapter.notifyDataSetChanged(); } else { showErrorMsg(code, respanse); } } else if (tag.equals(ADD_COMMENT)) { showProgressBar(false); if (code == 0) { umengEvent(UmengEvent.MAOPAO, "添加冒泡评论"); getNetwork(URI_COMMENT, URI_COMMENT); mEnterLayout.restoreDelete(data); mEnterLayout.clearContent(); mEnterLayout.hideKeyboard(); mModifyComment = true; } else { showErrorMsg(code, respanse); } } else if (tag.equals(HOST_GOOD)) { if (code == 0) { Maopao.MaopaoObject maopao = mMaopaoObject; maopao.liked = !maopao.liked; if (maopao.liked) { umengEvent(UmengEvent.MAOPAO, "冒泡点赞"); Maopao.Like_user like_user = new Maopao.Like_user(MyApp.sUserObject); maopao.like_users.add(0, like_user); ++maopao.likes; } else { umengEvent(UmengEvent.MAOPAO, "冒泡取消点赞"); for (int j = 0; j < maopao.like_users.size(); ++j) { if (maopao.like_users.get(j).global_key.equals(MyApp.sUserObject.global_key)) { maopao.like_users.remove(j); --maopao.likes; break; } } } likeUsersArea.displayLikeUser(); Intent intent = new Intent(); intent.putExtra(ListModify.DATA, mMaopaoObject); intent.putExtra(ListModify.TYPE, ListModify.Edit); setResult(Activity.RESULT_OK, intent); } else { showErrorMsg(code, respanse); } likeBtn.setChecked(mMaopaoObject.liked); } else if (tag.equals(maopaoUrl)) { if (code == 0) { mMaopaoObject = new Maopao.MaopaoObject(respanse.getJSONObject("data")); initData(); } else { mMaopaoObject = mMaopaoObjectOld; swipeRefreshLayout.setRefreshing(false); showErrorMsg(code, respanse); } } else if (tag.equals(URI_COMMENT_DELETE)) { if (code == 0) { mModifyComment = true; getNetwork(URI_COMMENT, URI_COMMENT); } else { showErrorMsg(code, respanse); } } else if (tag.equals(TAG_DELETE_MAOPAO)) { if (code == 0) { Intent intent = new Intent(); intent.putExtra(ListModify.TYPE, ListModify.Delete); intent.putExtra(ListModify.ID, mMaopaoObject.id); setResult(Activity.RESULT_OK, intent); finish(); } else { showErrorMsg(code, respanse); } } else if (tag.equals(TAG_LIKE_USERS)) { if (code == 0) { JSONObject jsonData = respanse.getJSONObject("data"); JSONArray jsonArray = jsonData.getJSONArray("list"); for (int i = 0; i < jsonArray.length(); ++i) { Maopao.Like_user user = new Maopao.Like_user(jsonArray.getJSONObject(i)); mMaopaoObject.like_users.add(user); } likeUsersArea.displayLikeUser(); } } }
void initHead() { if (mListHead == null) { mListHead = mInflater.inflate(R.layout.activity_maopao_detail_head, null, false); listView.addHeaderView(mListHead, null, false); } ImageView icon = (ImageView) mListHead.findViewById(R.id.icon); icon.setOnClickListener(mOnClickUser); TextView name = (TextView) mListHead.findViewById(R.id.name); name.setOnClickListener(mOnClickUser); TextView time = (TextView) mListHead.findViewById(R.id.time); time.setText(Global.dayToNow(mMaopaoObject.created_at)); iconfromNetwork(icon, mMaopaoObject.owner.avatar); icon.setTag(mMaopaoObject.owner.global_key); name.setText(mMaopaoObject.owner.name); name.setTag(mMaopaoObject.owner.global_key); WebView webView = (WebView) mListHead.findViewById(R.id.comment); Global.initWebView(webView); String replaceContent = bubble.replace("${webview_content}", mMaopaoObject.content); webView.loadDataWithBaseURL(null, replaceContent, "text/html", "UTF-8", null); webView.setWebViewClient(new CustomWebViewClient(this, mMaopaoObject.content)); mListHead.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { prepareAddComment(mMaopaoObject, true); } }); mListHead .findViewById(R.id.shareBtn) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { action_share_third(); } }); likeBtn = (CheckBox) mListHead.findViewById(R.id.likeBtn); mListHead .findViewById(R.id.commentBtn) .setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { prepareAddComment(mMaopaoObject, true); } }); likeBtn.setChecked(mMaopaoObject.liked); likeBtn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { if (mMaopaoObject == null) { showMiddleToast(R.string.maopao_load_fail_like); return; } boolean like = ((CheckBox) v).isChecked(); String type = like ? "like" : "unlike"; if (like) { View good = mListHead.findViewById(R.id.maopaoGood); MaopaoLikeAnimation.playAnimation(good, v); } String uri = String.format(HOST_GOOD, mMaopaoObject.id, type); postNetwork(uri, new RequestParams(), HOST_GOOD, 0, mMaopaoObject); } }); likeUsersArea = new LikeUsersArea(mListHead, this, getImageLoad(), mOnClickUser); likeUsersArea.likeUsersLayout.setTag(MaopaoListFragment.TAG_MAOPAO, mMaopaoObject); if (mMaopaoObject.like_users.isEmpty() && mMaopaoObject.likes > 0) { String hostLikes = String.format(LikeUsersListActivity.HOST_LIKES_USER, mMaopaoObject.id); getNetwork(hostLikes, TAG_LIKE_USERS); } likeUsersArea.displayLikeUser(); TextView locationView = (TextView) mListHead.findViewById(R.id.location); MaopaoLocationArea.bind(locationView, mMaopaoObject); TextView photoType = (TextView) mListHead.findViewById(R.id.photoType); String device = mMaopaoObject.device; if (!device.isEmpty()) { final String format = "来自 %s"; photoType.setText(String.format(format, device)); photoType.setVisibility(View.VISIBLE); } else { photoType.setText(""); photoType.setVisibility(View.GONE); } View deleteButton = mListHead.findViewById(R.id.deleteButton); if (mMaopaoObject.owner.isMe()) { deleteButton.setVisibility(View.VISIBLE); deleteButton.setOnClickListener(onClickDeleteMaopao); } else { deleteButton.setVisibility(View.INVISIBLE); } }