Commit 38f8993c authored by sheteng's avatar sheteng

加速修改模式切换2

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