Closes #1074: Added recommended settings UI under site permissions.
parent
0f1e65bdab
commit
f4b0864e06
|
@ -0,0 +1,88 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.settings
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.preference.PreferenceViewHolder
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.widget.RadioButton
|
||||||
|
import androidx.preference.Preference
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
|
||||||
|
class RadioButtonPreference : Preference {
|
||||||
|
private val radioGroups = mutableListOf<RadioButtonPreference>()
|
||||||
|
private lateinit var summaryView: TextView
|
||||||
|
private lateinit var radioButton: RadioButton
|
||||||
|
|
||||||
|
init {
|
||||||
|
layoutResource = R.layout.preference_widget_radiobutton
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
|
||||||
|
context,
|
||||||
|
attrs,
|
||||||
|
defStyleAttr
|
||||||
|
)
|
||||||
|
|
||||||
|
fun addToRadioGroup(radioPreference: RadioButtonPreference) {
|
||||||
|
radioGroups.add(radioPreference)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||||
|
super.onBindViewHolder(holder)
|
||||||
|
|
||||||
|
bindRadioButton(holder)
|
||||||
|
|
||||||
|
bindTitle(holder)
|
||||||
|
|
||||||
|
bindSummaryView(holder)
|
||||||
|
|
||||||
|
setOnPreferenceClickListener {
|
||||||
|
updateRadioValue(true)
|
||||||
|
|
||||||
|
toggleRadioGroups()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateRadioValue(isChecked: Boolean) {
|
||||||
|
persistBoolean(isChecked)
|
||||||
|
radioButton.isChecked = isChecked
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindRadioButton(holder: PreferenceViewHolder) {
|
||||||
|
radioButton = holder.findViewById(R.id.radio_button) as RadioButton
|
||||||
|
radioButton.isChecked = getPersistedBoolean(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleRadioGroups() {
|
||||||
|
if (radioButton.isChecked) {
|
||||||
|
radioGroups.forEach { it.updateRadioValue(false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindTitle(holder: PreferenceViewHolder) {
|
||||||
|
val titleView = holder.findViewById(R.id.title) as TextView
|
||||||
|
|
||||||
|
if (!TextUtils.isEmpty(title)) {
|
||||||
|
titleView.text = title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindSummaryView(holder: PreferenceViewHolder) {
|
||||||
|
summaryView = holder.findViewById(R.id.widget_summary) as TextView
|
||||||
|
if (!TextUtils.isEmpty(summary)) {
|
||||||
|
summaryView.text = summary
|
||||||
|
summaryView.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
summaryView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,4 +20,19 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.site_permissions_preferences, rootKey)
|
setPreferencesFromResource(R.xml.site_permissions_preferences, rootKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupPreferences() {
|
||||||
|
val keyRecommendSettings = getString(R.string.pref_key_recommended_settings)
|
||||||
|
val keyCustomSettings = getString(R.string.pref_key_custom_settings)
|
||||||
|
val radioRecommendSettings: RadioButtonPreference = requireNotNull(findPreference(keyRecommendSettings))
|
||||||
|
val radioCustomSettings: RadioButtonPreference = requireNotNull(findPreference(keyCustomSettings))
|
||||||
|
|
||||||
|
radioRecommendSettings.addToRadioGroup(radioCustomSettings)
|
||||||
|
radioCustomSettings.addToRadioGroup(radioRecommendSettings)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
setupPreferences()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:pathData="M11.026,22.133l7.282,-11.994c0.215,-0.354 0.102,-0.815 -0.252,-1.03 -0.117,-0.071 -0.252,-0.109 -0.389,-0.109H13l0.436,-6.987c0.01,-0.138 -0.096,-0.257 -0.233,-0.266 -0.093,-0.005 -0.181,0.04 -0.23,0.12L5.691,13.861c-0.215,0.354 -0.102,0.815 0.252,1.03 0.118,0.071 0.252,0.109 0.39,0.109H11l-0.437,6.987c-0.009,0.138 0.096,0.257 0.234,0.266 0.093,0.005 0.181,-0.04 0.23,-0.12z"
|
||||||
|
android:fillColor="?attr/iconColor"/>
|
||||||
|
</vector>
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,59 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/relativeLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingTop="@dimen/radio_button_preference_vertical"
|
||||||
|
android:paddingStart="@dimen/radio_button_preference_horizontal"
|
||||||
|
android:paddingEnd="@dimen/radio_button_preference_horizontal"
|
||||||
|
android:paddingBottom="@dimen/radio_button_preference_vertical"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
|
||||||
|
<LinearLayout android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/radio_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/radio_button_preference_height"
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:button="@null"
|
||||||
|
android:clickable="false"
|
||||||
|
android:drawableStart="?android:attr/listChoiceIndicatorSingle"
|
||||||
|
android:drawablePadding="@dimen/radio_button_preference_drawable_padding"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:gravity="center|start"
|
||||||
|
android:layout_height="@dimen/radio_button_preference_height"
|
||||||
|
tools:text="Use recommended settings"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceListItem"/>
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/widget_summary"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
|
tools:text="@string/preference_recommended_settings_summary"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -22,4 +22,8 @@
|
||||||
<dimen name="radio_button_drawable_padding">32dp</dimen>
|
<dimen name="radio_button_drawable_padding">32dp</dimen>
|
||||||
<dimen name="radio_button_padding_horizontal">16dp</dimen>
|
<dimen name="radio_button_padding_horizontal">16dp</dimen>
|
||||||
<dimen name="radio_button_padding_vertical">12dp</dimen>
|
<dimen name="radio_button_padding_vertical">12dp</dimen>
|
||||||
|
<dimen name="radio_button_preference_height">48dp</dimen>
|
||||||
|
<dimen name="radio_button_preference_horizontal">16dp</dimen>
|
||||||
|
<dimen name="radio_button_preference_drawable_padding">16dp</dimen>
|
||||||
|
<dimen name="radio_button_preference_vertical">12dp</dimen>
|
||||||
</resources>
|
</resources>
|
|
@ -37,4 +37,10 @@
|
||||||
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
<string name="pref_key_show_search_suggestions" translatable="false">pref_key_show_search_suggestions</string>
|
||||||
|
|
||||||
<string name = "pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
|
<string name = "pref_key_bounce_quick_action" translatable="false">pref_key_bounce_quick_action</string>
|
||||||
|
<!-- Site Permissions Settings -->
|
||||||
|
<string name="pref_key_optimize" translatable="false">pref_key_optimize</string>
|
||||||
|
<string name="pref_key_show_site_exceptions" translatable="false">pref_key_show_site_exceptions</string>
|
||||||
|
<string name="pref_key_recommended_settings" translatable="false">pref_key_recommended_settings</string>
|
||||||
|
<string name="pref_key_custom_settings" translatable="false">pref_key_custom_settings</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -120,6 +120,20 @@
|
||||||
<!-- Preference for account settings -->
|
<!-- Preference for account settings -->
|
||||||
<string name="preferences_account_settings">Account Settings</string>
|
<string name="preferences_account_settings">Account Settings</string>
|
||||||
|
|
||||||
|
<!-- Site Permissions Preferences -->
|
||||||
|
<!-- Preference for reducing image sizes, bandwidth and platform-level optimizations -->
|
||||||
|
<string name="preference_optimize">Optimize</string>
|
||||||
|
<!-- Label summary to explain how the optimize preference works -->
|
||||||
|
<string name="preference_optimize_summary">Lower image quality, throttle streaming bandwidth, and platform-level optimizations</string>
|
||||||
|
<!-- Preference for showing a list of websites that the default configurations won't apply to them -->
|
||||||
|
<string name="preference_exceptions">Exceptions</string>
|
||||||
|
<!-- Preference for applying recommend rules to all sites -->
|
||||||
|
<string name="preference_recommended_settings">Use recommended settings</string>
|
||||||
|
<!-- Label summary to explain how the recommended settings work -->
|
||||||
|
<string name="preference_recommended_settings_summary"><b>Blocked</b>\n Ads, autoplay sound and video (block playing media with sound), cookies (block third-party trackers cookies), trackers (allow some trackers), pop-up, website redirects. \n\n <b>Ask to allow</b> \n Camera, location, microphone and notification. \n\n <b>Allowed</b> \n DRM audio and video, JavaScript, cache and site data, images.</string>
|
||||||
|
<!-- Preference for applying custom rules to all sites -->
|
||||||
|
<string name="preference_custom_settings">Use custom settings</string>
|
||||||
|
|
||||||
<!-- Account Preferences -->
|
<!-- Account Preferences -->
|
||||||
<!-- Preference for triggering sync -->
|
<!-- Preference for triggering sync -->
|
||||||
<string name="preferences_sync_now">Sync now</string>
|
<string name="preferences_sync_now">Sync now</string>
|
||||||
|
|
|
@ -2,6 +2,30 @@
|
||||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<androidx.preference.SwitchPreference
|
||||||
</PreferenceScreen>
|
android:icon="@drawable/ic_energy"
|
||||||
|
android:key="@string/pref_key_optimize"
|
||||||
|
android:title="@string/preference_optimize"
|
||||||
|
android:summary="@string/preference_optimize_summary"
|
||||||
|
android:defaultValue="false"/>
|
||||||
|
|
||||||
|
<androidx.preference.Preference
|
||||||
|
android:icon="@drawable/ic_internet"
|
||||||
|
android:key="@string/pref_key_show_site_exceptions"
|
||||||
|
android:title="@string/preference_exceptions"/>
|
||||||
|
|
||||||
|
<org.mozilla.fenix.settings.RadioButtonPreference
|
||||||
|
android:key="@string/pref_key_recommended_settings"
|
||||||
|
android:title="@string/preference_recommended_settings"
|
||||||
|
android:summary="@string/preference_recommended_settings_summary"
|
||||||
|
android:defaultValue="false"/>
|
||||||
|
|
||||||
|
<org.mozilla.fenix.settings.RadioButtonPreference
|
||||||
|
android:key="@string/pref_key_custom_settings"
|
||||||
|
android:title="@string/preference_custom_settings"
|
||||||
|
android:defaultValue="false"/>
|
||||||
|
|
||||||
|
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue