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>
This commit is contained in:
Jason A. Donenfeld 2023-03-23 13:43:35 +01:00
parent 8139e60094
commit 497a60cc90
4 changed files with 46 additions and 0 deletions

View File

@ -48,6 +48,9 @@ android {
}
}
buildTypes {
all {
buildConfigField('boolean', 'IS_GOOGLE_PLAY', (findProperty('build.google_play') == 'true').toString())
}
release {
if (keystorePropertiesFile.exists()) signingConfig signingConfigs.release
minifyEnabled true

View File

@ -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) {
}
}
}

View File

@ -108,6 +108,9 @@
<string name="tv_select_a_storage_drive">Select a storage drive</string>
<string name="tv_no_file_picker">Please install a file management utility to browse files</string>
<string name="tv_add_tunnel_get_started">Add a tunnel to get started</string>
<string name="donate_title">♥ Donate to the WireGuard Project</string>
<string name="donate_summary">Every contribution helps</string>
<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>
<string name="disable_config_export_title">Disable config exporting</string>
<string name="disable_config_export_description">Disabling config exporting makes private keys less accessible</string>
<string name="dns_servers">DNS servers</string>

View File

@ -40,4 +40,6 @@
android:summaryOff="@string/allow_remote_control_intents_summary_off"
android:summaryOn="@string/allow_remote_control_intents_summary_on"
android:title="@string/allow_remote_control_intents_title" />
<com.wireguard.android.preference.DonatePreference
android:singleLineTitle="false" />
</androidx.preference.PreferenceScreen>