diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-01 16:06:56 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-01 16:06:56 +0200 |
commit | 1e45898d7035b5d617a3181cf1b6dfab8a10eae9 (patch) | |
tree | 6d4574252ab2a07ea51e6b836c92a9ee82f57756 /app/src/main/java/com/wireguard/android/preference/VersionPreference.java | |
parent | 61431fb57946ce92f6fa613c4683ac95b75f02de (diff) |
Settings: add version
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 | 56 |
1 files changed, 56 insertions, 0 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 new file mode 100644 index 00000000..c0fb986b --- /dev/null +++ b/app/src/main/java/com/wireguard/android/preference/VersionPreference.java @@ -0,0 +1,56 @@ +/* + * Copyright © 2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +package com.wireguard.android.preference; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.v7.preference.Preference; +import android.util.AttributeSet; + +import com.wireguard.android.Application; +import com.wireguard.android.BuildConfig; +import com.wireguard.android.R; +import com.wireguard.android.backend.GoBackend; +import com.wireguard.android.backend.WgQuickBackend; + +public class VersionPreference extends Preference { + private String versionSummary; + + public VersionPreference(final Context context, final AttributeSet attrs) { + super(context, attrs); + + if (Application.getComponent().getBackendType() == GoBackend.class) { + versionSummary = getContext().getString(R.string.version_userspace_summary, GoBackend.getVersion()); + } else if (Application.getComponent().getBackendType() == WgQuickBackend.class) { + Application.getComponent().getToolsInstaller().getVersion().whenComplete((version, exception) -> { + if (exception == null) + versionSummary = getContext().getString(R.string.version_kernel_summary, version); + else + versionSummary = getContext().getString(R.string.version_kernel_unknown_summary); + notifyChanged(); + }); + } + } + + @Override + public CharSequence getSummary() { + return versionSummary; + } + + @Override + public CharSequence getTitle() { + return getContext().getString(R.string.version_title, BuildConfig.VERSION_NAME); + } + + @Override + protected void onClick() { + final Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse("https://www.wireguard.com/")); + getContext().startActivity(intent); + } + +} |