diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatAdapter.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatAdapter.java index 3aef2dc..758ad9b 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatAdapter.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatAdapter.java @@ -25,16 +25,16 @@ public class ChatAdapter extends RecyclerView.Adapter { //Log需要的TAG private static final String TAG = "ChatAdapter & NLChat"; - private static final int VIEW_TYPE_MESSAGE_SENT = 1; //正常的消息,发 private static final int VIEW_TYPE_MESSAGE_RECEIVED = 2; //正常的消息,收 + private static final int VIEW_TYPE_MESSAGE_SENT = 1; //正常的消息,发 - private static final int VIEW_TYPE_MESSAGE_SENT_BURN = 3; //正常的消息,发,阅后即焚 private static final int VIEW_TYPE_MESSAGE_RECEIVED_BURN = 4; //正常的消息,收,阅后即焚 + private static final int VIEW_TYPE_MESSAGE_SENT_BURN = 3; //正常的消息,发,阅后即焚 private static final int VIEW_TYPE_DEBUG_RECEIVED = 5; //Debug消息 - private static final int VIEW_TYPE_MESSAGE_SENT_LATEST = -1; //数据库消息记录,发 private static final int VIEW_TYPE_MESSAGE_RECEIVED_LATEST = -2; //数据库消息记录,收 + private static final int VIEW_TYPE_MESSAGE_SENT_LATEST = -1; //数据库消息记录,发 private static final int VIEW_TYPE_HAOHANYH = 255; //彩蛋Debug @@ -56,6 +56,10 @@ public int getItemViewType(int position) { return VIEW_TYPE_MESSAGE_RECEIVED; } else if (message.isMe()) { return VIEW_TYPE_MESSAGE_SENT; + } else if (message.isUserBurn()) { + return VIEW_TYPE_MESSAGE_RECEIVED_BURN; + } else if (message.isMeBurn()) { + return VIEW_TYPE_MESSAGE_SENT_BURN; } else if (message.isDebug()) { return VIEW_TYPE_DEBUG_RECEIVED; } else if (message.isSQLiteUser()) { @@ -80,6 +84,14 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_chat_sent, parent, false); return new SentMessageHolder(view); + case VIEW_TYPE_MESSAGE_RECEIVED_BURN: + view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_chat_received, parent, false); + return new ReceivedMessageBurnHolder(view); + case VIEW_TYPE_MESSAGE_SENT_BURN: + view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_chat_sent, parent, false); + return new SentMessageBurnHolder(view); case VIEW_TYPE_DEBUG_RECEIVED: view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_debug, parent, false); @@ -104,11 +116,16 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ChatUtilsForMessage message = chatUtilsForMessages.get(position); int viewType = holder.getItemViewType(); + Log.d(TAG, "绑定数据到 ViewHolder: viewType = " + viewType + ", holder class = " + holder.getClass().getName()); - if (viewType == VIEW_TYPE_MESSAGE_SENT) { - ((SentMessageHolder) holder).bind(message); - } else if (viewType == VIEW_TYPE_MESSAGE_RECEIVED) { + if (viewType == VIEW_TYPE_MESSAGE_RECEIVED) { ((ReceivedMessageHolder) holder).bind(message); + } else if (viewType == VIEW_TYPE_MESSAGE_SENT) { + ((SentMessageHolder) holder).bind(message); + } else if (viewType == VIEW_TYPE_MESSAGE_RECEIVED_BURN) { + ((ReceivedMessageBurnHolder) holder).bind(message); + } else if (viewType == VIEW_TYPE_MESSAGE_SENT_BURN) { + ((SentMessageBurnHolder) holder).bind(message); } else if (viewType == VIEW_TYPE_DEBUG_RECEIVED) { ((ReceivedDEBUGMessageHolder) holder).bind(message); } else if (viewType == VIEW_TYPE_MESSAGE_SENT_LATEST) { @@ -128,6 +145,25 @@ public int getItemCount() { // todo 发送消息和接收消息每一方,如果消息有特殊情况比如enter,uuid会查询不到,目前这个bug打算后续修复。 + // 接收消息的ViewHolder + private class ReceivedMessageHolder extends RecyclerView.ViewHolder { + TextView messageText,timestampText; + + ReceivedMessageHolder(View itemView) { + super(itemView); + messageText = itemView.findViewById(R.id.text_message_body); + timestampText = itemView.findViewById(R.id.text_message_time); + + // 设置自定义字体 + ChatUIFontUtils.applyCustomFont(context, messageText); + } + + void bind(ChatUtilsForMessage message) { + messageText.setText(message.getMessage()); + timestampText.setText(message.getTimestamp()); + } + } + // 发送消息的ViewHolder private class SentMessageHolder extends RecyclerView.ViewHolder { TextView messageText,timestampText; @@ -139,6 +175,25 @@ private class SentMessageHolder extends RecyclerView.ViewHolder { // 设置自定义字体 ChatUIFontUtils.applyCustomFont(context, messageText); + } + + void bind(ChatUtilsForMessage message) { + messageText.setText(message.getMessage()); + timestampText.setText(message.getTimestamp()); + } + } + + // 接收消息的ViewHolder(阅后即焚) + private class ReceivedMessageBurnHolder extends RecyclerView.ViewHolder { + TextView messageText,timestampText; + + ReceivedMessageBurnHolder(View itemView) { + super(itemView); + messageText = itemView.findViewById(R.id.text_message_body); + timestampText = itemView.findViewById(R.id.text_message_time); + + // 设置自定义字体 + ChatUIFontUtils.applyCustomFont(context, messageText); messageText.setOnLongClickListener(new View.OnLongClickListener() { @Override @@ -146,7 +201,7 @@ public boolean onLongClick(View view) { Toast.makeText(context, messageText.getText().toString(), Toast.LENGTH_SHORT).show(); String message = messageText.getText().toString(); - String sender = "Me"; // 这里需要替换为实际的发送者 + String sender = "User"; // 这里需要替换为实际的发送者 String timestamp = ChatTimestamp.getLastTimestamp(); // 获取缓存的时间戳 @@ -177,11 +232,11 @@ void bind(ChatUtilsForMessage message) { } } - // 接收消息的ViewHolder - private class ReceivedMessageHolder extends RecyclerView.ViewHolder { + // 发送消息的ViewHolder(阅后即焚) + private class SentMessageBurnHolder extends RecyclerView.ViewHolder { TextView messageText,timestampText; - ReceivedMessageHolder(View itemView) { + SentMessageBurnHolder(View itemView) { super(itemView); messageText = itemView.findViewById(R.id.text_message_body); timestampText = itemView.findViewById(R.id.text_message_time); @@ -195,7 +250,7 @@ public boolean onLongClick(View view) { Toast.makeText(context, messageText.getText().toString(), Toast.LENGTH_SHORT).show(); String message = messageText.getText().toString(); - String sender = "User"; // 这里需要替换为实际的发送者 + String sender = "Me"; // 这里需要替换为实际的发送者 String timestamp = ChatTimestamp.getLastTimestamp(); // 获取缓存的时间戳 @@ -226,7 +281,6 @@ void bind(ChatUtilsForMessage message) { } } - // 接收DEBUG消息的ViewHolder private class ReceivedDEBUGMessageHolder extends RecyclerView.ViewHolder { TextView messageText; diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForMessage.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForMessage.java index 492112c..5fbec74 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForMessage.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForMessage.java @@ -9,7 +9,6 @@ public class ChatUtilsForMessage { private String message; private String timestamp; private int loglevel; - private String uuid; private boolean isUser; private boolean isMe; @@ -17,6 +16,8 @@ public class ChatUtilsForMessage { private boolean isSQLiteUser; private boolean isSQLiteMe; private boolean isSQLiteDebug; + private boolean isUserBurn; + private boolean isMeBurn; /** * 构造方法,适用于User消息 @@ -46,12 +47,12 @@ public ChatUtilsForMessage(String message, boolean isMe, String timestamp) { * 构造方法,适用于User消息(阅后即焚) * @param message User消息 * @param timestamp User消息时间 - * @param isUser 传参 + * @param isUserBurn 传参 */ - public ChatUtilsForMessage(String message, String timestamp, boolean isUser, String uuid) { + public ChatUtilsForMessage(String message, String timestamp, boolean isUserBurn, String uuid) { this.message = message; this.timestamp = timestamp; - this.isUser = isUser; + this.isUserBurn = isUserBurn; chatMessageUUID = new ChatMessageUUID(); chatMessageUUID.setUUID(uuid); @@ -60,13 +61,13 @@ public ChatUtilsForMessage(String message, String timestamp, boolean isUser, Str /** * 构造方法,适用于Me消息(阅后即焚) * @param message Me消息 - * @param isMe 传参 + * @param isMeBurn 传参 * @param timestamp Me消息时间 */ - public ChatUtilsForMessage(String message, boolean isMe, String timestamp, String uuid) { + public ChatUtilsForMessage(String message, boolean isMeBurn, String timestamp, String uuid) { this.message = message; this.timestamp = timestamp; - this.isMe = isMe; + this.isMeBurn = isMeBurn; chatMessageUUID = new ChatMessageUUID(); chatMessageUUID.setUUID(uuid); @@ -149,4 +150,12 @@ public boolean isSQLiteMe() { public boolean isSQLiteDebug() { return isSQLiteDebug; } + + public boolean isUserBurn() { + return isUserBurn; + } + + public boolean isMeBurn() { + return isMeBurn; + } } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 8c906b1..747b85a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -910,7 +910,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" - android:checked="false" + android:checked="true" android:fontFamily="sans-serif-medium" android:text="@string/uiNearLinkSettingsForWord" android:textColor="@color/Pink_is_fancy" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 83ced23..cf29a52 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ NLChat com.haohanyh.linmengjia.nearlink.nlchat.fun - 1.3.333.2024.0729 + 1.3.335.2024.0730 NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。 友情感谢