语圈基本完成

2、个人主页完成
This commit is contained in:
2025-06-07 09:00:24 +08:00
parent c24fb05d51
commit c9f5c59ba8
186 changed files with 7140 additions and 1889 deletions

View File

@@ -8,14 +8,34 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.TimeUtils;
import com.qxcm.moduleutil.R;
import com.qxcm.moduleutil.bean.CommentBean;
import java.util.List;
public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ReplyViewHolder> {
public interface OnReplyClickListener {
void onReplyClick(CommentBean.CommentDetailsBean.Replies reply, int position);
}
// 添加回调接口
public interface OnReplyLongClickListener {
void onReplyLongClick(CommentBean.CommentDetailsBean.Replies reply, int position);
}
private OnReplyLongClickListener longClickListener;
public void setOnReplyLongClickListener(OnReplyLongClickListener listener) {
this.longClickListener = listener;
}
private OnReplyClickListener listener;
// 设置监听器的方法
public void setOnReplyClickListener(OnReplyClickListener listener) {
this.listener = listener;
}
private List<CommentBean.CommentDetailsBean.Replies> replyList;
private boolean isExpanded = false; // 是否展开显示所有评论
public ReplyAdapter(List<CommentBean.CommentDetailsBean.Replies> replyList) {
this.replyList = replyList;
@@ -37,27 +57,60 @@ public class ReplyAdapter extends RecyclerView.Adapter<ReplyAdapter.ReplyViewHol
@Override
public void onBindViewHolder(@NonNull ReplyViewHolder holder, int position) {
CommentBean.CommentDetailsBean.Replies reply = replyList.get(position);
holder.bind(reply);
if (!isExpanded && position >= 2) {
return; // 不绑定数据
}
holder.bind(reply,position, listener,longClickListener);
}
public void setExpanded(boolean expanded) {
isExpanded = expanded;
notifyDataSetChanged(); // 刷新适配器
}
@Override
public int getItemCount() {
return replyList.size();
return isExpanded ? replyList.size() : Math.min(2, replyList.size());
}
static class ReplyViewHolder extends RecyclerView.ViewHolder {
private TextView tvNickname;
private TextView tvContent;
private TextView btnReply;
private TextView tvTime;
public ReplyViewHolder(@NonNull View itemView) {
super(itemView);
// tvNickname = itemView.findViewById(R.id.tv_reply_nickname);
// tvContent = itemView.findViewById(R.id.tv_reply_content);
tvNickname = itemView.findViewById(R.id.tv_name);
tvContent = itemView.findViewById(R.id.tv_reply);
btnReply = itemView.findViewById(R.id.btn_reply);
tvTime = itemView.findViewById(R.id.tv_time);
}
public void bind(CommentBean.CommentDetailsBean.Replies reply) {
tvNickname.setText(reply.getNickname());
public void bind(CommentBean.CommentDetailsBean.Replies reply,int position, OnReplyClickListener listener,OnReplyLongClickListener longClickListener) {
tvNickname.setText(reply.getNickname()+":" +(reply.getReply_to_user()!=null?reply.getReply_to_user():""));
tvContent.setText(reply.getContent());
tvTime.setText(TimeUtils.millis2String(Long.parseLong(reply.getCreatetime()+"") * 1000));
btnReply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (listener != null) {
listener.onReplyClick(reply, position);
}
}
});
// 添加长按监听
itemView.setOnLongClickListener(v -> {
if (longClickListener != null) {
longClickListener.onReplyLongClick(reply, position);
return true; // 消费事件
}
return false;
});
}
}
}