Commit 38f8993c authored by sheteng's avatar sheteng

加速修改模式切换2

parent ceedf52f
......@@ -63,7 +63,7 @@ class AcceleratorFragment : XPageFragment() {
override fun initViews() {
acceleratorViewModel.netState.observe(this, {
if (it.preNetDelay != -1) { //有网络
if (it.preNetDelay != -1 && state == BaseService.State.Connected) { //有网络
binding.preDelay1.setText(it.preNetDelay.toString())
binding.preDelay2.setText(it.preNetDelay.toString())
......@@ -77,7 +77,7 @@ class AcceleratorFragment : XPageFragment() {
binding.preDelay2Unit.visibility = View.GONE
}
if (it.accNetDelay != -1) {
if (it.accNetDelay != -1 && state == BaseService.State.Connected) {
binding.netDelay1.setText(it.accNetDelay.toString())
binding.netDelay2.setText(it.accNetDelay.toString())
binding.netDelay1Unit.visibility = View.VISIBLE
......
......@@ -85,6 +85,8 @@ object AcceleratorUtils {
delay(1000)
}
}
} else {
networkStatsListener(state, getAccTime(), netState)
}
}
......@@ -177,7 +179,6 @@ object AcceleratorUtils {
profile.password = "barfoo!"
profile.method = "none"
profile.beatsInterval = 10
NetworkAdapter.initNetworks(context)
withContext(Dispatchers.Main) {
ProfileManager.updateProfile(profile)
connect.launch(null)
......
......@@ -168,8 +168,10 @@ object AuthManager {
if (wifiLatencyList.size == 5) {
val wifiavg = wifiLatencyList.average().toInt()
val celavg = cellularLatencyList.average().toInt()
if (wifiavg > celavg && wifiavg > 200) {
if (wifiavg > celavg && wifiavg > 200 && celavg != -1) {
NetworkAdapter.useCellular(Core.deviceStorage)
} else if (celavg > wifiavg && wifiavg != -1) {
NetworkAdapter.useWifi(Core.deviceStorage)
}
wifiLatencyList.clear()
cellularLatencyList.clear()
......@@ -190,14 +192,14 @@ object AuthManager {
isSmartAccOpen // 根据用户设置测试延迟 ,过高时切换 connection.bindNetwork(NetworkMode.CELLULAR.code)
if (networkAutoSwitch) {
val wifiLatency: Int = doTestLatency(
DataStore.pingAccHost,
DataStore.pingAccPort,
"114.114.114.114",
53,
NetworkAdapter.wifiNetwork
)
wifiLatencyList.add(wifiLatency)
val cellularLatency: Int = doTestLatency(
DataStore.pingAccHost,
DataStore.pingAccPort,
"114.114.114.114",
53,
NetworkAdapter.cellularNetwork
)
cellularLatencyList.add(cellularLatency)
......
......@@ -120,7 +120,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
get() = privateStore.getInt(Key.pingIntervalSec) ?: 1
set(value) = privateStore.putInt(Key.pingIntervalSec, value)
var pingTimeoutMillis: Int
get() = privateStore.getInt(Key.pingTimeoutMillis) ?: 200
get() = privateStore.getInt(Key.pingTimeoutMillis) ?: 1000
set(value) = privateStore.putInt(Key.pingTimeoutMillis, value)
var pingAccHost: String
get() = privateStore.getString(Key.pingAccHost) ?: ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment