Skip to content

Commit

Permalink
🎉Release 1.3,让功能设置可以在UI上自由决定(星闪网络设置页面),添加对话框防止因外部点击消失,对某些暂时未完成的功能停止设置…
Browse files Browse the repository at this point in the history
…和监听事件。添加新旧聊天UI的代码内设置。
  • Loading branch information
Hny0305Lin committed Jul 6, 2024
1 parent 69d91b4 commit 3867299
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 28 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore;

import android.content.Context;
import android.content.DialogInterface;
import android.widget.CompoundButton;

import androidx.appcompat.app.AlertDialog;

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

public class ChatUIAlertDialog {

private static boolean b = true;

public static boolean show(Context context, String title, String message, CompoundButton compoundButton) {
new AlertDialog.Builder(context, R.style.HaohanyhDialog)
.setTitle(title)
.setMessage(message)
.setCancelable(false) // 设置为 false 以防止点击对话框外部时消失
.setPositiveButton("确认停止", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 用户确认,允许取消勾选
compoundButton.setChecked(false);
b = false;
}
})
.setNegativeButton("取消停止", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// 用户取消,恢复勾选状态
compoundButton.setChecked(true);
b = true;
}
})
.show();
return b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ public class ChatUtils {
//这里设置的是UI相关,是否做到消息滚动展示在UI上,而不是全部展示,全部展示会占用大量UI资源
private static boolean showUartLog = false; // 控制是否启用显示串口Log,打印在UI上(开发者使用)
private static final boolean scrollingMessages = true; // 控制是否启用滚动消息功能
private static final boolean clipMessages = true; // 控制是否启用剪贴板功能
private static boolean clipMessages = true; // 控制是否启用剪贴板功能
private static final boolean uiNewOrOld = true; // 控制是否启用新UI(一般为True)
//这里设置的是数据库相关
private static boolean sqlitemanager = true; // 控制是否启用SQLite存储功能
private static boolean sqlitehistory = false; // 控制是否启用SQLite历史记录显示功能
Expand All @@ -31,6 +32,10 @@ public class ChatUtils {
public static boolean isScrollingMessages() { return scrollingMessages; }
//控制是否启用剪贴板功能和设置
public static boolean isClipMessages() { return clipMessages; }

public static void setClipMessages(boolean clipMessages) { ChatUtils.clipMessages = clipMessages; }
//控制是否启用新UI
public static boolean isUiNewOrOld() { return uiNewOrOld; }
//控制是否启用SQLite功能
public static boolean isSqlitemanager() { return sqlitemanager; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatMessageQueueUpdater;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatProcessorForExtract;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatSaveMessageDatabaseManager;
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.ChatUtils;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.Premission.NearLinkChatGetSomePermission;
Expand Down Expand Up @@ -119,6 +120,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
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};

private AppCompatCheckBox SettingsForShowLog,SettingsForSaveSQL,SettingsForDelSQL,SettingsForHistory,SettingsForClearSCR,SettingsForEncryption,SettingsForClip,SettingsForPush,SettingsForBackground,SettingsForBackup,SettingsForNFC;

//Context
private Context context = MainActivity.this;

Expand Down Expand Up @@ -213,9 +217,15 @@ private void Init() {
clickCountButton_btnNearLinkStatus = 0;
btnNearLinkStatus.setImageDrawable(getResources().getDrawable(drawable.ic_baseline_done_all_24));
btnNearLinkStatus.setImageResource(drawable.ic_baseline_done_all_24);
clickCountButton_btnNearLinkUIChanges = 0;
btnNearLinkUIChanges.setImageDrawable(getResources().getDrawable(drawable.ic_baseline_nearlink_24));
btnNearLinkUIChanges.setImageResource(drawable.ic_baseline_nearlink_24);
if (ChatUtils.isUiNewOrOld()) {
clickCountButton_btnNearLinkUIChanges = 0;
btnNearLinkUIChanges.setImageDrawable(getResources().getDrawable(drawable.ic_baseline_nearlink_24));
btnNearLinkUIChanges.setImageResource(drawable.ic_baseline_nearlink_24);
} else {
clickCountButton_btnNearLinkUIChanges = 1;
btnNearLinkUIChanges.setImageDrawable(getResources().getDrawable(drawable.ic_baseline_done_all_24));
btnNearLinkUIChanges.setImageResource(drawable.ic_baseline_done_all_24);
}
clickCountButton_btnNearLinkUart = 1;
btnNearlinkUart.setImageDrawable(getResources().getDrawable(drawable.ic_baseline_close_24));
btnNearlinkUart.setImageResource(drawable.ic_baseline_close_24);
Expand All @@ -236,9 +246,14 @@ private void Init() {
CTHANKS = findViewById(id.CardAPP);
CTHANKS.setVisibility(View.VISIBLE);
CNearLinkChat = findViewById(id.CardIChat);
CNearLinkChat.setVisibility(View.GONE);
CNearLinkChatNewUI = findViewById(id.CardIChatNewUI);
CNearLinkChatNewUI.setVisibility(View.VISIBLE);
if (ChatUtils.isUiNewOrOld()) {
CNearLinkChatNewUI.setVisibility(View.VISIBLE);
CNearLinkChat.setVisibility(View.GONE);
} else {
CNearLinkChat.setVisibility(View.VISIBLE);
CNearLinkChatNewUI.setVisibility(View.GONE);
}
NearLinkNewUIUserTitle = findViewById(id.userTitleNewUI);
recyclerView = findViewById(id.recycler_view);
APPRunResult = findViewById(id.appResult);
Expand All @@ -247,25 +262,8 @@ private void Init() {
NearLinkUserTitle = findViewById(id.userTitle);
NearLinkUserText = findViewById(id.readText);
NearLinkMeText = findViewById(id.writeText);
EditChatSend = findViewById(id.editChatSend);
EditChatSend.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE ||
(keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_DOWN)) {
String text = textView.getText().toString().trim();
if (!text.isEmpty()) {
NearLinkChatSendData(textView);
return true;
} else {
SnackBarToastForDebug(context,"您发送的消息为空!","推荐编辑好再发送",0,Snackbar.LENGTH_SHORT);
}
}
return false;
}
});
EditChatSendNewUI = findViewById(id.editChatSendNewUI);
EditChatSendNewUI.setOnEditorActionListener(new TextView.OnEditorActionListener() {

TextView.OnEditorActionListener editorActionListenerForChatSend = new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
if (actionId == EditorInfo.IME_ACTION_DONE ||
Expand All @@ -280,7 +278,12 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent
}
return false;
}
});
};
EditChatSend = findViewById(id.editChatSend);
EditChatSend.setOnEditorActionListener(editorActionListenerForChatSend);
EditChatSendNewUI = findViewById(id.editChatSendNewUI);
EditChatSendNewUI.setOnEditorActionListener(editorActionListenerForChatSend);


