diff --git a/app/src/main/java/io/github/soclear/oneuix/data/Preference.kt b/app/src/main/java/io/github/soclear/oneuix/data/Preference.kt
index 6dd7fb06..d2444c40 100644
--- a/app/src/main/java/io/github/soclear/oneuix/data/Preference.kt
+++ b/app/src/main/java/io/github/soclear/oneuix/data/Preference.kt
@@ -49,6 +49,7 @@ data class Preference(
val hideBatteryLevelTextChargingIcon: Boolean = false,
val supportRealTimeNetworkSpeed: Boolean = true,
val showSeparateUpDownNetworkSpeeds: Boolean = false,
+ val networkSpeedThresholdKb: Int = 0,
val setStatusBarClockFormat: Boolean = false,
val statusBarClockFormat: String = "HH:mm",
val setStatusBarClockTextScale: Boolean = false,
diff --git a/app/src/main/java/io/github/soclear/oneuix/hook/Main.kt b/app/src/main/java/io/github/soclear/oneuix/hook/Main.kt
index 229358fc..0e979339 100644
--- a/app/src/main/java/io/github/soclear/oneuix/hook/Main.kt
+++ b/app/src/main/java/io/github/soclear/oneuix/hook/Main.kt
@@ -297,7 +297,10 @@ class Main : IXposedHookLoadPackage, IXposedHookInitPackageResources, IXposedHoo
}
if (preference.systemUI.statusBar.showSeparateUpDownNetworkSpeeds) {
- Network.showSeparateUpDownNetworkSpeeds(lpparam)
+ Network.showSeparateUpDownNetworkSpeeds(
+ lpparam,
+ thresholdKb = preference.systemUI.statusBar.networkSpeedThresholdKb
+ )
}
if (preference.systemUI.statusBar.setStatusBarClockFormat) {
diff --git a/app/src/main/java/io/github/soclear/oneuix/hook/Network.kt b/app/src/main/java/io/github/soclear/oneuix/hook/Network.kt
index c24f0619..a6be8a68 100644
--- a/app/src/main/java/io/github/soclear/oneuix/hook/Network.kt
+++ b/app/src/main/java/io/github/soclear/oneuix/hook/Network.kt
@@ -53,7 +53,8 @@ object Network {
fun showSeparateUpDownNetworkSpeeds(
loadPackageParam: LoadPackageParam,
- intervalMillisecond: Long = 3000L
+ intervalMillisecond: Long = 3000L,
+ thresholdKb: Int = 0
) {
if (loadPackageParam.packageName != Package.SYSTEMUI || intervalMillisecond <= 0L) {
return
@@ -115,6 +116,9 @@ object Network {
): String {
val txBytesPerSecond = (current.totalTx - previous.totalTx) / actualIntervalSeconds
val rxBytesPerSecond = (current.totalRx - previous.totalRx) / actualIntervalSeconds
+ if (!shouldDisplayNetworkSpeed(txBytesPerSecond, rxBytesPerSecond, thresholdKb)) {
+ return ""
+ }
return "${formatSpeed(txBytesPerSecond)}\n${formatSpeed(rxBytesPerSecond)}"
}
@@ -303,3 +307,14 @@ object Network {
}
}
}
+
+internal fun shouldDisplayNetworkSpeed(
+ txBytesPerSecond: Float,
+ rxBytesPerSecond: Float,
+ thresholdKb: Int,
+): Boolean {
+ if (thresholdKb <= 0) return true
+ val thresholdBytesPerSecond = thresholdKb * 1024f
+ return txBytesPerSecond > thresholdBytesPerSecond ||
+ rxBytesPerSecond > thresholdBytesPerSecond
+}
diff --git a/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt b/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
index 28e9589e..5bee3f71 100644
--- a/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
+++ b/app/src/main/java/io/github/soclear/oneuix/ui/category/DetailPaneSystemUI.kt
@@ -286,6 +286,47 @@ fun DetailPaneSystemUI(
onEvent(SystemUIEvent.StatusBar.ShowSeparateUpDownNetworkSpeeds(it))
}
)
+ Column {
+ var expanded by rememberSaveable { mutableStateOf(false) }
+ var threshold by remember {
+ mutableIntStateOf(uiState.statusBar.networkSpeedThresholdKb)
+ }
+ SwitchItem(
+ icon = ImageVector.vectorResource(id = R.drawable.net_speed),
+ title = stringResource(id = R.string.networkSpeedThreshold_title),
+ summary = if (uiState.statusBar.networkSpeedThresholdKb > 0) {
+ "${uiState.statusBar.networkSpeedThresholdKb} KB/s"
+ } else null,
+ modifier = Modifier.animateContentSize(),
+ clickable = true,
+ onClick = { expanded = !expanded },
+ checked = uiState.statusBar.networkSpeedThresholdKb > 0,
+ onCheckedChange = {
+ if (it && threshold == 0) threshold = 1
+ if (!it) threshold = 0
+ onEvent(SystemUIEvent.StatusBar.NetworkSpeedThreshold(threshold))
+ }
+ )
+ AnimatedVisibility(expanded && uiState.statusBar.networkSpeedThresholdKb > 0) {
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ modifier = Modifier.padding(horizontal = 16.dp),
+ ) {
+ OutlinedTextField(
+ value = threshold.toString(),
+ onValueChange = { threshold = it.toIntOrNull()?.coerceAtLeast(1) ?: 1 },
+ modifier = Modifier.weight(1f),
+ label = { Text(stringResource(id = R.string.networkSpeedThreshold_label)) }
+ )
+ Spacer(modifier = Modifier.width(8.dp))
+ Button(onClick = {
+ onEvent(SystemUIEvent.StatusBar.NetworkSpeedThreshold(threshold))
+ }) {
+ Text(text = stringResource(id = R.string.confirm))
+ }
+ }
+ }
+ }
Column {
var expanded by rememberSaveable { mutableStateOf(false) }
@@ -992,6 +1033,9 @@ sealed interface SystemUIEvent {
@JvmInline
value class ShowSeparateUpDownNetworkSpeeds(val value: Boolean) : StatusBar
+ @JvmInline
+ value class NetworkSpeedThreshold(val value: Int) : StatusBar
+
@JvmInline
value class SetStatusBarClockFormat(val value: Boolean) : StatusBar
@@ -1293,6 +1337,16 @@ private fun SettingViewModel.onStatusBarEvent(event: SystemUIEvent.StatusBar) {
)
}
+ is SystemUIEvent.StatusBar.NetworkSpeedThreshold -> {
+ preference.copy(
+ systemUI = preference.systemUI.copy(
+ statusBar = preference.systemUI.statusBar.copy(
+ networkSpeedThresholdKb = event.value
+ )
+ )
+ )
+ }
+
is SystemUIEvent.StatusBar.SetStatusBarClockFormat -> {
preference.copy(
systemUI = preference.systemUI.copy(
diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml
index 3b1591e1..45a2a5e3 100644
--- a/app/src/main/res/values-zh/strings.xml
+++ b/app/src/main/res/values-zh/strings.xml
@@ -25,6 +25,8 @@
设置->通知->高级设置->显示实时网速
状态栏显示上传下载网速
上行为上传速度,下行为下载速度
+ 网速显示阈值
+ 阈值(KB/s)
开启快捷设置 5G 磁贴
需要勾选系统 UI 和通话设置
请授予本应用 root 权限后手动添加 5G 磁贴
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index af8fe509..06729d50 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -25,6 +25,8 @@
Settings -> Notifications -> Advanced settings -> Show real-time network speed
Show separate upload/download speeds in status bar
Top is upload speed, bottom is download speed
+ Network speed display threshold
+ Threshold (KB/s)
Enable 5G Quick Settings tile
Requires checking System UI and Call Settings
Please grant root access to this app, then manually add the 5G tile
diff --git a/app/src/test/java/io/github/soclear/oneuix/hook/NetworkTest.kt b/app/src/test/java/io/github/soclear/oneuix/hook/NetworkTest.kt
new file mode 100644
index 00000000..487428b3
--- /dev/null
+++ b/app/src/test/java/io/github/soclear/oneuix/hook/NetworkTest.kt
@@ -0,0 +1,14 @@
+package io.github.soclear.oneuix.hook
+
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class NetworkTest {
+ @Test
+ fun displaysWhenEitherDirectionExceedsThreshold() {
+ assertTrue(shouldDisplayNetworkSpeed(1025f, 0f, 1))
+ assertTrue(shouldDisplayNetworkSpeed(0f, 1025f, 1))
+ assertFalse(shouldDisplayNetworkSpeed(1024f, 1024f, 1))
+ }
+}