mirror of https://github.com/termux/termux-app
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:
parent
79df863b75
commit
6de3713049
|
@ -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>
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.ClipData;
|
|||
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 @@ import com.termux.shared.logger.Logger;
|
|||
|
||||
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 class ShareUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -144,8 +144,11 @@ import java.util.List;
|
|||
*
|
||||
* - 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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue