|
|
@@ -1,28 +1,87 @@
|
|
|
package com.xzjmyk.pm.activity.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
+import android.text.SpannableStringBuilder;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.BaseAdapter;
|
|
|
import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.bean.User;
|
|
|
+import com.xzjmyk.pm.activity.bean.circle.Comment;
|
|
|
+import com.xzjmyk.pm.activity.bean.circle.Praise;
|
|
|
import com.xzjmyk.pm.activity.bean.circle.PublicMessage;
|
|
|
+import com.xzjmyk.pm.activity.helper.AvatarHelper;
|
|
|
+import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.HtmlUtils;
|
|
|
+import com.xzjmyk.pm.activity.util.LinkMovementClickMethod;
|
|
|
+import com.xzjmyk.pm.activity.util.StringUtils;
|
|
|
+import com.xzjmyk.pm.activity.util.TimeUtils;
|
|
|
import com.xzjmyk.pm.activity.view.MyListView;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by gongpm on 2016/8/1.
|
|
|
*/
|
|
|
public class WorkLogAdapter extends BaseAdapter {
|
|
|
+ private static final int PRAISE_WHAT = 0x11;
|
|
|
+ private User user;
|
|
|
private List<PublicMessage> messages;
|
|
|
private Context context;
|
|
|
+ private CommentAdapter mAdapter;
|
|
|
+ private int pon;//点赞的对象
|
|
|
+ private Handler handler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ String message = msg.getData().getString("result");
|
|
|
+ Log.i("gongpengming", message);
|
|
|
+ switch (msg.what) {
|
|
|
+ case PRAISE_WHAT:
|
|
|
+ JSONObject json = JSON.parseObject(message);
|
|
|
+ if (json.getIntValue("resultCode") != 1) return;
|
|
|
+ if (json.getString("data") == null) {//为取消点赞
|
|
|
+ messages.get(pon).setIsPraise(0);
|
|
|
+ messages.get(pon).setPraise(messages.get(pon).getPraise() - 1);
|
|
|
+ List<Praise> praises = messages.get(pon).getPraises();
|
|
|
+ for (int i = 0; i < praises.size(); i++) {
|
|
|
+ if (praises.get(i).getUserId().equals(MyApplication.getInstance().mLoginUser.getUserId())) {
|
|
|
+ praises.remove(i);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {//点赞
|
|
|
+ messages.get(pon).setIsPraise(1);
|
|
|
+ Praise bean = new Praise();
|
|
|
+ bean.setNickName(MyApplication.getInstance().mLoginUser.getNickName());
|
|
|
+ bean.setUserId(MyApplication.getInstance().mLoginUser.getUserId());
|
|
|
+ bean.setPraiseId(json.getString("data"));
|
|
|
+ messages.get(pon).getPraises().add(0, bean);
|
|
|
+ messages.get(pon).setPraise(messages.get(pon).getPraise() + 1);
|
|
|
+ }
|
|
|
+ notifyDataSetChanged();
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- public WorkLogAdapter(Context context) {
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ public WorkLogAdapter(Context context, List<PublicMessage> messages) {
|
|
|
this.context = context;
|
|
|
+ this.messages = messages;
|
|
|
+ this.user = MyApplication.getInstance().mLoginUser;
|
|
|
}
|
|
|
|
|
|
public void setData(List<PublicMessage> messages) {
|
|
|
@@ -50,18 +109,15 @@ public class WorkLogAdapter extends BaseAdapter {
|
|
|
ViewHolder holder;
|
|
|
if (view == null) {
|
|
|
holder = new ViewHolder();
|
|
|
- LayoutInflater.from(context).inflate(R.layout.p_msg_item_main_body, null);
|
|
|
+ view = LayoutInflater.from(context).inflate(R.layout.item_activity_worklogs, null);
|
|
|
holder.avatar_img = (ImageView) view.findViewById(R.id.avatar_img);
|
|
|
- holder.operation_more_img = (ImageView) view.findViewById(R.id.operation_more_img);
|
|
|
-
|
|
|
- holder.nick_name_tv = (TextView) view.findViewById(R.id.nick_name_tv);
|
|
|
- holder.body_tv = (TextView) view.findViewById(R.id.body_tv);
|
|
|
+ holder.comment_tag = (LinearLayout) view.findViewById(R.id.comment_tag);
|
|
|
+ holder.name_tv = (TextView) view.findViewById(R.id.name_tv);
|
|
|
+ holder.content_tv = (TextView) view.findViewById(R.id.content_tv);
|
|
|
holder.time_tv = (TextView) view.findViewById(R.id.time_tv);
|
|
|
- holder.delete_tv = (TextView) view.findViewById(R.id.delete_tv);
|
|
|
- holder.location_tv = (TextView) view.findViewById(R.id.location_tv);
|
|
|
- holder.multi_praise_tv = (TextView) view.findViewById(R.id.multi_praise_tv);
|
|
|
- holder.img_praise_line = view.findViewById(R.id.img_praise_line);
|
|
|
- holder.command_listView = (MyListView) view.findViewById(R.id.command_listView);
|
|
|
+ holder.like_tv = (TextView) view.findViewById(R.id.like_tv);
|
|
|
+ holder.command_tv = (TextView) view.findViewById(R.id.command_tv);
|
|
|
+ holder.command_lv = (MyListView) view.findViewById(R.id.command_lv);
|
|
|
view.setTag(holder);
|
|
|
} else {
|
|
|
holder = (ViewHolder) view.getTag();
|
|
|
@@ -70,22 +126,185 @@ public class WorkLogAdapter extends BaseAdapter {
|
|
|
return view;
|
|
|
}
|
|
|
|
|
|
- private void bindData(ViewHolder holder, int i) {
|
|
|
- PublicMessage message = messages.get(i);
|
|
|
+ private PublicMessage.Body body;//临时变量
|
|
|
|
|
|
+ private void bindData(ViewHolder holder, final int i) {
|
|
|
+ final PublicMessage message = messages.get(i);
|
|
|
+ holder.name_tv.setText(message.getNickName());//名字
|
|
|
+ AvatarHelper.getInstance().displayAvatar(message.getUserId(), holder.avatar_img, false);//头像设置
|
|
|
+ holder.time_tv.setText(TimeUtils.getFriendlyTimeDesc(context, (int) message.getTime()));//时间设置
|
|
|
+ body = message.getBody();
|
|
|
+ String text;
|
|
|
+ if (body == null || body.getText() == null) text = "";
|
|
|
+ else text = body.getText();
|
|
|
+ holder.content_tv.setText(text);
|
|
|
+ final List<Comment> comments = message.getComments();
|
|
|
+ holder.like_tv.setText(message.getPraise() + "");
|
|
|
+ final boolean isPraise = message.getIsPraise() != 1;
|
|
|
+ holder.command_tv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if (listener == null) return;
|
|
|
+ listener.onClick(i, message.getMessageId(), message.getUserId(), message.getNickName());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ holder.like_tv.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ praiseOrCancle(i, isPraise);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
+ if (comments == null || comments.size() <= 0) {
|
|
|
+ holder.comment_tag.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ holder.command_tv.setText(comments.size() + "");
|
|
|
+ mAdapter = new CommentAdapter(comments);
|
|
|
+ holder.command_lv.setAdapter(mAdapter);
|
|
|
}
|
|
|
|
|
|
class ViewHolder {
|
|
|
- ImageView avatar_img, //头像
|
|
|
- operation_more_img;//弹出点赞框
|
|
|
- TextView nick_name_tv,//名字
|
|
|
- body_tv,//内容
|
|
|
+ ImageView avatar_img; //头像
|
|
|
+ TextView name_tv,//名字
|
|
|
+ content_tv,//内容
|
|
|
time_tv, //发表时间
|
|
|
- delete_tv, //删除按钮
|
|
|
- location_tv;//地址
|
|
|
- TextView multi_praise_tv;//点赞
|
|
|
- View img_praise_line;//线
|
|
|
- MyListView command_listView;
|
|
|
+ like_tv, //点赞按钮
|
|
|
+ command_tv;//评论
|
|
|
+ MyListView command_lv;
|
|
|
+ LinearLayout comment_tag;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //评论适配器
|
|
|
+ public class CommentAdapter extends BaseAdapter {
|
|
|
+ private int messagePosition;
|
|
|
+ private List<Comment> datas;
|
|
|
+
|
|
|
+ public CommentAdapter(int messagePosition, List<Comment> datas) {
|
|
|
+ this.messagePosition = messagePosition;
|
|
|
+ this.datas = datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CommentAdapter(List<Comment> datas) {
|
|
|
+ this.datas = datas;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return datas.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getItem(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public long getItemId(int position) {
|
|
|
+ return position;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
+ ViewHolder holder = null;
|
|
|
+ if (convertView == null) {
|
|
|
+ holder = new ViewHolder();
|
|
|
+ convertView = LayoutInflater.from(context).inflate(R.layout.p_msg_comment_list_item, null);
|
|
|
+ holder.text_view = (TextView) convertView.findViewById(R.id.text_view);
|
|
|
+ convertView.setTag(holder);
|
|
|
+ } else {
|
|
|
+ holder = (ViewHolder) convertView.getTag();
|
|
|
+ }
|
|
|
+ final Comment comment = datas.get(position);
|
|
|
+ SpannableStringBuilder builder = new SpannableStringBuilder();
|
|
|
+ String showName = comment.getNickName();
|
|
|
+ UserClickableSpan.setClickableSpan(context, builder, showName, comment.getUserId());// 设置评论者的ClickSpanned
|
|
|
+ if (!TextUtils.isEmpty(comment.getToUserId()) && !TextUtils.isEmpty(comment.getToNickname())) {
|
|
|
+ builder.append(context.getString(R.string.replay));
|
|
|
+ String toShowName = comment.getToNickname();
|
|
|
+ UserClickableSpan.setClickableSpan(context, builder, toShowName, comment.getToUserId());// 设置被评论者的ClickSpanned
|
|
|
+ }
|
|
|
+
|
|
|
+ builder.append(":");
|
|
|
+ // 设置评论内容
|
|
|
+ String commentBody = comment.getBody();
|
|
|
+ if (!TextUtils.isEmpty(commentBody)) {
|
|
|
+ commentBody = StringUtils.replaceSpecialChar(comment.getBody());
|
|
|
+ CharSequence charSequence = HtmlUtils.transform200SpanString(commentBody.replaceAll("\n", "\r\n"),
|
|
|
+ true);
|
|
|
+ builder.append(charSequence);
|
|
|
+ }
|
|
|
+ holder.text_view.setText(builder);
|
|
|
+ holder.text_view.setLinksClickable(true);
|
|
|
+ holder.text_view.setMovementMethod(LinkMovementClickMethod.getInstance());
|
|
|
+ holder.text_view.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ //点击操作
|
|
|
+ Log.i("gongpengming", "点击了" + comment.getBody());
|
|
|
+// if (comment.getUserId().equals(mLoginUserId)) {// 如果消息是我发的,那么就弹出删除和复制的对话框
|
|
|
+// showCommentLongClickDialog(messagePosition, position, CommentAdapter.this);
|
|
|
+// } else {// 弹出回复的框
|
|
|
+// String toShowName = getShowName(comment.getUserId(), comment.getNickName());
|
|
|
+// // 懒得写回调的,直接强转,以后如果不适用,可以写个接口回调
|
|
|
+// if (context instanceof BusinessCircleActivity) {
|
|
|
+// ((BusinessCircleActivity) mContext).showCommentEnterView(messagePosition,
|
|
|
+// comment.getUserId(), comment.getNickName(), toShowName);
|
|
|
+//
|
|
|
+// } else {
|
|
|
+// ((MainActivity) context).getBusinessCircleFragment().showCommentEnterView(messagePosition,
|
|
|
+// comment.getUserId(), comment.getNickName(), toShowName);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ holder.text_view.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onLongClick(View v) {
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return convertView;
|
|
|
+ }
|
|
|
+
|
|
|
+ class ViewHolder {
|
|
|
+ TextView text_view;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ButtonViewListener listener;
|
|
|
+
|
|
|
+ public void setButtonViewListener(ButtonViewListener listener) {
|
|
|
+ this.listener = listener;
|
|
|
+ }
|
|
|
+
|
|
|
+ public interface ButtonViewListener {
|
|
|
+ void onClick(int i, String messageId, String userId, String nickName);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 赞或者取消赞
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @param isPraise
|
|
|
+ */
|
|
|
+ private void praiseOrCancle(final int position, final boolean isPraise) {
|
|
|
+ pon = position;
|
|
|
+ //参数
|
|
|
+ final PublicMessage message = messages.get(position);
|
|
|
+ String requestUrl = null;
|
|
|
+ if (isPraise) {
|
|
|
+ requestUrl = MyApplication.getInstance().getConfig().MSG_PRAISE_ADD;
|
|
|
+ } else {
|
|
|
+ requestUrl = MyApplication.getInstance().getConfig().MSG_PRAISE_DELETE;
|
|
|
+ }
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
+ params.put("access_token", MyApplication.getInstance().mAccessToken);
|
|
|
+ params.put("messageId", message.getMessageId());
|
|
|
+ ViewUtil.httpSendRequest(context, requestUrl, params, handler, null, PRAISE_WHAT, null, null, "get");
|
|
|
}
|
|
|
}
|