1
0
Fork 0

Closes #1074: Added recommended settings UI under site permissions.

master
Arturo Mejia 2019-03-21 14:04:24 -04:00 committed by Colin Lee
parent 0f1e65bdab
commit f4b0864e06
9 changed files with 238 additions and 2 deletions

View File

@ -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
}
}
}

View File

@ -20,4 +20,19 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
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()
}
}

View File

@ -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

View File

@ -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>

View File

@ -22,4 +22,8 @@
<dimen name="radio_button_drawable_padding">32dp</dimen>
<dimen name="radio_button_padding_horizontal">16dp</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>

View File

@ -37,4 +37,10 @@
<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>
<!-- 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>

View File

@ -120,6 +120,20 @@
<!-- Preference for account settings -->
<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 -->
<!-- Preference for triggering sync -->
<string name="preferences_sync_now">Sync now</string>

View File

@ -2,6 +2,30 @@
<!-- 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/. -->
<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">
</PreferenceScreen>
<androidx.preference.SwitchPreference
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>