Skip to content

Commit

Permalink
Bug 1811537 - Add secret setting allowing to overwrite the country
Browse files Browse the repository at this point in the history
…and `city` parameters for Pocket sponsored stories
Alexandru2909 authored and mergify[bot] committed Feb 8, 2023
1 parent 9c51764 commit 9f2a959
Showing 6 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
@@ -413,7 +413,11 @@ class Core(
appId = BuildConfig.POCKET_CONSUMER_KEY,
),
sponsoredStoriesParams = if (context.settings().useCustomConfigurationForSponsoredStories) {
PocketStoriesRequestConfig(context.settings().pocketSponsoredStoriesSiteId)
PocketStoriesRequestConfig(
context.settings().pocketSponsoredStoriesSiteId,
context.settings().pocketSponsoredStoriesCountry,
context.settings().pocketSponsoredStoriesCity,
)
} else {
PocketStoriesRequestConfig()
},
Original file line number Diff line number Diff line change
@@ -34,5 +34,21 @@ class SponsoredStoriesSettingsFragment : PreferenceFragmentCompat() {
true
}
}

requirePreference<EditTextPreference>(R.string.pref_key_custom_sponsored_stories_country).apply {
isVisible = Config.channel.isNightlyOrDebug
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
context.settings().pocketSponsoredStoriesCountry = (newValue as String)
true
}
}

requirePreference<EditTextPreference>(R.string.pref_key_custom_sponsored_stories_city).apply {
isVisible = Config.channel.isNightlyOrDebug
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
context.settings().pocketSponsoredStoriesCity = (newValue as String)
true
}
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
@@ -1472,6 +1472,22 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = "",
)

/**
* Country parameter used to set the spoc content.
*/
var pocketSponsoredStoriesCountry by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_custom_sponsored_stories_country),
default = "",
)

/**
* City parameter used to set the spoc content.
*/
var pocketSponsoredStoriesCity by stringPreference(
appContext.getPreferenceKey(R.string.pref_key_custom_sponsored_stories_city),
default = "",
)

/**
* Indicates if the Contile functionality should be visible.
*/
2 changes: 2 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
@@ -320,6 +320,8 @@
<string name="pref_key_custom_sponsored_stories_parameters" translatable="false">pref_key_custom_sponsored_stories_parameters</string>
<string name="pref_key_custom_sponsored_stories_parameters_enabled" translatable="false">pref_key_custom_sponsored_stories_parameters_enabled</string>
<string name="pref_key_custom_sponsored_stories_site_id" translatable="false">pref_key_custom_sponsored_stories_site_id</string>
<string name="pref_key_custom_sponsored_stories_country" translatable="false">pref_key_custom_sponsored_stories_country</string>
<string name="pref_key_custom_sponsored_stories_city" translatable="false">pref_key_custom_sponsored_stories_city</string>

<!-- Growth Data -->
<string name="pref_key_growth_set_as_default" translatable="false">pref_key_growth_set_as_default</string>
4 changes: 4 additions & 0 deletions app/src/main/res/values/static_strings.xml
Original file line number Diff line number Diff line change
@@ -54,6 +54,10 @@
<string name="preferences_debug_settings_custom_sponsored_stories_parameters_enabled" translatable="false">Enable custom Pocket sponsored stories parameters (requires restart)</string>
<!-- Label for custom Pocket sponsored stories site id setting -->
<string name="preferences_debug_settings_custom_sponsored_stories_parameters_site" translatable="false">Site parameter</string>
<!-- Label for custom Pocket sponsored stories country parameter -->
<string name="preferences_debug_settings_custom_sponsored_stories_country" translatable="false">Country parameter</string>
<!-- Label for custom Pocket sponsored stories city parameter -->
<string name="preferences_debug_settings_custom_sponsored_stories_city" translatable="false">City parameter</string>
<!-- Title of preference for sync debugging (only shown in the when the secret debug menu is enabled) -->
<string name="preferences_sync_debug">Sync Debug</string>
<!-- Preference to override the Push server -->
14 changes: 14 additions & 0 deletions app/src/main/res/xml/sponsored_stories_settings.xml
Original file line number Diff line number Diff line change
@@ -15,4 +15,18 @@
android:title="@string/preferences_debug_settings_custom_sponsored_stories_parameters_site"
app:iconSpaceReserved="false"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:dependency="@string/pref_key_custom_sponsored_stories_parameters_enabled"
android:key="@string/pref_key_custom_sponsored_stories_country"
android:title="@string/preferences_debug_settings_custom_sponsored_stories_country"
android:inputType="text"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false" />
<EditTextPreference
android:dependency="@string/pref_key_custom_sponsored_stories_parameters_enabled"
android:key="@string/pref_key_custom_sponsored_stories_city"
android:title="@string/preferences_debug_settings_custom_sponsored_stories_city"
android:inputType="text"
app:useSimpleSummaryProvider="true"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceScreen>

0 comments on commit 9f2a959

Please sign in to comment.