Skip to content

Commit

Permalink
🎉Release 1.3,添加高频波特率(BETA)、数据库相关代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 8, 2024
1 parent 3a947c3 commit 8b3ae76
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* 受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.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;

import com.haohanyh.linmengjia.nearlink.nlchat.fun.R;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.SQLite.SQLiteDataBaseAPP;

public class ChatSaveMessageDatabaseManager {
private static final String TAG = "ChatSaveMessageDatabaseManager & NLChat";

//调用SQLite
private static SQLiteDataBaseAPP dbHelper;
Expand All @@ -16,6 +17,10 @@ public class ChatSaveMessageDatabaseManager {

public ChatSaveMessageDatabaseManager(Context context) {
this.context = context;

dbHelper = SQLiteDataBaseAPP.SQLiteData();
dbHelper.CreateSql(context.getFilesDir().getPath());
Log.i(TAG, "当前数据库保存地址:" + context.getFilesDir().getPath()); // 打印储存位置到日志
}

public void saveMessageToDatabase(String timestamp, String message, String sender) {
Expand All @@ -26,5 +31,6 @@ public void saveMessageToDatabase(String timestamp, String message, String sende
//如果有消息再保存,上面是没消息不予保存
dbHelper.saveMessageToDatabase(message, sender, timestamp);
dbHelper.saveVersionToDatabase(context.getString(R.string.app_version));
Log.i(TAG, "当前数据库保存内容:\n消息内容" + message + "\n用户名" + sender + "\n时间戳" + timestamp); // 打印内容到日志
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private WCHUartSettings wchUartSettings = new WCHUartSettings();
private AppCompatCheckBox CheckBoxUartWarn;
private boolean NearLinkUartWarnToast = false;
private RadioButton RadioButtonBaud4800,RadioButtonBaud9600,RadioButtonBaud19200,RadioButtonBaud38400,RadioButtonBaud57600,RadioButtonBaud115200,RadioButtonBaud921600;
private RadioButton RadioButtonBaud4800,RadioButtonBaud9600,RadioButtonBaud19200,RadioButtonBaud38400,RadioButtonBaud57600,RadioButtonBaud115200,RadioButtonBaud230400,RadioButtonBaud921600,RadioButtonBaud1000000, RadioButtonBaud2000000;
private RadioButton RadioButtonData5,RadioButtonData6,RadioButtonData7,RadioButtonData8;
private RadioButton RadioButtonStop1,RadioButtonStop2;
private RadioButton RadioButtonParityNone,RadioButtonParityOdd,RadioButtonParityEven,RadioButtonParityMark,RadioButtonParitySpace;
private final int[] baudRateIds = {id.rbBaud4800, id.rbBaud9600, id.rbBaud19200, id.rbBaud38400, id.rbBaud57600, id.rbBaud115200, id.rbBaud921600};
private final int[] baudRateIds = {id.rbBaud4800, id.rbBaud9600, id.rbBaud19200, id.rbBaud38400, id.rbBaud57600, id.rbBaud115200, id.rbBaud230400, id.rbBaud921600, id.rbBaud1000000, id.rbBaud2000000};
private final int[] dataBitIds = {id.rbData5, id.rbData6, id.rbData7, id.rbData8};
private final int[] stopBitIds = {id.rbStop1, id.rbStop2};
private final int[] parityIds = {id.rbParityNone, id.rbParityOdd, id.rbParityEven, id.rbParityMark, id.rbParitySpace};
Expand Down Expand Up @@ -189,11 +189,6 @@ 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 @@ -309,7 +304,10 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent
RadioButtonBaud38400 = findViewById(id.rbBaud38400);
RadioButtonBaud57600 = findViewById(id.rbBaud57600);
RadioButtonBaud115200 = findViewById(id.rbBaud115200);
RadioButtonBaud230400 = findViewById(id.rbBaud230400);
RadioButtonBaud921600 = findViewById(id.rbBaud921600);
RadioButtonBaud1000000 = findViewById(id.rbBaud1000000);
RadioButtonBaud2000000 = findViewById(id.rbBaud2000000);
RadioButtonData5 = findViewById(id.rbData5);
RadioButtonData6 = findViewById(id.rbData6);
RadioButtonData7 = findViewById(id.rbData7);
Expand Down Expand Up @@ -354,6 +352,8 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent
//聊天初始化
serverUpdater = new ChatMessageQueueUpdater(NearLinkUserText, serverMessageQueue, chatMessages, chatAdapter, "User: ");
clientUpdater = new ChatMessageQueueUpdater(NearLinkMeText, clientMessageQueue, chatMessages, chatAdapter,"Me: ");
//聊天数据库初始化
chatSaveMessageDatabaseManager = new ChatSaveMessageDatabaseManager(MainActivity.this);

//星闪网络相关设置初始化,目前多数还不允许UI设置,敬请期待
CompoundButton.OnCheckedChangeListener SettingsChangeListener = new CompoundButton.OnCheckedChangeListener() {
Expand Down Expand Up @@ -445,8 +445,6 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
SettingsForNFC.setEnabled(false);
SettingsForNFC.setOnCheckedChangeListener(SettingsChangeListener);



//初始化完成,软件第一次启动必须提示(这里写的第一次启动是软件启动的第一次,而不是使用频率的第一次
HhandlerI.sendEmptyMessage(31);
//如果SQLite有记录,可以显示在UI上
Expand Down Expand Up @@ -513,7 +511,10 @@ private void InitToOpen() {
RadioButtonBaud38400.setEnabled(false);
RadioButtonBaud57600.setEnabled(false);
RadioButtonBaud115200.setEnabled(false);
RadioButtonBaud230400.setEnabled(false);
RadioButtonBaud921600.setEnabled(false);
RadioButtonBaud1000000.setEnabled(false);
RadioButtonBaud2000000.setEnabled(false);
RadioButtonData5.setEnabled(false);
RadioButtonData6.setEnabled(false);
RadioButtonData7.setEnabled(false);
Expand Down Expand Up @@ -582,16 +583,6 @@ private void loadMessagesFromDatabase() {
}
}

private void saveMessageToDatabase(String timestamp, String message, String sender) {
//检索是否有空消息,串口通讯时常有相关问题
if (message == null || message.trim().isEmpty()) {
return;
}
//如果有消息再保存,上面是没消息不予保存
dbHelper.saveMessageToDatabase(message, sender, timestamp);
dbHelper.saveVersionToDatabase(context.getString(string.app_version));
}

private StringBuilder buffer = new StringBuilder();
private void NearLinkChatReadData() {
//先播报星闪软件情况,已经UART接入星闪网络,再好好的处理字符
Expand All @@ -610,7 +601,7 @@ private void NearLinkChatReadData() {
//如果需要存储到数据库中
if (ChatUtils.isSqlitemanager()) {
String timestamp = chatTimestamp.saveCurrentTimestamp();
saveMessageToDatabase(timestamp, processedString, "User");
chatSaveMessageDatabaseManager.saveMessageToDatabase(timestamp, processedString, "User");
}
//如果需要UI滚动消息
if (ChatUtils.isScrollingMessages()) {
Expand Down Expand Up @@ -743,7 +734,7 @@ public void NearLinkChatSendData(View view) {
//如果需要存储到数据库中
if (ChatUtils.isSqlitemanager()) {
String timestamp = chatTimestamp.saveCurrentTimestamp();
saveMessageToDatabase(timestamp, messageSend, "Me");
chatSaveMessageDatabaseManager.saveMessageToDatabase(timestamp, messageSend, "Me");
}
//如果需要UI滚动消息
if (ChatUtils.isScrollingMessages()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SQLiteDataBaseAPP {

SQLiteDatabase sqLiteDataBaseForAPP;

protected SQLiteDataBaseAPP() { }
public SQLiteDataBaseAPP() { }
public static SQLiteDataBaseAPP SQLiteData() { return SQLiteDataBaseAPP.data.shuju; }
protected static class data { private static final SQLiteDataBaseAPP shuju = new SQLiteDataBaseAPP(); }

Expand Down
32 changes: 32 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@
android:theme="@style/MyRadiobutton"
tools:ignore="HardcodedText,RtlHardcoded" />

<RadioButton
android:id="@+id/rbBaud230400"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:checked="false"
android:text="230400"
android:textColor="@color/nearlinkgreen"
android:theme="@style/MyRadiobutton"
tools:ignore="HardcodedText,RtlHardcoded" />

<RadioButton
android:id="@+id/rbBaud921600"
android:layout_width="wrap_content"
Expand All @@ -458,6 +469,27 @@
android:theme="@style/MyRadiobutton"
tools:ignore="HardcodedText,RtlHardcoded" />

<RadioButton
android:id="@+id/rbBaud1000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:checked="false"
android:text="1000000"
android:textColor="@color/nearlinkgreen"
android:theme="@style/MyRadiobutton"
tools:ignore="HardcodedText,RtlHardcoded" />

<RadioButton
android:id="@+id/rbBaud2000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:checked="false"
android:text="2000000"
android:textColor="@color/nearlinkgreen"
android:theme="@style/MyRadiobutton"
tools:ignore="HardcodedText,RtlHardcoded" />
</RadioGroup>

</HorizontalScrollView>
Expand Down
5 changes: 4 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.106.2024.0708</string>
<string name="app_version">1.3.120.2024.0708</string>

<string name="appwarn">NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。</string>
<string name="thanks3q">友情感谢</string>
Expand All @@ -21,7 +21,10 @@
<item>38400</item>
<item>57600</item>
<item>115200</item>
<item>230400</item>
<item>921600</item>
<item>1000000</item>
<item>2000000</item>
</string-array>
<string name="uiBaud">设置波特率: </string>
<string-array name="listData">
Expand Down

0 comments on commit 8b3ae76

Please sign in to comment.