From 123a1c16871dbfa767675327de08066fcc055079 Mon Sep 17 00:00:00 2001 From: alphi Date: Mon, 25 Mar 2024 01:27:18 +0800 Subject: [PATCH 1/5] add BATTERY_INFO_SIMPLE --- .../main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt | 7 ++++++- app/src/main/res/values/strings.xml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt index f5e1b0592b..eed8c6c6bb 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt @@ -93,10 +93,15 @@ data class MsgInfo( .replaceTag(getString(R.string.tag_call_type), CALL_TYPE_MAP[callType.toString()] ?: getString(R.string.unknown_call), needJson) .replaceTag(getString(R.string.tag_ipv4), TaskUtils.ipv4, needJson) .replaceTag(getString(R.string.tag_ipv6), TaskUtils.ipv6, needJson) - .replaceTag(getString(R.string.tag_battery_pct), "%.2f".format(TaskUtils.batteryPct), needJson) + .replaceTag(getString(R.string.tag_battery_pct), "%.0f%%".format(TaskUtils.batteryPct), needJson) .replaceTag(getString(R.string.tag_battery_status), BatteryUtils.getStatus(TaskUtils.batteryStatus), needJson) .replaceTag(getString(R.string.tag_battery_plugged), BatteryUtils.getPlugged(TaskUtils.batteryPlugged), needJson) .replaceTag(getString(R.string.tag_battery_info), TaskUtils.batteryInfo, needJson) + .replaceTag(getString(R.string.tag_battery_info_simple), "%.0f%%".format(TaskUtils.batteryPct) + + with(BatteryUtils.getPlugged(TaskUtils.batteryPlugged)) { + if (this == "未知") "" else " - $this" + } + ) .replaceAppNameTag(from, needJson) .replaceLocationTag(needJson) .regexReplace(regexReplace) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d6221d28cf..cf8002f8ec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -634,6 +634,7 @@ {{BATTERY_STATUS}} {{BATTERY_PLUGGED}} {{BATTERY_INFO}} + {{BATTERY_INFO_SIMPLE}} {{UID}} {{IPV4}} {{IPV6}} From 667292ff86ee54c93b03d84207ae0b49e96b3410 Mon Sep 17 00:00:00 2001 From: alphi Date: Sat, 30 Mar 2024 16:32:39 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BC=98=E5=8C=96unknow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt index eed8c6c6bb..50a6be5242 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt @@ -99,7 +99,7 @@ data class MsgInfo( .replaceTag(getString(R.string.tag_battery_info), TaskUtils.batteryInfo, needJson) .replaceTag(getString(R.string.tag_battery_info_simple), "%.0f%%".format(TaskUtils.batteryPct) + with(BatteryUtils.getPlugged(TaskUtils.batteryPlugged)) { - if (this == "未知") "" else " - $this" + if (this == getString(R.string.unknown)) "" else " - $this" } ) .replaceAppNameTag(from, needJson) From db56d4c0e479c50f891fc182df5b95b54dd063b8 Mon Sep 17 00:00:00 2001 From: alphi Date: Sat, 30 Mar 2024 17:13:18 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0NET=5FTYPE=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idormy/sms/forwarder/entity/MsgInfo.kt | 57 +++++++++++++++---- app/src/main/res/values/strings.xml | 1 + 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt index 50a6be5242..a437c61ae6 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt @@ -15,6 +15,7 @@ import com.idormy.sms.forwarder.utils.SettingUtils.Companion.enableSmsTemplate import com.idormy.sms.forwarder.utils.SettingUtils.Companion.extraDeviceMark import com.idormy.sms.forwarder.utils.SettingUtils.Companion.smsTemplate import com.idormy.sms.forwarder.utils.task.TaskUtils +import com.xuexiang.xutil.net.NetworkUtils import com.xuexiang.xutil.resource.ResUtils.getString import java.io.Serializable import java.text.SimpleDateFormat @@ -86,22 +87,48 @@ data class MsgInfo( .replaceTag(getString(R.string.tag_card_subid), subId.toString(), needJson) .replaceTag(getString(R.string.tag_title), simInfo, needJson) .replaceTag(getString(R.string.tag_uid), uid.toString(), needJson) - .replaceTag(getString(R.string.tag_receive_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date), needJson) - .replaceTag(getString(R.string.tag_current_time), SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()), needJson) + .replaceTag( + getString(R.string.tag_receive_time), + SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date), + needJson + ) + .replaceTag( + getString(R.string.tag_current_time), + SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date()), + needJson + ) .replaceTag(getString(R.string.tag_device_name), extraDeviceMark.trim(), needJson) .replaceTag(getString(R.string.tag_app_version), AppUtils.getAppVersionName(), needJson) - .replaceTag(getString(R.string.tag_call_type), CALL_TYPE_MAP[callType.toString()] ?: getString(R.string.unknown_call), needJson) + .replaceTag( + getString(R.string.tag_call_type), + CALL_TYPE_MAP[callType.toString()] ?: getString(R.string.unknown_call), + needJson + ) .replaceTag(getString(R.string.tag_ipv4), TaskUtils.ipv4, needJson) .replaceTag(getString(R.string.tag_ipv6), TaskUtils.ipv6, needJson) .replaceTag(getString(R.string.tag_battery_pct), "%.0f%%".format(TaskUtils.batteryPct), needJson) - .replaceTag(getString(R.string.tag_battery_status), BatteryUtils.getStatus(TaskUtils.batteryStatus), needJson) - .replaceTag(getString(R.string.tag_battery_plugged), BatteryUtils.getPlugged(TaskUtils.batteryPlugged), needJson) + .replaceTag( + getString(R.string.tag_battery_status), + BatteryUtils.getStatus(TaskUtils.batteryStatus), + needJson + ) + .replaceTag( + getString(R.string.tag_battery_plugged), + BatteryUtils.getPlugged(TaskUtils.batteryPlugged), + needJson + ) .replaceTag(getString(R.string.tag_battery_info), TaskUtils.batteryInfo, needJson) - .replaceTag(getString(R.string.tag_battery_info_simple), "%.0f%%".format(TaskUtils.batteryPct) - + with(BatteryUtils.getPlugged(TaskUtils.batteryPlugged)) { - if (this == getString(R.string.unknown)) "" else " - $this" - } + .replaceTag(getString(R.string.tag_battery_info_simple), + "%.0f%%".format(TaskUtils.batteryPct) + + with(BatteryUtils.getPlugged(TaskUtils.batteryPlugged)) { + if (this == getString(R.string.unknown)) "" else " - $this" + } ) + .replaceTag(getString(R.string.tag_net_type), with(NetworkUtils.getNetStateType()) { + if (this == NetworkUtils.NetState.NET_NO || this == NetworkUtils.NetState.NET_UNKNOWN) + this.name + this.name.removePrefix("NET_") + }) .replaceAppNameTag(from, needJson) .replaceLocationTag(needJson) .regexReplace(regexReplace) @@ -117,7 +144,10 @@ data class MsgInfo( val lineSplit = line.split("===".toRegex()).toTypedArray() if (lineSplit.isNotEmpty()) { val regex = lineSplit[0] - val replacement = if (lineSplit.size >= 2) lineSplit[1].replace("\\\\n".toRegex(), "\n") else "" + val replacement = if (lineSplit.size >= 2) lineSplit[1].replace( + "\\\\n".toRegex(), + "\n" + ) else "" newContent = newContent.replace(regex.toRegex(), replacement) } } @@ -129,7 +159,12 @@ data class MsgInfo( } //替换标签(支持正则替换) - private fun String.replaceTag(tag: String, info: String, needJson: Boolean = false, ignoreCase: Boolean = true): String { + private fun String.replaceTag( + tag: String, + info: String, + needJson: Boolean = false, + ignoreCase: Boolean = true + ): String { var result = if (needJson) { this.replace(tag, toJsonStr(info), ignoreCase) } else { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cf8002f8ec..3fbbf2b2a1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1429,4 +1429,5 @@ 不支持蓝牙设备 搜索设备 蓝牙设备MAC地址无效,例如:AA:BB:CC:DD:EE:FF + {{NET_TYPE}} From 25293110ca61a60935537f0c6bda4c96165e3682 Mon Sep 17 00:00:00 2001 From: alphi Date: Sat, 30 Mar 2024 17:19:07 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../idormy/sms/forwarder/entity/MsgInfo.kt | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt index a437c61ae6..66f461498d 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt @@ -99,24 +99,13 @@ data class MsgInfo( ) .replaceTag(getString(R.string.tag_device_name), extraDeviceMark.trim(), needJson) .replaceTag(getString(R.string.tag_app_version), AppUtils.getAppVersionName(), needJson) - .replaceTag( - getString(R.string.tag_call_type), - CALL_TYPE_MAP[callType.toString()] ?: getString(R.string.unknown_call), - needJson - ) + .replaceTag(getString(R.string.tag_call_type), + CALL_TYPE_MAP[callType.toString()] ?: getString(R.string.unknown_call), needJson) .replaceTag(getString(R.string.tag_ipv4), TaskUtils.ipv4, needJson) .replaceTag(getString(R.string.tag_ipv6), TaskUtils.ipv6, needJson) .replaceTag(getString(R.string.tag_battery_pct), "%.0f%%".format(TaskUtils.batteryPct), needJson) - .replaceTag( - getString(R.string.tag_battery_status), - BatteryUtils.getStatus(TaskUtils.batteryStatus), - needJson - ) - .replaceTag( - getString(R.string.tag_battery_plugged), - BatteryUtils.getPlugged(TaskUtils.batteryPlugged), - needJson - ) + .replaceTag(getString(R.string.tag_battery_status), BatteryUtils.getStatus(TaskUtils.batteryStatus), needJson) + .replaceTag(getString(R.string.tag_battery_plugged), BatteryUtils.getPlugged(TaskUtils.batteryPlugged), needJson) .replaceTag(getString(R.string.tag_battery_info), TaskUtils.batteryInfo, needJson) .replaceTag(getString(R.string.tag_battery_info_simple), "%.0f%%".format(TaskUtils.batteryPct) @@ -144,10 +133,9 @@ data class MsgInfo( val lineSplit = line.split("===".toRegex()).toTypedArray() if (lineSplit.isNotEmpty()) { val regex = lineSplit[0] - val replacement = if (lineSplit.size >= 2) lineSplit[1].replace( - "\\\\n".toRegex(), - "\n" - ) else "" + val replacement = + if (lineSplit.size >= 2) + lineSplit[1].replace("\\\\n".toRegex(), "\n") else "" newContent = newContent.replace(regex.toRegex(), replacement) } } @@ -159,12 +147,7 @@ data class MsgInfo( } //替换标签(支持正则替换) - private fun String.replaceTag( - tag: String, - info: String, - needJson: Boolean = false, - ignoreCase: Boolean = true - ): String { + private fun String.replaceTag(tag: String, info: String, needJson: Boolean = false, ignoreCase: Boolean = true): String { var result = if (needJson) { this.replace(tag, toJsonStr(info), ignoreCase) } else { From 754f68314c953e008502c1627992ebff8c4bd226 Mon Sep 17 00:00:00 2001 From: alphi Date: Mon, 1 Apr 2024 10:06:00 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84unknown=E9=94=99=E8=AF=AF=EF=BC=8C=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E4=B8=BAbattery=5Funknown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt index 66f461498d..0eb446e7d6 100644 --- a/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt +++ b/app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt @@ -110,7 +110,7 @@ data class MsgInfo( .replaceTag(getString(R.string.tag_battery_info_simple), "%.0f%%".format(TaskUtils.batteryPct) + with(BatteryUtils.getPlugged(TaskUtils.batteryPlugged)) { - if (this == getString(R.string.unknown)) "" else " - $this" + if (this == getString(R.string.battery_unknown)) "" else " - $this" } ) .replaceTag(getString(R.string.tag_net_type), with(NetworkUtils.getNetStateType()) {