Skip to content

Commit

Permalink
🎉Release 1.3,ChatCore对阅后即焚相关功能修改(功能8月见面)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 29, 2024
1 parent 24573c2 commit 1e5b3af
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public class ChatAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
//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

Expand All @@ -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()) {
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -139,14 +175,33 @@ 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
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(); // 获取缓存的时间戳

Expand Down Expand Up @@ -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);
Expand All @@ -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(); // 获取缓存的时间戳

Expand Down Expand Up @@ -226,7 +281,6 @@ void bind(ChatUtilsForMessage message) {
}
}


// 接收DEBUG消息的ViewHolder
private class ReceivedDEBUGMessageHolder extends RecyclerView.ViewHolder {
TextView messageText;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ public class ChatUtilsForMessage {
private String message;
private String timestamp;
private int loglevel;
private String uuid;

private boolean isUser;
private boolean isMe;
private boolean isDebug;
private boolean isSQLiteUser;
private boolean isSQLiteMe;
private boolean isSQLiteDebug;
private boolean isUserBurn;
private boolean isMeBurn;

/**
* 构造方法,适用于User消息
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -149,4 +150,12 @@ public boolean isSQLiteMe() {
public boolean isSQLiteDebug() {
return isSQLiteDebug;
}

public boolean isUserBurn() {
return isUserBurn;
}

public boolean isMeBurn() {
return isMeBurn;
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name">NLChat</string>
<string name="app_package">com.haohanyh.linmengjia.nearlink.nlchat.fun</string>
<string name="app_version">1.3.333.2024.0729</string>
<string name="app_version">1.3.335.2024.0730</string>

<string name="appwarn">NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。</string>
<string name="thanks3q">友情感谢</string>
Expand Down

0 comments on commit 1e5b3af

Please sign in to comment.