Commit 3f8acd85 authored by Mygod's avatar Mygod

Optimize timer code.

Apparently onStop will be executed when the screen goes off.
parent 14414c64
...@@ -475,15 +475,12 @@ class Shadowsocks ...@@ -475,15 +475,12 @@ class Shadowsocks
} else { } else {
TrafficMonitor.reset() TrafficMonitor.reset()
} }
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager] val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
if (pm.isScreenOn) { TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH, TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate, handler.post(() => {
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal) preferences.findPreference(Key.stat).setSummary(trafficStat)
handler.post(() => { })
preferences.findPreference(Key.stat).setSummary(trafficStat)
})
}
} }
} }
timer = new Timer(true) timer = new Timer(true)
......
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