Skip to content

Commit

Permalink
🎉Release 1.3,客户板接入时的Log弹窗,数据库部分功能陆续修复
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 17, 2024
1 parent 31c6cc8 commit c1c7ab0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,55 @@ public boolean onLongClick(View view) {
String result = messageText.getText().toString().trim();

if (result.equals(ChatUtils.getPrefixLogConnected())) {
ChatUIAlertDialog.showSerialLog(context, ChatUtils.getPrefixLogConnected(), context.getString(string.prefixLogConnected), "推荐开始聊天", "取消显示", "复制进剪贴板");
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogConnected(),
context.getString(string.prefixLogConnected),
"推荐开始聊天", "取消显示", "复制进剪贴板");
} else if (result.equals(ChatUtils.getPrefixLogDisconnected())) {
ChatUIAlertDialog.showSerialLog(context, ChatUtils.getPrefixLogDisconnected(), context.getString(string.prefixLogDisConnected), "推荐重启软件和星闪板", "取消显示", "复制进剪贴板");
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogDisconnected(),
context.getString(string.prefixLogDisConnected),
"推荐重启软件和星闪板", "取消显示", "复制进剪贴板");
} else if (result.equals(ChatUtils.getPrefixLogAcore())) {
//ACore暂时不写
} else if (result.startsWith(ChatUtils.getPrefixLogConnectStateChanged())) {
ChatUIAlertDialog.showSerialLog(context, ChatUtils.getPrefixLogConnectStateChanged(), context.getString(string.prefixLogConnectStateChanged), "推荐检查", "取消显示", "复制进剪贴板");
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogConnectStateChanged(),
context.getString(string.prefixLogConnectStateChanged),
"推荐检查", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogNearlinkDevicesAddr())) {
ChatUIAlertDialog.showSerialLog(context, ChatUtils.getPrefixLogNearlinkDevicesAddr(), context.getString(string.prefixLogNearlinkDevicesAddr), "推荐开始聊天", "取消显示", "复制进剪贴板");
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogNearlinkDevicesAddr(),
context.getString(string.prefixLogNearlinkDevicesAddr),
"推荐开始聊天", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogPairComplete())) {
ChatUIAlertDialog.showSerialLog(context, ChatUtils.getPrefixLogPairComplete(), context.getString(string.prefixLogPairComplete), "推荐开始聊天", "取消显示", "复制进剪贴板");
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogPairComplete(),
context.getString(string.prefixLogPairComplete),
"推荐开始聊天", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogSsapsMtuChanged())) {
//MTU暂时不写
//服务板MTU暂时不写
} else if (result.startsWith(ChatUtils.getPrefixLogSleAnnounceEnableCallback())) {
//CakkBack暂时不写
} else {
//分支暂时不写
//服务板CallBack暂时不写
} else if (result.startsWith(ChatUtils.getPrefixLogClientConnectStateChanged())) {
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogClientConnectStateChanged(),
context.getString(string.prefixLogClientConnectStateChanged),
"推荐检查", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogClientNearlinkDevicesAddr())) {
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogClientNearlinkDevicesAddr(),
context.getString(string.prefixLogClientNearlinkDevicesAddr),
"推荐开始聊天", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogClientPairComplete())) {
ChatUIAlertDialog.showSerialLog(context,
ChatUtils.getPrefixLogClientPairComplete(),
context.getString(string.prefixLogClientPairComplete),
"推荐开始聊天", "取消显示", "复制进剪贴板");
} else if (result.startsWith(ChatUtils.getPrefixLogClientMtu())) {
//客户板MTU暂时不写
} else if (result.startsWith(ChatUtils.getPrefixLogClientSleAnnounceEnableCallback())) {
//客户板CallBack暂时不写
}

