mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -170,7 +170,10 @@
|
||||
<string name="termux_soft_keyboard_enabled_only_if_no_hardware_on">Soft keyboard will be enabled only if no hardware keyboard is connected.</string>
|
||||
|
||||
|
||||
<!-- About Preferences -->
|
||||
<string name="about_preferences_title">About</string>
|
||||
<!-- About Preference -->
|
||||
<string name="about_preference_title">About</string>
|
||||
|
||||
<!-- Donate Preference -->
|
||||
<string name="donate_preference_title">Donate</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -8,8 +8,14 @@
|
||||
|
||||
<Preference
|
||||
app:key="about"
|
||||
app:title="@string/about_preferences_title"
|
||||
app:title="@string/about_preference_title"
|
||||
app:persistent="false"/>
|
||||
<!-- app:layout="@layout/preference_markdown_text" -->
|
||||
|
||||
<Preference
|
||||
app:key="donate"
|
||||
app:title="@string/donate_preference_title"
|
||||
app:persistent="false"
|
||||
app:isPreferenceVisible="false"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
Reference in New Issue
Block a user