Skip to content

Commit 497a60c

Browse files
committed
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: streetcomplete/StreetComplete#3768 Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent 8139e60 commit 497a60c

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

ui/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ android {
4848
}
4949
}
5050
buildTypes {
51+
all {
52+
buildConfigField('boolean', 'IS_GOOGLE_PLAY', (findProperty('build.google_play') == 'true').toString())
53+
}
5154
release {
5255
if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release
5356
minifyEnabled true
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright © 2017-2023 WireGuard LLC. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package com.wireguard.android.preference
7+
8+
import android.app.AlertDialog
9+
import android.content.ActivityNotFoundException
10+
import android.content.Context
11+
import android.content.Intent
12+
import android.net.Uri
13+
import android.util.AttributeSet
14+
import androidx.preference.Preference
15+
import com.wireguard.android.BuildConfig
16+
import com.wireguard.android.R
17+
18+
class DonatePreference(context: Context, attrs: AttributeSet?) : Preference(context, attrs) {
19+
override fun getSummary() = context.getString(R.string.donate_summary)
20+
21+
override fun getTitle() = context.getString(R.string.donate_title)
22+
23+
override fun onClick() {
24+
if (BuildConfig.IS_GOOGLE_PLAY) {
25+
AlertDialog.Builder(context)
26+
.setTitle(R.string.donate_title)
27+
.setMessage(R.string.donate_google_play_disappointment)
28+
.show()
29+
return
30+
}
31+
val intent = Intent(Intent.ACTION_VIEW)
32+
intent.data = Uri.parse("https://www.wireguard.com/donations/")
33+
try {
34+
context.startActivity(intent)
35+
} catch (ignored: ActivityNotFoundException) {
36+
}
37+
}
38+
}

ui/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
<string name="tv_select_a_storage_drive">Select a storage drive</string>
109109
<string name="tv_no_file_picker">Please install a file management utility to browse files</string>
110110
<string name="tv_add_tunnel_get_started">Add a tunnel to get started</string>
111+
<string name="donate_title">♥ Donate to the WireGuard Project</string>
112+
<string name="donate_summary">Every contribution helps</string>
113+
<string name="donate_google_play_disappointment">Thank you for supporting the WireGuard Project!\n\nUnfortunately, due to Google\'s policies, we\'re not allowed to link to the part of the project webpage where you can make a donation. Hopefully you can figure this out!\n\nThanks again for your contribution.</string>
111114
<string name="disable_config_export_title">Disable config exporting</string>
112115
<string name="disable_config_export_description">Disabling config exporting makes private keys less accessible</string>
113116
<string name="dns_servers">DNS servers</string>

ui/src/main/res/xml/preferences.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@
4040
android:summaryOff="@string/allow_remote_control_intents_summary_off"
4141
android:summaryOn="@string/allow_remote_control_intents_summary_on"
4242
android:title="@string/allow_remote_control_intents_title" />
43+
<com.wireguard.android.preference.DonatePreference
44+
android:singleLineTitle="false" />
4345
</androidx.preference.PreferenceScreen>

0 commit comments

Comments
 (0)