// 在这里处理长按事件
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ public static void showSerialLog(Context context, String title, String message,
.setMessage(message)
.setCancelable(false)
.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

}
})
.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

}
})
.setNeutralButton(neutralButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {

//剪贴板功能有待补充
}
})
.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ChatUtils {
private static boolean clipMessages = true; // 控制是否启用剪贴板功能
//这里设置的是数据库相关
private static boolean sqlitemanager = true; // 控制是否启用SQLite存储功能
private static boolean sqlitehistory = false; // 控制是否启用SQLite历史记录显示功能
private static boolean sqlitehistory = true; // 控制是否启用SQLite历史记录显示功能
//这里设置的是跟C代码相关的,白名单获取聊天文本,当这些文本出现在串口通讯里面的时候,提取这String后者即可,期间过滤掉前者和大量串口log。
private static final String PREFIX_SERVER = " Let's start chatting, This is the content of the server:";
private static final String PREFIX_CLIENT = " Let's start chatting, This is the content of the client:";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ private void Init() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
if (Environment.isExternalStorageManager()) {
Log.v(TAG,"Android 10以上设备是否获取最高读写文件权限?:" + Environment.isExternalStorageManager());
//既然有权限了,带上数据库初始化
if (ChatUtils.isSqlitemanager()) {
dbHelper = SQLiteDataBaseAPP.SQLiteData();
dbHelper.CreateSql(getFilesDir().getPath());
}
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);intent.setData(Uri.parse("package:" + this.getPackageName()));startActivityForResult(intent, 1024);
}
Expand Down Expand Up @@ -512,7 +517,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
//初始化完成,软件第一次启动必须提示(这里写的第一次启动是软件启动的第一次,而不是使用频率的第一次
HhandlerI.sendEmptyMessage(31);
//如果SQLite有记录,可以显示在UI上
//if (ChatUtils.isSqliteHistory()) loadMessagesFromDatabase();
if (ChatUtils.isSqliteHistory()) loadMessagesFromDatabase();

//背景处理
//注册图片选择器的启动器
Expand Down Expand Up @@ -603,18 +608,20 @@ private void InitToOpen() {

private void loadMessagesFromDatabase() {
Cursor cursor = dbHelper.getAllMessages();
if (cursor != null) {
if (cursor != null && cursor.moveToFirst()) {
try {
while (cursor.moveToNext()) {
do {
@SuppressLint("Range") String timestampStr = cursor.getString(cursor.getColumnIndex("timestamp"));
@SuppressLint("Range") String message = cursor.getString(cursor.getColumnIndex("message"));
@SuppressLint("Range") String sender = cursor.getString(cursor.getColumnIndex("sender"));
Log.d(TAG, "Message: " + message + ", Sender: " + sender + ", Timestamp: " + timestampStr); // 记录调试日志
// 根据sender区分消息显示
if ("User".equals(sender)) {
NearLinkUserText.append(message + "\n");
} else {
NearLinkMeText.append(message + "\n");
}
}





} while (cursor.moveToNext());
} finally {
cursor.close();
}
Expand Down Expand Up @@ -734,23 +741,23 @@ private String CH34xProcessingForReadData(String string) {
}
}
}
//UART服务器日志相关,星闪MAC,为防止获取不到先判断
//UART服务器日志相关,服务端星闪MAC,为防止获取不到先判断
if (completeFirstData.contains(ChatUtils.getPrefixLogNearlinkDevicesAddr())) {
// 处理采集到星闪MAC地址完成日志
if (ChatUtils.isClipMessages()) {
Log.d(TAG, "采集到星闪MAC地址日志:" + completeFirstData + ",将进入剪贴板!");
Log.d(TAG, "采集到服务端星闪MAC地址日志:" + completeFirstData + ",将进入剪贴板!");
ChatProcessorForExtract.initializeHandler();
ChatProcessorForExtract.processChat(context, completeFirstData);
}

ChatUtils.setShowUartLog(true);
if (ChatUtils.isShowUartLog()) {
Log.d(TAG, "采集到星闪MAC地址日志:" + completeFirstData + ",是否显示?:" + true);
Log.d(TAG, "采集到服务端星闪MAC地址日志:" + completeFirstData + ",是否显示?:" + true);
if (ChatUtils.isSetDebugLog()) {
Log.d(TAG, "采集到星闪MAC地址日志:" + completeFirstData + ",是否设置打开?:" + true);
Log.d(TAG, "采集到服务端星闪MAC地址日志:" + completeFirstData + ",是否设置打开?:" + true);
return completeFirstData;
} else {
Log.d(TAG, "采集到星闪MAC地址日志:" + completeFirstData + ",是否设置打开?:" + false);
Log.d(TAG, "采集到服务端星闪MAC地址日志:" + completeFirstData + ",是否设置打开?:" + false);
}
}
}
Expand Down Expand Up @@ -831,7 +838,7 @@ private String CH34xProcessingForReadData(String string) {
}
}
}
//UART服务器日志相关,客户端星闪MAC,为防止获取不到先判断
//UART服务器日志相关,服务端星闪MAC,为防止获取不到先判断
if (completeFirstData.contains(ChatUtils.getPrefixLogClientPairComplete())) {
// 处理采集到客户端星闪MAC地址完成日志
if (ChatUtils.isClipMessages()) {
Expand Down Expand Up @@ -869,17 +876,17 @@ private String CH34xProcessingForReadData(String string) {
}
//UART客户端日志
if (completeFirstData.contains(ChatUtils.getPrefixLogSleUartClient())) {
Log.d(TAG, "UART客户端日志:" + completeFirstData);
Log.d(TAG, "客户端UART客户端日志:" + completeFirstData);
// 处理UART服务器日志

ChatUtils.setShowUartLog(true);
if (ChatUtils.isShowUartLog()) {
Log.d(TAG, "UART客户端日志:" + completeFirstData + ",是否显示?:" + true);
Log.d(TAG, "客户端UART客户端日志:" + completeFirstData + ",是否显示?:" + true);
if (ChatUtils.isSetDebugLog()) {
Log.d(TAG, "UART客户端日志:" + completeFirstData + ",是否设置打开?:" + true);
Log.d(TAG, "客户端UART客户端日志:" + completeFirstData + ",是否设置打开?:" + true);
return completeFirstData;
} else {
Log.d(TAG, "UART客户端日志:" + completeFirstData + ",是否设置打开?:" + false);
Log.d(TAG, "客户端UART客户端日志:" + completeFirstData + ",是否设置打开?:" + false);
}
}
}
Expand Down Expand Up @@ -918,16 +925,10 @@ public void NearLinkChatSendData(View view) {
clientMessageQueue.poll(); // 移除最早的消息
}
clientMessageQueue.add(TextOfClient);
//updateClientTextView();
clientUpdater.updateTextView();
MainAPP.Vibrate(this);
} else {
NearLinkMeText.append(messageSend);
if (NearLinkMeText.length() > 2048) {
String str = NearLinkMeText.getText().toString().substring(NearLinkMeText.getText().length() - 1024, NearLinkMeText.getText().length());
NearLinkMeText.setText("");
NearLinkMeText.append(str);
}
clientUpdater.updateTextView();
MainAPP.Vibrate(this);
}
//发送完消息清空待发送文本
Expand Down
20 changes: 19 additions & 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.269.2024.0716</string>
<string name="app_version">1.3.273.2024.0717</string>

<string name="appwarn">NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。</string>
<string name="thanks3q">友情感谢</string>
Expand Down Expand Up @@ -104,6 +104,24 @@
弹出此内容时,请您检查设备是否能正常链接,能正常链接则忽略。
</string>

<string name="prefixLogClientConnectStateChanged">
该串口提示为您设备接入的客户板,和服务板的链接状态发生改变。
\n
弹出此内容时,请您检查设备是否能正常链接,能正常链接则忽略,如果该内容是与Disconnected相互发送的,则链接已断开。
</string>

<string name="prefixLogClientPairComplete">
该串口提示为您设备接入的客户板,和服务板的链接,配对成功。
\n
弹出此内容时,请您检查设备MAC地址是否为客户板地址,能正常则忽略。
</string>

<string name="prefixLogClientNearlinkDevicesAddr">
该串口提示为您设备接入的客户板,已经获取服务端的专有MAC地址。
\n
弹出此内容时,请您检查设备是否能正常链接,能正常链接则忽略。
</string>



<string name="egg">
Expand Down

0 comments on commit c1c7ab0

Please sign in to comment.