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
} else {
TrafficMonitor.reset()
}
val pm = getSystemService(Context.POWER_SERVICE).asInstanceOf[PowerManager]
if (pm.isScreenOn) {
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
handler.post(() => {
preferences.findPreference(Key.stat).setSummary(trafficStat)
})
}
val trafficStat = getString(R.string.stat_summary).formatLocal(Locale.ENGLISH,
TrafficMonitor.getTxRate, TrafficMonitor.getRxRate,
TrafficMonitor.getTxTotal, TrafficMonitor.getRxTotal)
handler.post(() => {
preferences.findPreference(Key.stat).setSummary(trafficStat)
})
}
}
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