From 685eddc2d932a682ccf1c14d8d11f7e18c19e83b Mon Sep 17 00:00:00 2001 From: Hny0305Lin <1553809191@qq.com> Date: Tue, 9 Jul 2024 19:43:43 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=89Release=201.3=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=96=B0UI=E9=A1=B5=E9=9D=A2=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E4=B8=B2=E5=8F=A3=EF=BC=8C=E6=96=B0UI=E9=80=82=E9=85=8D?= =?UTF-8?q?=E5=99=A8=E5=87=BD=E6=95=B0=E8=B0=83=E6=95=B4=EF=BC=8C=E9=AB=98?= =?UTF-8?q?=E9=A2=91=E6=B3=A2=E7=89=B9=E7=8E=87=E5=8F=96=E6=B6=88BETA?= =?UTF-8?q?=EF=BC=8C=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9B=B8=E5=85=B3=E6=96=B0?= =?UTF-8?q?=E5=A2=9EDebug=EF=BC=8C=E8=B0=83=E6=95=B4=E4=B8=BB=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nlchat/fun/ChatCore/ChatAdapter.java | 28 ++++++- .../nlchat/fun/ChatCore/ChatMessage.java | 27 ++++-- .../fun/ChatCore/ChatMessageQueueUpdater.java | 27 ++++-- .../ChatSaveMessageDatabaseManager.java | 10 +++ .../nlchat/fun/ChatCore/ChatUIUpdater.java | 82 +++++++++++++++++++ .../nlchat/fun/ChatCore/ChatUtils.java | 2 +- .../nearlink/nlchat/fun/MainActivity.java | 54 ++++++------ .../nlchat/fun/SQLite/SQLiteDataBaseAPP.java | 20 +++++ .../bg_chat_bubble_wechat_received.xml | 3 + .../drawable/bg_chat_bubble_wechat_sent.xml | 3 + .../main/res/layout/item_chat_received.xml | 10 ++- app/src/main/res/layout/item_chat_sent.xml | 4 +- app/src/main/res/layout/item_debug.xml | 2 + app/src/main/res/values/strings.xml | 2 +- 14 files changed, 224 insertions(+), 50 deletions(-) create mode 100644 app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUIUpdater.java 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 5ae4592..a32d1fc 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 @@ -18,6 +18,7 @@ public class ChatAdapter extends RecyclerView.Adapter { private static final int VIEW_TYPE_MESSAGE_SENT = 1; private static final int VIEW_TYPE_MESSAGE_RECEIVED = 2; + private static final int VIEW_TYPE_DEBUG_RECEIVED = 3; private List chatMessages; private Context context; @@ -32,8 +33,10 @@ public ChatAdapter(Context context, List chatMessages) { @Override public int getItemViewType(int position) { ChatMessage message = chatMessages.get(position); - if (message.isSent()) { + if (message.isUser()) { return VIEW_TYPE_MESSAGE_RECEIVED; + } else if (message.isDebug()) { + return VIEW_TYPE_DEBUG_RECEIVED; } else { return VIEW_TYPE_MESSAGE_SENT; } @@ -46,6 +49,10 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_chat_sent, parent, false); return new SentMessageHolder(view); + } else if (viewType == VIEW_TYPE_DEBUG_RECEIVED) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_debug, parent, false); + return new ReceivedDEBUGMessageHolder(view); } else { View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_chat_received, parent, false); @@ -59,6 +66,8 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { ChatMessage message = chatMessages.get(position); if (holder.getItemViewType() == VIEW_TYPE_MESSAGE_SENT) { ((SentMessageHolder) holder).bind(message); + } else if (holder.getItemViewType() == VIEW_TYPE_DEBUG_RECEIVED) { + ((ReceivedDEBUGMessageHolder) holder).bind(message); } else { ((ReceivedMessageHolder) holder).bind(message); } @@ -89,6 +98,23 @@ void bind(ChatMessage message) { } } + // 接收DEBUG消息的ViewHolder + private class ReceivedDEBUGMessageHolder extends RecyclerView.ViewHolder { + TextView messageText; + + ReceivedDEBUGMessageHolder(View itemView) { + super(itemView); + messageText = itemView.findViewById(R.id.text_message_body); + + // 设置自定义字体 + ChatUIFontUtils.applyCustomFont(context, messageText); + } + + void bind(ChatMessage message) { + messageText.setText(message.getMessage()); + } + } + // 接收消息的ViewHolder private class ReceivedMessageHolder extends RecyclerView.ViewHolder { TextView messageText,timestampText; diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessage.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessage.java index 14e4daf..3393f23 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessage.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessage.java @@ -4,12 +4,25 @@ public class ChatMessage { private String message; private String timestamp; - private boolean isSent; + private boolean isUser; + private boolean isDebug; + private boolean isMe; - public ChatMessage(String message, String timestamp, boolean isSent) { + public ChatMessage(String message, String timestamp, boolean isUser) { this.message = message; this.timestamp = timestamp; - this.isSent = isSent; + this.isUser = isUser; + } + + public ChatMessage(String message, boolean isDebug) { + this.message = message; + this.isDebug = isDebug; + } + + public ChatMessage(String message, boolean isMe, String timestamp) { + this.message = message; + this.timestamp = timestamp; + this.isMe = isMe; } public String getMessage() { @@ -20,7 +33,11 @@ public String getTimestamp() { return timestamp; } - public boolean isSent() { - return isSent; + public boolean isUser() { + return isUser; } + + public boolean isDebug() { return isDebug; } + + public boolean isMe() { return isMe; } } \ No newline at end of file diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessageQueueUpdater.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessageQueueUpdater.java index 1bff35e..40621c5 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessageQueueUpdater.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatMessageQueueUpdater.java @@ -50,7 +50,7 @@ public ChatMessageQueueUpdater(TextView textView, Queue messageQueue, Li @SuppressLint("NotifyDataSetChanged") public void updateTextView() { StringBuilder allMessages = new StringBuilder(); - List newMessages = new ArrayList<>(); //使用临时列表,服务NewUI + List newMessages = new ArrayList<>(); // 使用临时列表,服务NewUI Iterator iterator = messageQueue.iterator(); while (iterator.hasNext()) { @@ -68,15 +68,28 @@ public void updateTextView() { // 新UI处理,将新消息添加到 chatMessages 列表中 for (String newMessage : newMessages) { - boolean isUser = logPrefix.contains("User: "); - String timestamp = chatTimestamp.getCurrentTimestamp(); // 获取当前时间戳 - chatMessages.add(new ChatMessage(newMessage, timestamp, isUser)); + boolean isUser = logPrefix.equals("User: "); + boolean isDebug = logPrefix.equals("Debug: "); + boolean isMe = logPrefix.equals("Me: "); + Log.v(TAG, "isUser:" + isUser); + Log.v(TAG, "isDebug:" + isDebug); + Log.v(TAG, "isMe:" + isMe); + if (isUser) { + String timestamp = chatTimestamp.getCurrentTimestamp(); // 获取当前时间戳 + chatMessages.add(new ChatMessage(newMessage, timestamp, isUser)); + } else if (isDebug) { + chatMessages.add(new ChatMessage(newMessage, isDebug)); + } else if (isMe) { + String timestamp = chatTimestamp.getCurrentTimestamp(); // 获取当前时间戳 + chatMessages.add(new ChatMessage(newMessage, isMe, timestamp)); + } } chatAdapter.updateMessages(chatMessages, recyclerView); // 更新消息并滚动到底部 // 旧UI处理 - textView.setText(allMessages.toString()); - Log.i(TAG, logPrefix + "消息队列有改动"); - //在处理完所有消息后,清空 messageQueue,确保不会重复处理相同的消息。 + // textView.setText(allMessages.toString()); + // Log.i(TAG, logPrefix + "消息队列有改动"); + // 在处理完所有消息后,清空 messageQueue,确保不会重复处理相同的消息。 messageQueue.clear(); } + } diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatSaveMessageDatabaseManager.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatSaveMessageDatabaseManager.java index cf0113e..860b31a 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatSaveMessageDatabaseManager.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatSaveMessageDatabaseManager.java @@ -33,4 +33,14 @@ public void saveMessageToDatabase(String timestamp, String message, String sende dbHelper.saveVersionToDatabase(context.getString(R.string.app_version)); Log.i(TAG, "当前数据库保存内容:\n消息内容" + message + "\n用户名" + sender + "\n时间戳" + timestamp); // 打印内容到日志 } + + public void saveDebugMessageToDatabase(String timestamp, String message, String sender) { + //检索是否有空消息,串口通讯时常有相关问题 + if (message == null || message.trim().isEmpty()) { + return; + } + //如果有消息再保存,上面是没消息不予保存 + dbHelper.saveDebugToDatabase(message, sender, timestamp); + Log.i(TAG, "当前数据库保存内容:\n消息内容" + message + "\n用户名" + sender + "\n时间戳" + timestamp); // 打印内容到日志 + } } diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUIUpdater.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUIUpdater.java new file mode 100644 index 0000000..2adb4e4 --- /dev/null +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUIUpdater.java @@ -0,0 +1,82 @@ +/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://github.com/Hny0305Lin/LICENSE/blob/main/LICENSE */ +package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore; + +import android.app.Activity; +import android.content.Context; +import android.widget.TextView; + +import com.haohanyh.linmengjia.nearlink.nlchat.fun.MainAPP; + +import java.util.Queue; + +public class ChatUIUpdater { + private Context context; + private ChatSaveMessageDatabaseManager chatSaveMessageDatabaseManager; + private ChatTimestamp chatTimestamp; + private Queue serverMessageQueue; + private Queue serverDebugQueue; + private ChatMessageQueueUpdater serverUpdater; + private ChatMessageQueueUpdater serverDebugUpdater; + private TextView NearLinkUserText; + private static final int MAX_MESSAGES = 8; // 假设的最大消息数 + + public ChatUIUpdater(Context context, + ChatSaveMessageDatabaseManager chatSaveMessageDatabaseManager, + ChatTimestamp chatTimestamp, + Queue serverMessageQueue, + Queue serverDebugQueue, + ChatMessageQueueUpdater serverUpdater, + ChatMessageQueueUpdater serverDebugUpdater, + TextView NearLinkUserText) { + this.context = context; + this.chatSaveMessageDatabaseManager = chatSaveMessageDatabaseManager; + this.chatTimestamp = chatTimestamp; + this.serverMessageQueue = serverMessageQueue; + this.serverDebugQueue = serverDebugQueue; + this.serverUpdater = serverUpdater; + this.serverDebugUpdater = serverDebugUpdater; + this.NearLinkUserText = NearLinkUserText; + } + + public void updateUI(String processedString) { + // 处理完再打印到UI上 + ((Activity) context).runOnUiThread(() -> { + // 如果需要存储到数据库中 + if (ChatUtils.isSqlitemanager()) { + String timestamp = chatTimestamp.saveCurrentTimestamp(); + if (ChatUtils.isShowUartLog()) { + // 如果是debuglog,则分开存储 + chatSaveMessageDatabaseManager.saveDebugMessageToDatabase(timestamp, processedString, "UserDebug"); + } else { + chatSaveMessageDatabaseManager.saveMessageToDatabase(timestamp, processedString, "User"); + } + } + // 如果需要UI滚动消息 + if (ChatUtils.isScrollingMessages()) { + if (ChatUtils.isShowUartLog()) { + if (serverDebugQueue.size() >= MAX_MESSAGES) { + serverDebugQueue.poll(); + } + serverDebugQueue.add(processedString); + serverDebugUpdater.updateTextView(); + MainAPP.Vibrate(context); + } else { + if (serverMessageQueue.size() >= MAX_MESSAGES) { + serverMessageQueue.poll(); + } + serverMessageQueue.add(processedString); + serverUpdater.updateTextView(); + MainAPP.Vibrate(context); + } + } else { + NearLinkUserText.append(processedString); + if (NearLinkUserText.length() > 2048) { + String str = NearLinkUserText.getText().toString().substring(NearLinkUserText.getText().length() - 1024, NearLinkUserText.getText().length()); + NearLinkUserText.setText(""); + NearLinkUserText.append(str); + } + MainAPP.Vibrate(context); + } + }); + } +} diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtils.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtils.java index 995f89a..df90f99 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtils.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtils.java @@ -3,7 +3,7 @@ public class ChatUtils { //这里设置的是UI相关,是否做到消息滚动展示在UI上,而不是全部展示,全部展示会占用大量UI资源 - private static boolean showUartLog = false; // 控制是否启用显示串口Log,打印在UI上(开发者使用) + private static boolean showUartLog = true; // 控制是否启用显示串口Log,打印在UI上(开发者使用) private static final boolean scrollingMessages = true; // 控制是否启用滚动消息功能 private static boolean clipMessages = true; // 控制是否启用剪贴板功能 private static final boolean uiNewOrOld = true; // 控制是否启用新UI(一般为True) diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java index 2a98816..f19c813 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java @@ -62,6 +62,7 @@ import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIAlertDialog; import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIAnimationUtils; import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIBackgroundUtils; +import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIUpdater; import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUtils; import com.haohanyh.linmengjia.nearlink.nlchat.fun.Premission.NearLinkChatGetSomePermission; import com.haohanyh.linmengjia.nearlink.nlchat.fun.R.array; @@ -111,7 +112,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe private Message MessageTV_Text; private TextView APPRunResult,MobileUSBResult,UARTResult; private AppCompatTextView NearLinkUserTitle; - private TextView NearLinkUserText,NearLinkMeText; + private TextView NearLinkUserText,NearLinkDebug,NearLinkMeText; private EditText EditChatSend,EditChatSendNewUI; private Resources resources; @@ -138,11 +139,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe //聊天相关 private Queue serverMessageQueue = new LinkedList<>(); + private Queue serverDebugQueue = new LinkedList<>(); private Queue clientMessageQueue = new LinkedList<>(); private static final int MAX_MESSAGES = 8; // 设置最大消息数量 private ChatMessageQueueUpdater serverUpdater; + private ChatMessageQueueUpdater serverDebugUpdater; private ChatMessageQueueUpdater clientUpdater; private ChatSaveMessageDatabaseManager chatSaveMessageDatabaseManager; + private ChatUIUpdater chatUIUpdater; //聊天时间戳 private ChatTimestamp chatTimestamp = new ChatTimestamp(); @@ -361,9 +365,13 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent //聊天初始化 serverUpdater = new ChatMessageQueueUpdater(NearLinkUserText, serverMessageQueue, chatMessages, chatAdapter, "User: ", recyclerView); - clientUpdater = new ChatMessageQueueUpdater(NearLinkMeText, clientMessageQueue, chatMessages, chatAdapter,"Me: ", recyclerView); + serverDebugUpdater = new ChatMessageQueueUpdater(NearLinkDebug, serverDebugQueue, chatMessages, chatAdapter, "Debug: ", recyclerView); + clientUpdater = new ChatMessageQueueUpdater(NearLinkMeText, clientMessageQueue, chatMessages, chatAdapter, "Me: ", recyclerView); //聊天数据库初始化 chatSaveMessageDatabaseManager = new ChatSaveMessageDatabaseManager(MainActivity.this); + //聊天核心初始化 + chatUIUpdater = new ChatUIUpdater(this, chatSaveMessageDatabaseManager, chatTimestamp, serverMessageQueue, serverDebugQueue, serverUpdater, serverDebugUpdater, NearLinkUserText); + //星闪网络相关设置初始化,目前多数还不允许UI设置,敬请期待 CompoundButton.OnCheckedChangeListener SettingsChangeListener = new CompoundButton.OnCheckedChangeListener() { @@ -575,7 +583,8 @@ private void loadMessagesFromDatabase() { private void NearLinkChatReadData() { //先播报星闪软件情况,已经UART接入星闪网络,再好好的处理字符 HhandlerI.sendEmptyMessage(10); - StringBuffer stringBuffer = new StringBuffer(); + + //监听 MainAPP.CH34X.setReadListener(bytes -> { //字节转文本 //String string = StringUtils.needProcess().bytesToString(bytes); @@ -583,32 +592,8 @@ private void NearLinkChatReadData() { Log.v(TAG, "长度:bytes.length="+ bytes.length + "\t内容:" + string); //进行文本处理 String processedString = CH34xProcessingForReadData(string); - stringBuffer.append(processedString); - //处理完再打印到UI上 - runOnUiThread(() -> { - //如果需要存储到数据库中 - if (ChatUtils.isSqlitemanager()) { - String timestamp = chatTimestamp.saveCurrentTimestamp(); - chatSaveMessageDatabaseManager.saveMessageToDatabase(timestamp, processedString, "User"); - } - //如果需要UI滚动消息 - if (ChatUtils.isScrollingMessages()) { - if (serverMessageQueue.size() >= MAX_MESSAGES) { - serverMessageQueue.poll(); - } - serverMessageQueue.add(processedString); - serverUpdater.updateTextView(); - MainAPP.Vibrate(this); - } else { - NearLinkUserText.append(processedString); - if (NearLinkUserText.length() > 2048) { - String str = NearLinkUserText.getText().toString().substring(NearLinkUserText.getText().length() - 1024, NearLinkUserText.getText().length()); - NearLinkUserText.setText(""); - NearLinkUserText.append(str); - } - MainAPP.Vibrate(this); - } - }); + // 使用ChatUIUpdater更新UI + chatUIUpdater.updateUI(processedString); }); } @@ -643,7 +628,7 @@ private String CH34xProcessingForReadData(String string) { ChatProcessorForExtract.processChat(context, completeSecondData); } - return completeSecondData; + ChatUtils.setShowUartLog(false);return completeSecondData; } else if (completeFirstData.contains(ChatUtils.getPrefixLogNotConnectedServer())) { Log.w(TAG, "串口Log内容:" + completeFirstData); if (completeFirstData.startsWith(ChatUtils.getPrefixLogNotConnectedServer())) @@ -657,27 +642,33 @@ private String CH34xProcessingForReadData(String string) { if (completeFirstData.contains(ChatUtils.getPrefixLogConnected())) { Log.d(TAG, "连接日志:" + completeFirstData); // 处理连接日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogDisconnected())) { Log.d(TAG, "断开连接日志:" + completeFirstData); // 处理断开连接日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogAcore())) { Log.d(TAG, "ACore日志:" + completeFirstData); // 处理ACore日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } //UART服务器日志,以下可以读取星闪日志 if (completeFirstData.contains(ChatUtils.getPrefixLogSleUartServer())) { Log.d(TAG, "UART服务器日志:" + completeFirstData); // 处理UART服务器日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogConnectStateChanged())) { Log.d(TAG, "连接状态改变日志:" + completeFirstData); // 处理连接状态改变日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogPairComplete())) { Log.d(TAG, "配对完成日志:" + completeFirstData); // 处理配对完成日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogNearlinkDevicesAddr())) { // 处理采集到星闪MAC地址完成日志 @@ -686,14 +677,17 @@ private String CH34xProcessingForReadData(String string) { ChatProcessorForExtract.initializeHandler(); ChatProcessorForExtract.processChat(context, completeFirstData); } + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogSsapsMtuChanged())) { Log.d(TAG, "MTU改变日志:" + completeFirstData); // 处理MTU改变日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } if (completeFirstData.contains(ChatUtils.getPrefixLogSleAnnounceEnableCallback())) { Log.d(TAG, "启用回调日志:" + completeFirstData); // 处理启用回调日志 + ChatUtils.setShowUartLog(true);return completeFirstData; } } return ""; diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/SQLite/SQLiteDataBaseAPP.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/SQLite/SQLiteDataBaseAPP.java index 2a5037f..db37dad 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/SQLite/SQLiteDataBaseAPP.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/SQLite/SQLiteDataBaseAPP.java @@ -21,6 +21,7 @@ protected static class data { private static final SQLiteDataBaseAPP shuju = new public void CreateSql(String SDPath) { sqLiteDataBaseForAPP = SQLiteDatabase.openOrCreateDatabase(SDPath + "/NLChat.db",null); createChatTable(); + createDebugTable(); createVersionTable(); } @@ -35,6 +36,16 @@ private void createChatTable() { sqLiteDataBaseForAPP.execSQL(TABLE_CREATE); } + //创建日志表,存储日志消息、相关用户、聊天时间 + private void createDebugTable() { + String TABLE_CREATE = + "CREATE TABLE IF NOT EXISTS debug (" + + "message TEXT, " + + "sender TEXT, " + + "timestamp TEXT);"; + sqLiteDataBaseForAPP.execSQL(TABLE_CREATE); + } + //创建版本表,存储聊天消息时使用该软件的版本号,绑定ID private void createVersionTable() { String TABLE_CREATE = @@ -53,6 +64,15 @@ public void saveMessageToDatabase(String message, String sender, String timestam sqLiteDataBaseForAPP.insert("messages", null, values); } + //保存此时日志到数据库 + public void saveDebugToDatabase(String message, String sender, String timestamp) { + ContentValues values = new ContentValues(); + values.put("message", message); + values.put("sender", sender); + values.put("timestamp", timestamp); + sqLiteDataBaseForAPP.insert("debug", null, values); + } + //保存版本号到数据库 public void saveVersionToDatabase(String version) { ContentValues values = new ContentValues(); diff --git a/app/src/main/res/drawable/bg_chat_bubble_wechat_received.xml b/app/src/main/res/drawable/bg_chat_bubble_wechat_received.xml index 208a590..3f4d4e1 100644 --- a/app/src/main/res/drawable/bg_chat_bubble_wechat_received.xml +++ b/app/src/main/res/drawable/bg_chat_bubble_wechat_received.xml @@ -1,5 +1,6 @@ + @@ -10,6 +11,8 @@ + + + @@ -10,6 +11,8 @@ + + diff --git a/app/src/main/res/layout/item_debug.xml b/app/src/main/res/layout/item_debug.xml index e1a8cc6..9b38099 100644 --- a/app/src/main/res/layout/item_debug.xml +++ b/app/src/main/res/layout/item_debug.xml @@ -18,6 +18,8 @@ android:hyphenationFrequency="none" android:maxWidth="220dp" android:padding="10dp" + android:fontFamily="monospace" + android:textSize="8sp" android:text="Hello, this is a sent message! Test!" android:textColor="@android:color/black"/> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 781cb6b..92c59da 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.148.2024.0709 + 1.3.169.2024.0709 NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。 友情感谢