From 88fc092aa283bebdc623c0889a7cd68ea2badef8 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 4 Feb 2018 04:12:17 -0800 Subject: [PATCH] Get rid of postDelayeds FASTER! --- .../java/com/github/shadowsocks/VpnRequestActivity.kt | 8 +++----- .../java/com/github/shadowsocks/widget/ServiceButton.kt | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/mobile/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt b/mobile/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt index 2ce7837c..da0cc06d 100644 --- a/mobile/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt +++ b/mobile/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt @@ -56,11 +56,9 @@ class VpnRequestActivity : AppCompatActivity(), ShadowsocksConnection.Interface } override fun onServiceConnected(service: IShadowsocksService) { - app.handler.postDelayed({ - val intent = VpnService.prepare(this) - if (intent == null) onActivityResult(REQUEST_CONNECT, RESULT_OK, null) - else startActivityForResult(intent, REQUEST_CONNECT) - }, 1000) + val intent = VpnService.prepare(this) + if (intent == null) onActivityResult(REQUEST_CONNECT, RESULT_OK, null) + else startActivityForResult(intent, REQUEST_CONNECT) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { diff --git a/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt b/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt index 8569990c..670f68de 100644 --- a/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt +++ b/mobile/src/main/java/com/github/shadowsocks/widget/ServiceButton.kt @@ -84,9 +84,7 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute TooltipCompat.setTooltipText(this, context.getString(R.string.connect)) } refreshDrawableState() - isEnabled = false - if (state == BaseService.CONNECTED || state == BaseService.STOPPED) app.handler.postDelayed( - { isEnabled = state == BaseService.CONNECTED || state == BaseService.STOPPED }, 1000) + isEnabled = state == BaseService.CONNECTED || state == BaseService.STOPPED } private fun counters(a: AnimatedVectorDrawableCompat, b: AnimatedVectorDrawableCompat): Boolean =