From 2f1b6ce0e08595ca6202c1328f44a3699cceebbf Mon Sep 17 00:00:00 2001 From: Konstantin Pastbin Date: Wed, 4 Dec 2024 01:24:30 +0300 Subject: [PATCH] [android] Add a setting to display Kayak links Disabled by default in F-Droid build, enabled in other builds. Signed-off-by: Konstantin Pastbin --- .../java/app/organicmaps/MwmActivity.java | 9 +- .../settings/SettingsPrefsFragment.java | 16 ++ .../java/app/organicmaps/util/Config.java | 13 ++ .../sections/PlacePageLinksFragment.java | 5 +- .../src/main/res/values/donottranslate.xml | 2 + android/app/src/main/res/xml/prefs_main.xml | 7 + data/strings/strings.txt | 140 ++++++++++++++++++ 7 files changed, 187 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/app/organicmaps/MwmActivity.java b/android/app/src/main/java/app/organicmaps/MwmActivity.java index c5baf60699..d64562190f 100644 --- a/android/app/src/main/java/app/organicmaps/MwmActivity.java +++ b/android/app/src/main/java/app/organicmaps/MwmActivity.java @@ -1726,7 +1726,8 @@ public class MwmActivity extends BaseMwmFragmentActivity public void openKayakLink(@NonNull String url) { - if (Config.isKayakDisclaimerAccepted()) + // The disclaimer is not needed if a user had explicitly opted-in via the setting. + if (Config.isKayakDisclaimerAccepted() || Config.isKayakDisplayEnabled()) { Utils.openUrl(this, url); return; @@ -1736,12 +1737,16 @@ public class MwmActivity extends BaseMwmFragmentActivity mAlertDialog = new MaterialAlertDialogBuilder(this, R.style.MwmTheme_AlertDialog) .setTitle(R.string.how_to_support_us) .setMessage(R.string.dialog_kayak_disclaimer) - .setCancelable(false) + .setCancelable(true) .setPositiveButton(R.string.dialog_kayak_button, (dlg, which) -> { Config.acceptKayakDisclaimer(); Utils.openUrl(this, url); }) .setNegativeButton(R.string.cancel, null) + .setNeutralButton(R.string.dialog_kayak_disable_button, (dlg, which) -> { + Config.setKayakDisplay(false); + UiUtils.hide(findViewById(R.id.ll__place_kayak)); + }) .setOnDismissListener(dialog -> mAlertDialog = null) .show(); } diff --git a/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java b/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java index 5fad681533..b7d8e35f69 100644 --- a/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java +++ b/android/app/src/main/java/app/organicmaps/settings/SettingsPrefsFragment.java @@ -66,6 +66,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La initPowerManagementPrefsCallbacks(); initPlayServicesPrefsCallbacks(); initSearchPrivacyPrefsCallbacks(); + initDisplayKayakPrefsCallbacks(); initScreenSleepEnabledPrefsCallbacks(); initShowOnLockScreenPrefsCallbacks(); } @@ -301,6 +302,21 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La }); } + private void initDisplayKayakPrefsCallbacks() + { + final TwoStatePreference pref = getPreference(getString(R.string.pref_display_kayak)); + + pref.setChecked(Config.isKayakDisplayEnabled()); + pref.setOnPreferenceChangeListener((preference, newValue) -> { + final boolean oldVal = Config.isKayakDisplayEnabled(); + final boolean newVal = (Boolean) newValue; + if (oldVal != newVal) + Config.setKayakDisplay(newVal); + + return true; + }); + } + private void init3dModePrefsCallbacks() { final TwoStatePreference pref = getPreference(getString(R.string.pref_3d_buildings)); diff --git a/android/app/src/main/java/app/organicmaps/util/Config.java b/android/app/src/main/java/app/organicmaps/util/Config.java index 132b3c6051..18760a93e1 100644 --- a/android/app/src/main/java/app/organicmaps/util/Config.java +++ b/android/app/src/main/java/app/organicmaps/util/Config.java @@ -21,6 +21,7 @@ public final class Config private static final String KEY_PREF_USE_GS = "UseGoogleServices"; private static final String KEY_MISC_DISCLAIMER_ACCEPTED = "IsDisclaimerApproved"; + private static final String KEY_PREF_KAYAK_DISPLAY = "DisplayKayak"; private static final String KEY_MISC_KAYAK_ACCEPTED = "IsKayakApproved"; private static final String KEY_MISC_LOCATION_REQUESTED = "LocationRequested"; private static final String KEY_MISC_UI_THEME = "UiTheme"; @@ -219,6 +220,18 @@ public final class Config setBool(KEY_MISC_DISCLAIMER_ACCEPTED); } + public static boolean isKayakDisplayEnabled() + { + // Kayak is disabled by default in F-Droid build, + // unless a user has already accepted its disclaimer before. + return getBool(KEY_PREF_KAYAK_DISPLAY, !isFdroid() || isKayakDisclaimerAccepted()); + } + + public static void setKayakDisplay(boolean enabled) + { + setBool(KEY_PREF_KAYAK_DISPLAY, enabled); + } + public static boolean isKayakDisclaimerAccepted() { return getBool(KEY_MISC_KAYAK_ACCEPTED); diff --git a/android/app/src/main/java/app/organicmaps/widget/placepage/sections/PlacePageLinksFragment.java b/android/app/src/main/java/app/organicmaps/widget/placepage/sections/PlacePageLinksFragment.java index e27f3d2f7a..b6754928f8 100644 --- a/android/app/src/main/java/app/organicmaps/widget/placepage/sections/PlacePageLinksFragment.java +++ b/android/app/src/main/java/app/organicmaps/widget/placepage/sections/PlacePageLinksFragment.java @@ -18,6 +18,7 @@ import app.organicmaps.MwmActivity; import app.organicmaps.R; import app.organicmaps.bookmarks.data.MapObject; import app.organicmaps.bookmarks.data.Metadata; +import app.organicmaps.util.Config; import app.organicmaps.util.UiUtils; import app.organicmaps.util.Utils; import app.organicmaps.widget.placepage.PlacePageUtils; @@ -201,8 +202,6 @@ public class PlacePageLinksFragment extends Fragment implements Observerpref_privacy pref_search_history + DisplayKayak NEVER ALWAYS AUTO + com.google.android.material.bottomsheet.BottomSheetBehavior CAR_NOTIFICATION_CHANNEL diff --git a/android/app/src/main/res/xml/prefs_main.xml b/android/app/src/main/res/xml/prefs_main.xml index a3d27cc074..e162e025d6 100644 --- a/android/app/src/main/res/xml/prefs_main.xml +++ b/android/app/src/main/res/xml/prefs_main.xml @@ -163,6 +163,13 @@ app:singleLineTitle="false" android:defaultValue="true" android:order="2"/> +