diff --git a/app/src/main/java/com/termux/app/activities/SettingsActivity.java b/app/src/main/java/com/termux/app/activities/SettingsActivity.java index afb7373e97..08ac7fef59 100644 --- a/app/src/main/java/com/termux/app/activities/SettingsActivity.java +++ b/app/src/main/java/com/termux/app/activities/SettingsActivity.java @@ -11,6 +11,8 @@ 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 static class RootPreferencesFragment extends PreferenceFragmentCompat { 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 @@ private void setAboutOnPreferenceClickListener() { }); } } + + 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; + }); + } + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c00943eff..c149c4cba3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -170,7 +170,10 @@ Soft keyboard will be enabled only if no hardware keyboard is connected. - - About + + About + + + Donate diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 297b490366..f8efef7b70 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -8,8 +8,14 @@ + + diff --git a/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java b/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java index c4efab2352..2f38a3a929 100644 --- a/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/interact/ShareUtils.java @@ -4,6 +4,7 @@ import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.net.Uri; import androidx.core.content.ContextCompat; @@ -13,6 +14,8 @@ public class ShareUtils { + private static final String LOG_TAG = "ShareUtils"; + /** * Open the system app chooser that allows the user to select which app to send the intent. * @@ -68,4 +71,21 @@ public static void copyTextToClipboard(final Context context, final String text, } } + /** + * Open a url. + * + * @param context The context for operations. + * @param url The url to open. + */ + public static void openURL(final Context context, final String url) { + if (context == null || url == null || url.isEmpty()) return; + try { + Uri uri = Uri.parse(url); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + context.startActivity(intent); + } catch (Exception e) { + Logger.logStackTraceWithMessage(LOG_TAG, "Failed to open the url \"" + url + "\"", e); + } + } + } diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java index 2f4284d9ac..3d79dee7d7 100644 --- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java @@ -144,8 +144,11 @@ * * - 0.21.0 (2021-05-13) * - Added `APK_RELEASE_FDROID`, `APK_RELEASE_FDROID_SIGNING_CERTIFICATE_SHA256_DIGEST`, - * - Added `APK_RELEASE_GITHUB_DEBUG_BUILD`, `APK_RELEASE_GITHUB_DEBUG_BUILD_SIGNING_CERTIFICATE_SHA256_DIGEST`, - * - Added `APK_RELEASE_GOOGLE_PLAYSTORE`, `APK_RELEASE_GOOGLE_PLAYSTORE_SIGNING_CERTIFICATE_SHA256_DIGEST`. + * `APK_RELEASE_GITHUB_DEBUG_BUILD`, `APK_RELEASE_GITHUB_DEBUG_BUILD_SIGNING_CERTIFICATE_SHA256_DIGEST`, + * `APK_RELEASE_GOOGLE_PLAYSTORE`, `APK_RELEASE_GOOGLE_PLAYSTORE_SIGNING_CERTIFICATE_SHA256_DIGEST`. + * + * - 0.22.0 (2021-05-13) + * - Added `TERMUX_DONATE_URL`. * */ @@ -200,24 +203,6 @@ public final class TermuxConstants { /** Termux Github organization url */ public static final String TERMUX_GITHUB_ORGANIZATION_URL = "https://github.com" + "/" + TERMUX_GITHUB_ORGANIZATION_NAME; // Default: "https://github.com/termux" - /** Termux support email url */ - public static final String TERMUX_SUPPORT_EMAIL_URL = "termuxreports@groups.io"; // Default: "termuxreports@groups.io" - - /** Termux support email mailto url */ - public static final String TERMUX_SUPPORT_EMAIL_MAILTO_URL = "mailto:" + TERMUX_SUPPORT_EMAIL_URL; // Default: "mailto:termuxreports@groups.io" - - /** Termux Wiki */ - public static final String TERMUX_WIKI = "Termux Wiki"; // Default: "Termux Wiki" - - /** Termux Wiki url */ - public static final String TERMUX_WIKI_URL = "https://wiki.termux.com"; // Default: "https://wiki.termux.com" - - /** Termux Reddit subreddit */ - public static final String TERMUX_REDDIT_SUBREDDIT = "r/termux"; // Default: "r/termux" - - /** Termux Reddit subreddit url */ - public static final String TERMUX_REDDIT_SUBREDDIT_URL = "https://www.reddit.com/r/termux"; // Default: "https://www.reddit.com/r/termux" - /** F-Droid packages base url */ public static final String FDROID_PACKAGES_BASE_URL = "https://f-droid.org/en/packages"; // Default: "https://f-droid.org/en/packages" @@ -239,8 +224,6 @@ public final class TermuxConstants { public static final String TERMUX_GITHUB_REPO_URL = TERMUX_GITHUB_ORGANIZATION_URL + "/" + TERMUX_GITHUB_REPO_NAME; // Default: "https://github.com/termux/termux-app" /** Termux Github issues repo url */ public static final String TERMUX_GITHUB_ISSUES_REPO_URL = TERMUX_GITHUB_REPO_URL + "/issues"; // Default: "https://github.com/termux/termux-app/issues" - /** Termux Github wiki repo url */ - public static final String TERMUX_GITHUB_WIKI_REPO_URL = TERMUX_GITHUB_REPO_URL + "/wiki"; // Default: "https://github.com/termux/termux-app/wiki" /** Termux F-Droid package url */ public static final String TERMUX_FDROID_PACKAGE_URL = FDROID_PACKAGES_BASE_URL + "/" + TERMUX_PACKAGE_NAME; // Default: "https://f-droid.org/en/packages/com.termux" @@ -392,8 +375,6 @@ public final class TermuxConstants { public static final String TERMUX_PACKAGES_GITHUB_REPO_URL = TERMUX_GITHUB_ORGANIZATION_URL + "/" + TERMUX_PACKAGES_GITHUB_REPO_NAME; // Default: "https://github.com/termux/termux-packages" /** Termux Packages Github issues repo url */ public static final String TERMUX_PACKAGES_GITHUB_ISSUES_REPO_URL = TERMUX_PACKAGES_GITHUB_REPO_URL + "/issues"; // Default: "https://github.com/termux/termux-packages/issues" - /** Termux Packages wiki repo url */ - public static final String TERMUX_PACKAGES_GITHUB_WIKI_REPO_URL = TERMUX_PACKAGES_GITHUB_REPO_URL + "/wiki"; // Default: "https://github.com/termux/termux-packages/wiki" /** Termux Game Packages Github repo name */ @@ -439,6 +420,44 @@ public final class TermuxConstants { + /* + * Termux miscellaneous urls. + */ + + /** Termux Wiki */ + public static final String TERMUX_WIKI = TERMUX_APP_NAME + " Wiki"; // Default: "Termux Wiki" + + /** Termux Wiki url */ + public static final String TERMUX_WIKI_URL = "https://wiki.termux.com"; // Default: "https://wiki.termux.com" + + /** Termux Github wiki repo url */ + public static final String TERMUX_GITHUB_WIKI_REPO_URL = TERMUX_GITHUB_REPO_URL + "/wiki"; // Default: "https://github.com/termux/termux-app/wiki" + + /** Termux Packages wiki repo url */ + public static final String TERMUX_PACKAGES_GITHUB_WIKI_REPO_URL = TERMUX_PACKAGES_GITHUB_REPO_URL + "/wiki"; // Default: "https://github.com/termux/termux-packages/wiki" + + + /** Termux support email url */ + public static final String TERMUX_SUPPORT_EMAIL_URL = "termuxreports@groups.io"; // Default: "termuxreports@groups.io" + + /** Termux support email mailto url */ + public static final String TERMUX_SUPPORT_EMAIL_MAILTO_URL = "mailto:" + TERMUX_SUPPORT_EMAIL_URL; // Default: "mailto:termuxreports@groups.io" + + + /** Termux Reddit subreddit */ + public static final String TERMUX_REDDIT_SUBREDDIT = "r/termux"; // Default: "r/termux" + + /** Termux Reddit subreddit url */ + public static final String TERMUX_REDDIT_SUBREDDIT_URL = "https://www.reddit.com/r/termux"; // Default: "https://www.reddit.com/r/termux" + + + /** Termux donate url */ + public static final String TERMUX_DONATE_URL = TERMUX_PACKAGES_GITHUB_REPO_URL + "/wiki/Donate"; // Default: "https://github.com/termux/termux-packages/wiki/Donate" + + + + + /* * Termux app core directory paths. */