CheckBoxUartWarn = findViewById(id.cbUartWarn);
NearLinkUartWarnToast = CheckBoxUartWarn.isChecked();
Expand Down Expand Up @@ -335,7 +338,7 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent
radioButton.setOnCheckedChangeListener(createCheckedChangeListener(i, "Parity"));
}

//聊天 1.3更新
//聊天NewUI
recyclerView.setLayoutManager(new LinearLayoutManager(this));
chatAdapter = new ChatAdapter(this, chatMessages);
recyclerView.setAdapter(chatAdapter);
Expand All @@ -344,6 +347,98 @@ 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: ");

//星闪网络相关设置初始化,目前多数还不允许UI设置,敬请期待
CompoundButton.OnCheckedChangeListener SettingsChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (compoundButton.isEnabled()) {
if (compoundButton.getId() == id.cbSettingsForShowLog) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForSaveSQL) {
if (isChecked) {
ChatUtils.setSqlitemanager(true);
SnackBarToastForDebug(context,"您已开始保存您的聊天记录啦!","目前为" + ChatUtils.isSqlitemanager(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "聊天保存(SQLite)", "您确定要停止保存聊天数据吗?停止保存您的聊天,将会在接下来聊天时无法保存内容,可能会造成聊天记录丢失。", compoundButton))
ChatUtils.setSqlitemanager(false);
SnackBarToastForDebug(context,"已为您取消保存聊天记录!","目前为" + ChatUtils.isSqlitemanager(),0,Snackbar.LENGTH_SHORT);
}
} else if (compoundButton.getId() == id.cbSettingsForDelSQL) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForHistory) {
if (isChecked) {
ChatUtils.setSqliteHistory(true);
SnackBarToastForDebug(context,"您已开始展示您的聊天记录啦!","目前为" + ChatUtils.isSqliteHistory(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "历史设备记录(SQLite)", "您确定要停止展示聊天数据在UI上吗?", compoundButton))
ChatUtils.setSqliteHistory(false);
SnackBarToastForDebug(context,"已为您取消保存聊天记录!","目前为" + ChatUtils.isSqliteHistory(),0,Snackbar.LENGTH_SHORT);
}
} else if (compoundButton.getId() == id.cbSettingsForClearSCR) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForEncryption) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForClip) {
if (isChecked) {
ChatUtils.setClipMessages(true);
SnackBarToastForDebug(context,"您已开启剪贴板功能!","目前为" + ChatUtils.isClipMessages(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "聊天文本进入剪贴板", "您确定要停止剪贴板吗?剪贴板功能可以帮您自动按规则捕获内容,可以很大程度上帮助到您手动任务耗时的情况,取消则需要您自行处理屏幕上的UI信息。", compoundButton))
ChatUtils.setClipMessages(false);
SnackBarToastForDebug(context,"已为您取消剪贴板功能!","目前为" + ChatUtils.isClipMessages(),0,Snackbar.LENGTH_SHORT);
}
} else if (compoundButton.getId() == id.cbSettingsForPush) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForBackground) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForBackup) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);
} else if (compoundButton.getId() == id.cbSettingsForNFC) {
SnackBarToastForDebug(context,"敬请期待!","如有不适,那没办法,做的慢怪我咯o(*^@^*)o",0,Snackbar.LENGTH_SHORT);

}
}
}
};
SettingsForShowLog = findViewById(id.cbSettingsForShowLog);
SettingsForShowLog.setEnabled(false);
SettingsForShowLog.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForSaveSQL = findViewById(id.cbSettingsForSaveSQL);
SettingsForSaveSQL.setEnabled(true);
SettingsForSaveSQL.setChecked(true);
SettingsForSaveSQL.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForDelSQL = findViewById(id.cbSettingsForDelSQL);
SettingsForDelSQL.setEnabled(false);
SettingsForDelSQL.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForHistory = findViewById(id.cbSettingsForHistory);
SettingsForHistory.setEnabled(true);
SettingsForHistory.setChecked(false);
SettingsForHistory.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForClearSCR = findViewById(id.cbSettingsForClearSCR);
SettingsForClearSCR.setEnabled(false);
SettingsForClearSCR.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForEncryption = findViewById(id.cbSettingsForEncryption);
SettingsForEncryption.setEnabled(false);
SettingsForEncryption.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForClip = findViewById(id.cbSettingsForClip);
SettingsForClip.setEnabled(true);
SettingsForClip.setChecked(true);
SettingsForClip.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForPush = findViewById(id.cbSettingsForPush);
SettingsForPush.setEnabled(false);
SettingsForPush.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForBackground = findViewById(id.cbSettingsForBackground);
SettingsForBackground.setEnabled(false);
SettingsForBackground.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForBackup = findViewById(id.cbSettingsForBackup);
SettingsForBackup.setEnabled(false);
SettingsForBackup.setOnCheckedChangeListener(SettingsChangeListener);
SettingsForNFC = findViewById(id.cbSettingsForNFC);
SettingsForNFC.setEnabled(false);
SettingsForNFC.setOnCheckedChangeListener(SettingsChangeListener);



//初始化完成,软件第一次启动必须提示(这里写的第一次启动是软件启动的第一次,而不是使用频率的第一次
HhandlerI.sendEmptyMessage(31);
//如果SQLite有记录,可以显示在UI上
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.69.2024.0706</string>
<string name="app_version">1.3.80.2024.0706</string>

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

0 comments on commit 3867299

Please sign in to comment.