diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-07 02:28:15 -0600 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-04-07 02:28:34 -0600 |
commit | b858284b1ea68c1a2065adab5ebc67c887155a5b (patch) | |
tree | eeae2460d9ea149127b6683c122e913fbaf6041c /ui/src/main/java | |
parent | 3c6e06f8d55b1ab8379beff65d8795bbdb26ce41 (diff) |
KernelModuleDisablerPreference: do not make synchronous calls to getBackend
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java')
-rw-r--r-- | ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt index 8e834260..1479d7b6 100644 --- a/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt +++ b/ui/src/main/java/com/wireguard/android/preference/KernelModuleDisablerPreference.kt @@ -18,11 +18,18 @@ import java9.util.concurrent.CompletableFuture import kotlin.system.exitProcess class KernelModuleDisablerPreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) { - private var state = if (Application.getBackend() is WgQuickBackend) State.ENABLED else State.DISABLED + private var state = State.UNKNOWN - override fun getSummary() = context.getString(state.summaryResourceId) + init { + isVisible = false + Application.getBackendAsync().thenAccept { backend -> + setState(if (backend is WgQuickBackend) State.ENABLED else State.DISABLED) + } + } + + override fun getSummary() = if (state == State.UNKNOWN) "" else context.getString(state.summaryResourceId) - override fun getTitle() = context.getString(state.titleResourceId) + override fun getTitle() = if (state == State.UNKNOWN) "" else context.getString(state.titleResourceId) @SuppressLint("ApplySharedPref") override fun onClick() { @@ -51,13 +58,15 @@ class KernelModuleDisablerPreference(context: Context, attrs: AttributeSet?) : P if (this.state == state) return this.state = state if (isEnabled != state.shouldEnableView) isEnabled = state.shouldEnableView + if (isVisible != state.visible) isVisible = state.visible notifyChanged() } - private enum class State(val titleResourceId: Int, val summaryResourceId: Int, val shouldEnableView: Boolean) { - ENABLED(R.string.module_disabler_enabled_title, R.string.module_disabler_enabled_summary, true), - DISABLED(R.string.module_disabler_disabled_title, R.string.module_disabler_disabled_summary, true), - ENABLING(R.string.module_disabler_disabled_title, R.string.success_application_will_restart, false), - DISABLING(R.string.module_disabler_enabled_title, R.string.success_application_will_restart, false); + private enum class State(val titleResourceId: Int, val summaryResourceId: Int, val shouldEnableView: Boolean, val visible: Boolean) { + UNKNOWN(0, 0, false, false), + ENABLED(R.string.module_disabler_enabled_title, R.string.module_disabler_enabled_summary, true, true), + DISABLED(R.string.module_disabler_disabled_title, R.string.module_disabler_disabled_summary, true, true), + ENABLING(R.string.module_disabler_disabled_title, R.string.success_application_will_restart, false, true), + DISABLING(R.string.module_disabler_enabled_title, R.string.success_application_will_restart, false, true); } } |