mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-10 20:44:12 +08:00
Add in-app Donation link in Termux Settings for non google playstore releases
The `TermuxConstants` class has been updated to `v0.22.0`. Check its Changelog sections for info on changes.
This commit is contained in:
@@ -11,6 +11,8 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
import com.termux.R;
|
||||
import com.termux.app.models.ReportInfo;
|
||||
import com.termux.app.models.UserAction;
|
||||
import com.termux.shared.interact.ShareUtils;
|
||||
import com.termux.shared.packages.PackageUtils;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
import com.termux.shared.termux.TermuxUtils;
|
||||
|
||||
@@ -44,10 +46,11 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey);
|
||||
|
||||
setAboutOnPreferenceClickListener();
|
||||
configureAboutPreference();
|
||||
configureDonatePreference();
|
||||
}
|
||||
|
||||
private void setAboutOnPreferenceClickListener() {
|
||||
private void configureAboutPreference() {
|
||||
Context context = getContext();
|
||||
Preference about = findPreference("about");
|
||||
if (context != null && about != null) {
|
||||
@@ -70,6 +73,31 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void configureDonatePreference() {
|
||||
Context context = getContext();
|
||||
Preference donate = findPreference("donate");
|
||||
if (context != null && donate != null) {
|
||||
String signingCertificateSHA256Digest = PackageUtils.getSigningCertificateSHA256DigestForPackage(context);
|
||||
if (signingCertificateSHA256Digest != null) {
|
||||
// If APK is a Google Playstore release, then do not show the donation link
|
||||
// since Termux isn't exempted from the playstore policy donation links restriction
|
||||
// Check Fund solicitations: https://pay.google.com/intl/en_in/about/policy/
|
||||
String apkRelease = TermuxUtils.getAPKRelease(signingCertificateSHA256Digest);
|
||||
if (apkRelease == null || apkRelease.equals(TermuxConstants.APK_RELEASE_GOOGLE_PLAYSTORE_SIGNING_CERTIFICATE_SHA256_DIGEST)) {
|
||||
donate.setVisible(false);
|
||||
return;
|
||||
} else {
|
||||
donate.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
donate.setOnPreferenceClickListener(preference -> {
|
||||
ShareUtils.openURL(context, TermuxConstants.TERMUX_DONATE_URL);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user