summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2023-03-23 13:43:35 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2023-03-24 14:16:08 +0100
commit497a60cc90e6559111e6564e8723f87c0df4632c (patch)
treeecb38ae09fb9178e7d66dbf11b080ef45de751a2 /ui/src/main/java/com
parent8139e600940d286000e8db4e9398104012d08d64 (diff)
ui: bring back donation button
For Google Play Store builds, we'll display an alert box. This was inspired by the discussion around StreetComplete; hopefully we'll have a similar okay outcome. Link: https://github.com/streetcomplete/streetcomplete/issues/3768 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'ui/src/main/java/com')
-rw-r--r--ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt38
1 files changed, 38 insertions, 0 deletions
diff --git a/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt
new file mode 100644
index 00000000..57202c81
--- /dev/null
+++ b/ui/src/main/java/com/wireguard/android/preference/DonatePreference.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2017-2023 WireGuard LLC. All Rights Reserved.
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package com.wireguard.android.preference
+
+import android.app.AlertDialog
+import android.content.ActivityNotFoundException
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+import android.util.AttributeSet
+import androidx.preference.Preference
+import com.wireguard.android.BuildConfig
+import com.wireguard.android.R
+
+class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
+ override fun getSummary() = context.getString(R.string.donate_summary)
+
+ override fun getTitle() = context.getString(R.string.donate_title)
+
+ override fun onClick() {
+ if (BuildConfig.IS_GOOGLE_PLAY) {
+ AlertDialog.Builder(context)
+ .setTitle(R.string.donate_title)
+ .setMessage(R.string.donate_google_play_disappointment)
+ .show()
+ return
+ }
+ val intent = Intent(Intent.ACTION_VIEW)
+ intent.data = Uri.parse("https://www.wireguard.com/donations/")
+ try {
+ context.startActivity(intent)
+ } catch (ignored: ActivityNotFoundException) {
+ }
+ }
+} \ No newline at end of file