Skip to content

Commit

Permalink
Add in-app Donation link in Termux Settings for non google playstore …
Browse files Browse the repository at this point in the history
…releases

The `TermuxConstants` class has been updated to `v0.22.0`. Check its Changelog sections for info on changes.
  • Loading branch information
agnostic-apollo committed May 14, 2021
1 parent 79df863 commit 6de3713
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 29 deletions.
32 changes: 30 additions & 2 deletions app/src/main/java/com/termux/app/activities/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
});
}
}
}

}
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 7 additions & 1 deletion app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*
Expand Down Expand Up @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*
*/

Expand Down Expand Up @@ -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"

Expand All @@ -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"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 6de3713

Please sign in to comment.