diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-14 04:59:24 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-14 05:06:18 +0200 |
commit | e8891d775b613781529e2f86cb063ee2f16a229f (patch) | |
tree | 069ddd86ba338411653a5c26e6b3570b6f507fbf /app/src/main/java/com/wireguard/android/preference/VersionPreference.java | |
parent | 0f128f99a1175b229fb82e2a802b1ea3fe4aedf5 (diff) |
global: supply backend asynchronously
We can't block for IO, so move everything to async workers or to
callbacks.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/preference/VersionPreference.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/preference/VersionPreference.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/app/src/main/java/com/wireguard/android/preference/VersionPreference.java b/app/src/main/java/com/wireguard/android/preference/VersionPreference.java index ab51644f..6b21977a 100644 --- a/app/src/main/java/com/wireguard/android/preference/VersionPreference.java +++ b/app/src/main/java/com/wireguard/android/preference/VersionPreference.java @@ -27,13 +27,14 @@ public class VersionPreference extends Preference { public VersionPreference(final Context context, final AttributeSet attrs) { super(context, attrs); - final Backend backend = Application.getBackend(); - versionSummary = getContext().getString(R.string.version_summary_checking, backend.getTypeName().toLowerCase()); - Application.getAsyncWorker().supplyAsync(backend::getVersion).whenComplete((version, exception) -> { - versionSummary = exception == null - ? getContext().getString(R.string.version_summary, backend.getTypeName(), version) - : getContext().getString(R.string.version_summary_unknown, backend.getTypeName().toLowerCase()); - notifyChanged(); + Application.onHaveBackend(backend -> { + versionSummary = getContext().getString(R.string.version_summary_checking, backend.getTypeName().toLowerCase()); + Application.getAsyncWorker().supplyAsync(backend::getVersion).whenComplete((version, exception) -> { + versionSummary = exception == null + ? getContext().getString(R.string.version_summary, backend.getTypeName(), version) + : getContext().getString(R.string.version_summary_unknown, backend.getTypeName().toLowerCase()); + notifyChanged(); + }); }); } |