From c64b6ef2293754b337d7b0a91358a819cd77ffd9 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 11 Feb 2022 23:08:16 +0800 Subject: [PATCH] Version 5.1.8. Add Reddit User Agreement to settings. Move Privacy Policy option from About to main settings page. --- app/build.gradle | 4 +-- .../activities/LoginActivity.java | 33 +++++++++++++++++++ .../settings/AboutPreferenceFragment.java | 13 -------- .../settings/MainPreferenceFragment.java | 25 ++++++++++++++ .../utils/SharedPreferencesUtils.java | 1 + app/src/main/res/values/strings.xml | 6 ++++ app/src/main/res/xml/about_preferences.xml | 4 --- app/src/main/res/xml/main_preferences.xml | 8 +++++ 8 files changed, 75 insertions(+), 19 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e55aa22b..548b70fa 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "ml.docilealligator.infinityforreddit" minSdkVersion 21 targetSdkVersion 30 - versionCode 92 - versionName "5.1.7" + versionCode 93 + versionName "5.1.8" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java index 8e143136..552dbca9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/LoginActivity.java @@ -8,6 +8,8 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; +import android.text.SpannableString; +import android.text.util.Linkify; import android.util.Log; import android.view.InflateException; import android.view.MenuItem; @@ -40,6 +42,7 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import me.saket.bettermovementmethod.BetterLinkMovementMethod; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -58,6 +61,7 @@ import retrofit2.Retrofit; public class LoginActivity extends BaseActivity { private static final String ENABLE_DOM_STATE = "EDS"; + private static final String IS_AGREE_TO_USER_AGGREMENT_STATE = "IATUAS"; @BindView(R.id.coordinator_layout_login_activity) CoordinatorLayout coordinatorLayout; @@ -91,6 +95,7 @@ public class LoginActivity extends BaseActivity { Executor mExecutor; private String authCode; private boolean enableDom = false; + private boolean isAgreeToUserAgreement = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -123,6 +128,7 @@ public class LoginActivity extends BaseActivity { if (savedInstanceState != null) { enableDom = savedInstanceState.getBoolean(ENABLE_DOM_STATE); + isAgreeToUserAgreement = savedInstanceState.getBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE); } fab.setOnClickListener(view -> { @@ -260,12 +266,39 @@ public class LoginActivity extends BaseActivity { super.onPageFinished(view, url); } }); + + if (!isAgreeToUserAgreement) { + TextView messageTextView = new TextView(this); + int padding = (int) Utils.convertDpToPixel(24, this); + messageTextView.setPaddingRelative(padding, padding, padding, padding); + SpannableString message = new SpannableString(getString(R.string.user_agreement_message, "https://www.redditinc.com/policies/user-agreement-september-12-2021", "https://docile-alligator.github.io")); + Linkify.addLinks(message, Linkify.WEB_URLS); + messageTextView.setMovementMethod(BetterLinkMovementMethod.newInstance().setOnLinkClickListener(new BetterLinkMovementMethod.OnLinkClickListener() { + @Override + public boolean onClick(TextView textView, String url) { + Intent intent = new Intent(LoginActivity.this, LinkResolverActivity.class); + intent.setData(Uri.parse(url)); + startActivity(intent); + return true; + } + })); + messageTextView.setLinkTextColor(getResources().getColor(R.color.colorAccent)); + messageTextView.setText(message); + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(getString(R.string.user_agreement_dialog_title)) + .setView(messageTextView) + .setPositiveButton(R.string.agree, (dialogInterface, i) -> isAgreeToUserAgreement = true) + .setNegativeButton(R.string.do_not_agree, (dialogInterface, i) -> finish()) + .setCancelable(false) + .show(); + } } @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(ENABLE_DOM_STATE, enableDom); + outState.putBoolean(IS_AGREE_TO_USER_AGGREMENT_STATE, isAgreeToUserAgreement); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java index abcdb0d3..f746cf48 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/AboutPreferenceFragment.java @@ -35,7 +35,6 @@ public class AboutPreferenceFragment extends CustomFontPreferenceFragmentCompat Preference redditAccountPreference = findPreference(SharedPreferencesUtils.REDDIT_ACCOUNT_KEY); Preference subredditPreference = findPreference(SharedPreferencesUtils.SUBREDDIT_KEY); Preference sharePreference = findPreference(SharedPreferencesUtils.SHARE_KEY); - Preference privacyPolicyPreference = findPreference(SharedPreferencesUtils.PRIVACY_POLICY_KEY); Preference versionPreference = findPreference(SharedPreferencesUtils.VERSION_KEY); if (openSourcePreference != null) { @@ -107,18 +106,6 @@ public class AboutPreferenceFragment extends CustomFontPreferenceFragmentCompat }); } - if (privacyPolicyPreference != null) { - privacyPolicyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Intent intent = new Intent(activity, LinkResolverActivity.class); - intent.setData(Uri.parse("https://docile-alligator.github.io/")); - activity.startActivity(intent); - return true; - } - }); - } - if (versionPreference != null) { versionPreference.setSummary(getString(R.string.settings_version_summary, BuildConfig.VERSION_NAME)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java index 272af42f..80ff74ab 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/MainPreferenceFragment.java @@ -6,6 +6,7 @@ import static androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTI import android.content.Intent; import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; import androidx.biometric.BiometricManager; @@ -16,6 +17,7 @@ import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity; import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity; import ml.docilealligator.infinityforreddit.customviews.CustomFontPreferenceFragmentCompat; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -37,6 +39,8 @@ public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat { Preference securityPreference = findPreference(SharedPreferencesUtils.SECURITY); Preference postFilterPreference = findPreference(SharedPreferencesUtils.POST_FILTER); + Preference privacyPolicyPreference = findPreference(SharedPreferencesUtils.PRIVACY_POLICY_KEY); + Preference redditUserAgreementPreference = findPreference(SharedPreferencesUtils.REDDIT_USER_AGREEMENT_KEY); BiometricManager biometricManager = BiometricManager.from(activity); if (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL) != BiometricManager.BIOMETRIC_SUCCESS) { @@ -52,5 +56,26 @@ public class MainPreferenceFragment extends CustomFontPreferenceFragmentCompat { return true; }); } + + if (privacyPolicyPreference != null) { + privacyPolicyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(activity, LinkResolverActivity.class); + intent.setData(Uri.parse("https://docile-alligator.github.io/")); + activity.startActivity(intent); + return true; + } + }); + } + + if (redditUserAgreementPreference != null) { + redditUserAgreementPreference.setOnPreferenceClickListener(preference -> { + Intent intent = new Intent(activity, LinkResolverActivity.class); + intent.setData(Uri.parse("https://www.redditinc.com/policies/user-agreement-september-12-2021")); + activity.startActivity(intent); + return true; + }); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index 9c20f2f6..803ca8ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -43,6 +43,7 @@ public class SharedPreferencesUtils { public static final String CUSTOM_FONT_FAMILY_KEY = "custom_font_family"; public static final String CUSTOM_TITLE_FONT_FAMILY_KEY = "custom_title_font_family"; public static final String CUSTOM_CONTENT_FONT_FAMILY_KEY = "custom_content_font_family"; + public static final String REDDIT_USER_AGREEMENT_KEY = "reddit_user_agreement"; public static final String SORT_TYPE_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.sort_type"; public static final String SORT_TYPE_BEST_POST = "sort_type_best_post"; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bcb4d083..ce9583e9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -630,6 +630,7 @@ Show Fewer Toolbar Options Starting From Level %1$d Hide Author Avatar + Reddit User Agreement Cannot get the link @@ -1264,4 +1265,9 @@ Caption (max 180 characters) Url + User Agreement + You need to agree to Reddit User Agreement (%1$s) and Infinity for Reddit\'s Privacy Policy (%2$s) before logging in. + Agree + Don\'t Agree + diff --git a/app/src/main/res/xml/about_preferences.xml b/app/src/main/res/xml/about_preferences.xml index cff7c151..6503e6fa 100644 --- a/app/src/main/res/xml/about_preferences.xml +++ b/app/src/main/res/xml/about_preferences.xml @@ -46,10 +46,6 @@ app:title="@string/settings_share_title" app:summary="@string/settings_share_summary" /> - - + + + + \ No newline at end of file