Skip to content

Commit

Permalink
🎉Release 1.2,添加聊天剪贴板(BETA,仅数字验证码)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 1, 2024
1 parent 86ed3e2 commit 557a85c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
Binary file added DevSummary/Screenshot_20240701_143020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NLChat是专门为[小熊派BearPi的星闪代码](https://github.com/Hny0305Lin/Bearpi_Hi2821_Pico_NLChat)开发的一款基于SLE通讯的文本传输软件,目前还在开发中,敬请期待完整版向大家开放。

![IMG.SHIELD.IO](https://img.shields.io/badge/Hi2821_NLChat-Release1.2.18.2024.0701-gray.svg?colorA=007FFC&colorB=4DDDFC&style=for-the-badge)
![IMG.SHIELD.IO](https://img.shields.io/badge/Hi2821_NLChat-Release1.2.31.2024.0701-gray.svg?colorA=007FFC&colorB=4DDDFC&style=for-the-badge)

![NLChat](https://github.com/Hny0305Lin/NLChat/blob/master/DevSummary/NLChat.jpg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
public class ChatUtils {
//这里设置的是UI相关,是否做到消息滚动展示在UI上,而不是全部展示,全部展示会占用大量UI资源
private static final boolean scrollingMessages = false; // 控制是否启用滚动消息功能
//这里设置的是数据库相关,是否做到消息保存进SQLite里
private static boolean sqlite = true; // 控制是否启用SQLite功能
private static final boolean clipMessages = true; // 控制是否启用剪贴板功能(目前仅验证码)
//这里设置的是数据库相关
private static boolean sqlitemanager = true; // 控制是否启用SQLite存储功能
private static boolean sqlitehistory = false; // 控制是否启用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:";
//控制是否启用滚动消息功能
public static boolean isScrollingMessages() { return scrollingMessages; }
//控制是否启用剪贴板功能和设置
public static boolean isClipMessages() { return clipMessages; }

public static void setSqlitehistory(boolean sqlitehistory) { ChatUtils.sqlitehistory = sqlitehistory; }
//控制是否启用SQLite功能
public static boolean isSqlite() { return sqlite; }
public static boolean isSqlitemanager() { return sqlitemanager; }

public static void setSqlite(boolean sqlite) { ChatUtils.sqlite = sqlite; }
public static void setSqlitemanager(boolean sqlitemanager) { ChatUtils.sqlitemanager = sqlitemanager; }

public static boolean isSqliteHistory() { return sqlitehistory; }

public static void setSqliteHistory(boolean sqlitehistory) { ChatUtils.sqlitehistory = sqlitehistory; }

//对方为星闪服务端
public static String getPrefixServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand Down Expand Up @@ -55,6 +57,8 @@
import java.text.SimpleDateFormat;
import java.util.LinkedList;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//Log需要的TAG
Expand Down Expand Up @@ -91,6 +95,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//手机常量,代码里设置
private final boolean MobileKeepScreenOn = false;

//聊天相关
private LinkedList<String> serverMessageQueue = new LinkedList<>();
private LinkedList<String> clientMessageQueue = new LinkedList<>();
private static final int MAX_MESSAGES = 10; // 设置最大消息数量
private StringBuilder extractedNumbers = new StringBuilder();
//聊天时间戳
@SuppressLint("SimpleDateFormat")
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
//调用SQLite
private SQLiteDataBaseAPP dbHelper;

Expand Down Expand Up @@ -131,7 +143,7 @@ private void Init() {
if (Environment.isExternalStorageManager()) {
Log.v(TAG,"Android 10以上设备是否获取最高读写文件权限?:" + Environment.isExternalStorageManager());
//既然有权限了,带上数据库初始化
if (ChatUtils.isSqlite()) {
if (ChatUtils.isSqlitemanager()) {
dbHelper = SQLiteDataBaseAPP.SQLiteData();
dbHelper.CreateSql(getFilesDir().getPath());
}
Expand Down Expand Up @@ -432,10 +444,10 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
}
}
});

//初始化完成,软件第一次启动必须提示(这里写的第一次启动是软件启动的第一次,而不是使用频率的第一次
HhandlerI.sendEmptyMessage(31);

loadMessagesFromDatabase();
//如果SQLite有记录,可以显示在UI上
if (ChatUtils.isSqliteHistory()) loadMessagesFromDatabase();
}

private void InitToOpen() {
Expand Down Expand Up @@ -521,11 +533,6 @@ private void saveMessageToDatabase(String message, String sender) {
}

private StringBuilder buffer = new StringBuilder();
private LinkedList<String> serverMessageQueue = new LinkedList<>();
private LinkedList<String> clientMessageQueue = new LinkedList<>();
private static final int MAX_MESSAGES = 10; // 设置最大消息数量
@SuppressLint("SimpleDateFormat")
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
private void NearLinkChatReadData() {
//先播报星闪软件情况,已经UART接入星闪网络,再好好的处理字符
HhandlerI.sendEmptyMessage(10);
Expand Down Expand Up @@ -594,6 +601,26 @@ private String CH34xProcessingForReadData(String string) {
if (!completeSecondData.endsWith("\n")) {
completeSecondData += "\n";
}

//聊天进入剪贴板
if (ChatUtils.isClipMessages()) {
// 提取四位和六位数字
Pattern pattern = Pattern.compile("\\b\\d{4}\\b|\\b\\d{6}\\b");
Matcher matcher = pattern.matcher(completeSecondData);
while (matcher.find()) {
String foundNumber = matcher.group();
extractedNumbers.append(foundNumber).append("\n");
}

// 将提取到的数字复制到剪贴板
if (extractedNumbers.length() > 0) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("extractedNumbers", extractedNumbers.toString().trim());
clipboard.setPrimaryClip(clip);
SnackBarToastForDebug("提取到疑似验证码,已复制到剪贴板!","推荐去粘贴",0,Snackbar.LENGTH_LONG);
}
}

return completeSecondData;
}
} else {
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.2.18.2024.0701</string>
<string name="app_version">1.2.31.2024.0701</string>

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

0 comments on commit 557a85c

Please sign in to comment.