diff --git a/android/res/layout/fragment_welcome.xml b/android/res/layout/fragment_welcome.xml index 6be6f42071..18ce7fbb56 100644 --- a/android/res/layout/fragment_welcome.xml +++ b/android/res/layout/fragment_welcome.xml @@ -12,6 +12,7 @@ onTermsOfUseViewChanged(isChecked)); mPrivacyPolicyCheckbox.setOnCheckedChangeListener( (buttonView, isChecked) -> onPrivacyPolicyViewChanged(isChecked)); - UiUtils.linkifyPolicyView(mContentView, R.id.privacy_policy_welcome, - R.string.sign_agree_pp_gdpr, Framework.nativeGetPrivacyPolicyLink()); + UiUtils.linkifyView(mContentView, R.id.privacy_policy_welcome, + R.string.sign_agree_pp_gdpr, Framework.nativeGetPrivacyPolicyLink()); - UiUtils.linkifyPolicyView(mContentView, R.id.term_of_use_welcome, - R.string.sign_agree_tof_gdpr, Framework.nativeGetTermsOfUseLink()); + UiUtils.linkifyView(mContentView, R.id.term_of_use_welcome, + R.string.sign_agree_tof_gdpr, Framework.nativeGetTermsOfUseLink()); } private void onPrivacyPolicyViewChanged(boolean isChecked) { - onCheckedValueChanged(isChecked, mTermOfUseCheckbox.isChecked(), - SharedPropertiesUtils.USER_AGREEMENT_PRIVACY_POLICY); + SharedPropertiesUtils.putPrivacyPolicyAgreement(requireContext(), isChecked); + onCheckedValueChanged(isChecked, mTermOfUseCheckbox.isChecked()); } private void onTermsOfUseViewChanged(boolean isChecked) { - onCheckedValueChanged(isChecked, mPrivacyPolicyCheckbox.isChecked(), - SharedPropertiesUtils.USER_AGREEMENT_TERM_OF_USE); + SharedPropertiesUtils.putTermOfUseAgreement(requireContext(), isChecked); + onCheckedValueChanged(isChecked, mPrivacyPolicyCheckbox.isChecked()); } private void onCheckedValueChanged(boolean isChecked, - boolean isAnotherConditionChecked, - @NonNull String key) + boolean isAnotherConditionChecked) { - applyPreferenceChanges(key, isChecked); boolean isAgreementGranted = isChecked && isAnotherConditionChecked; if (!isAgreementGranted) return; @@ -269,11 +266,10 @@ public class WelcomeDialogFragment extends BaseMwmDialogFragment implements View editor.putBoolean(key, value).apply(); } - private static boolean isAgreementDenied(@NonNull Context context) + private static boolean isAgreementDeclined(@NonNull Context context) { - SharedPreferences prefs = MwmApplication.prefs(context); - return !prefs.getBoolean(SharedPropertiesUtils.USER_AGREEMENT_TERM_OF_USE, false) - || !prefs.getBoolean(SharedPropertiesUtils.USER_AGREEMENT_PRIVACY_POLICY, false); + return !SharedPropertiesUtils.isTermOfUseAgreementConfirmed(context) + || !SharedPropertiesUtils.isPrivacyPolicyAgreementConfirmed(context); } diff --git a/android/src/com/mapswithme/util/SharedPropertiesUtils.java b/android/src/com/mapswithme/util/SharedPropertiesUtils.java index 1462e3d4b0..88707ea140 100644 --- a/android/src/com/mapswithme/util/SharedPropertiesUtils.java +++ b/android/src/com/mapswithme/util/SharedPropertiesUtils.java @@ -14,8 +14,8 @@ import static com.mapswithme.util.Config.KEY_PREF_STATISTICS; public final class SharedPropertiesUtils { - public static final String USER_AGREEMENT_TERM_OF_USE = "user_agreement_term_of_use"; - public static final String USER_AGREEMENT_PRIVACY_POLICY = "user_agreement_privacy_policy"; + private static final String USER_AGREEMENT_TERM_OF_USE = "user_agreement_term_of_use"; + private static final String USER_AGREEMENT_PRIVACY_POLICY = "user_agreement_privacy_policy"; private static final String PREFS_SHOW_EMULATE_BAD_STORAGE_SETTING = "ShowEmulateBadStorageSetting"; private static final String PREFS_BACKUP_WIDGET_EXPANDED = "BackupWidgetExpanded"; private static final String PREFS_WHATS_NEW_TITLE_CONCATENATION = "WhatsNewTitleConcatenation"; @@ -105,4 +105,37 @@ public final class SharedPropertiesUtils .putInt(PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE, pageIndex) .apply(); } + + public static boolean isTermOfUseAgreementConfirmed(@NonNull Context context) + { + return getBoolean(context, USER_AGREEMENT_TERM_OF_USE); + } + + public static boolean isPrivacyPolicyAgreementConfirmed(@NonNull Context context) + { + return getBoolean(context, USER_AGREEMENT_PRIVACY_POLICY); + } + + public static void putPrivacyPolicyAgreement(@NonNull Context context, boolean isChecked) + { + putBoolean(context, USER_AGREEMENT_PRIVACY_POLICY, isChecked); + } + + public static void putTermOfUseAgreement(@NonNull Context context, boolean isChecked) + { + putBoolean(context, USER_AGREEMENT_TERM_OF_USE, isChecked); + } + + private static boolean getBoolean(@NonNull Context context, @NonNull String key) + { + return MwmApplication.prefs(context).getBoolean(key, false); + } + + private static void putBoolean(@NonNull Context context, @NonNull String key, boolean value) + { + MwmApplication.prefs(context) + .edit() + .putBoolean(key, value) + .apply(); + } } diff --git a/android/src/com/mapswithme/util/UiUtils.java b/android/src/com/mapswithme/util/UiUtils.java index ef6bb48780..0042d9f164 100644 --- a/android/src/com/mapswithme/util/UiUtils.java +++ b/android/src/com/mapswithme/util/UiUtils.java @@ -65,10 +65,10 @@ public final class UiUtils frontView.bringToFront(); } - public static void linkifyPolicyView(@NonNull View root, @IdRes int id, @StringRes int stringId, - @NonNull String link) + public static void linkifyView(@NonNull View view, @IdRes int id, @StringRes int stringId, + @NonNull String link) { - TextView policyView = root.findViewById(id); + TextView policyView = view.findViewById(id); Resources rs = policyView.getResources(); policyView.setText(Html.fromHtml(rs.getString(stringId, link))); policyView.setMovementMethod(LinkMovementMethod.getInstance());