8000 新增:两个常用标签`网络状态`(`{{NET_TYPE}}`)和`简单电池信息`(`{{BATTERY_INFO_SIMPLE}}`) by alphime · Pull Request #439 · pppscn/SmsForwarder · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

新增:两个常用标签网络状态({{NET_TYPE}})和简单电池信息({{BATTERY_INFO_SIMPLE}}) #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions app/src/main/java/com/idormy/sms/forwarder/entity/MsgInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,17 +87,37 @@ 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), "%.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 == getString(R.string.battery_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)
Expand All @@ -112,7 +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)
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@
<string name="tag_battery_status">{{BATTERY_STATUS}}</string>
<string name="tag_battery_plugged">{{BATTERY_PLUGGED}}</string>
<string name="tag_battery_info">{{BATTERY_INFO}}</string>
<string name="tag_battery_info_simple" translatable="false">{{BATTERY_INFO_SIMPLE}}</string>
<string name="tag_uid">{{UID}}</string>
<string name="tag_ipv4">{{IPV4}}</string>
<string name="tag_ipv6">{{IPV6}}</string>
Expand Down Expand Up @@ -1450,4 +1451,5 @@
<string name="bluetooth_not_supported">不支持蓝牙设备</string>
<string name="start_discovery">搜索设备</string>
<string name="invalid_bluetooth_mac_address">蓝牙设备MAC地址无效,例如:AA:BB:CC:DD:EE:FF</string>
<string name="tag_net_type" translatable="false">{{NET_TYPE}}</string>
</resources>
0