Commit 2ca6737f authored by Mygod's avatar Mygod

Remove redundant lazy initialization

parent d9de5430
...@@ -92,24 +92,22 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre ...@@ -92,24 +92,22 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
// service // service
var state = BaseService.IDLE var state = BaseService.IDLE
override val serviceCallback: IShadowsocksServiceCallback.Stub by lazy { override val serviceCallback = object : IShadowsocksServiceCallback.Stub() {
object : IShadowsocksServiceCallback.Stub() { override fun stateChanged(state: Int, profileName: String?, msg: String?) {
override fun stateChanged(state: Int, profileName: String?, msg: String?) { Core.handler.post { changeState(state, msg, true) }
Core.handler.post { changeState(state, msg, true) } }
} override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { Core.handler.post {
Core.handler.post { if (profileId == 0L) this@MainActivity.stats.updateTraffic(
if (profileId == 0L) this@MainActivity.stats.updateTraffic( stats.txRate, stats.rxRate, stats.txTotal, stats.rxTotal)
stats.txRate, stats.rxRate, stats.txTotal, stats.rxTotal) if (state != BaseService.STOPPING) {
if (state != BaseService.STOPPING) { (supportFragmentManager.findFragmentById(R.id.fragment_holder) as? ToolbarFragment)
(supportFragmentManager.findFragmentById(R.id.fragment_holder) as? ToolbarFragment) ?.onTrafficUpdated(profileId, stats)
?.onTrafficUpdated(profileId, stats)
}
} }
} }
override fun trafficPersisted(profileId: Long) { }
Core.handler.post { ProfilesFragment.instance?.onTrafficPersisted(profileId) } override fun trafficPersisted(profileId: Long) {
} Core.handler.post { ProfilesFragment.instance?.onTrafficPersisted(profileId) }
} }
} }
......
...@@ -42,33 +42,30 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface { ...@@ -42,33 +42,30 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
private val keyguard by lazy { getSystemService<KeyguardManager>()!! } private val keyguard by lazy { getSystemService<KeyguardManager>()!! }
private var tapPending = false private var tapPending = false
override val serviceCallback: IShadowsocksServiceCallback.Stub by lazy { override val serviceCallback = object : IShadowsocksServiceCallback.Stub() {
@RequiresApi(24) override fun stateChanged(state: Int, profileName: String?, msg: String?) {
object : IShadowsocksServiceCallback.Stub() { val tile = qsTile ?: return
override fun stateChanged(state: Int, profileName: String?, msg: String?) { var label: String? = null
val tile = qsTile ?: return when (state) {
var label: String? = null BaseService.STOPPED -> {
when (state) { tile.icon = iconIdle
BaseService.STOPPED -> { tile.state = Tile.STATE_INACTIVE
tile.icon = iconIdle }
tile.state = Tile.STATE_INACTIVE BaseService.CONNECTED -> {
} tile.icon = iconConnected
BaseService.CONNECTED -> { if (!keyguard.isDeviceLocked) label = profileName
tile.icon = iconConnected tile.state = Tile.STATE_ACTIVE
if (!keyguard.isDeviceLocked) label = profileName }
tile.state = Tile.STATE_ACTIVE else -> {
} tile.icon = iconBusy
else -> { tile.state = Tile.STATE_UNAVAILABLE
tile.icon = iconBusy
tile.state = Tile.STATE_UNAVAILABLE
}
} }
tile.label = label ?: getString(R.string.app_name)
tile.updateTile()
} }
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { } tile.label = label ?: getString(R.string.app_name)
override fun trafficPersisted(profileId: Long) { } tile.updateTile()
} }
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { }
override fun trafficPersisted(profileId: Long) { }
} }
override fun onServiceConnected(service: IShadowsocksService) { override fun onServiceConnected(service: IShadowsocksService) {
......
...@@ -89,20 +89,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -89,20 +89,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
// service // service
var state = BaseService.IDLE var state = BaseService.IDLE
private set private set
override val serviceCallback: IShadowsocksServiceCallback.Stub by lazy { override val serviceCallback = object : IShadowsocksServiceCallback.Stub() {
object : IShadowsocksServiceCallback.Stub() { override fun stateChanged(state: Int, profileName: String?, msg: String?) {
override fun stateChanged(state: Int, profileName: String?, msg: String?) { Core.handler.post { changeState(state, msg) }
Core.handler.post { changeState(state, msg) } }
} override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { if (profileId == 0L) this@MainPreferenceFragment.stats.summary = getString(R.string.stat_summary,
if (profileId == 0L) this@MainPreferenceFragment.stats.summary = getString(R.string.stat_summary, getString(R.string.speed, Formatter.formatFileSize(activity, stats.txRate)),
getString(R.string.speed, Formatter.formatFileSize(activity, stats.txRate)), getString(R.string.speed, Formatter.formatFileSize(activity, stats.rxRate)),
getString(R.string.speed, Formatter.formatFileSize(activity, stats.rxRate)), Formatter.formatFileSize(activity, stats.txTotal),
Formatter.formatFileSize(activity, stats.txTotal), Formatter.formatFileSize(activity, stats.rxTotal))
Formatter.formatFileSize(activity, stats.rxTotal))
}
override fun trafficPersisted(profileId: Long) { }
} }
override fun trafficPersisted(profileId: Long) { }
} }
private fun changeState(state: Int, msg: String? = null) { private fun changeState(state: Int, msg: String? = null) {
......
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