1
0
Fork 0

Closes #1075: Added custom settings UI under site permissions.

master
Arturo Mejia 2019-03-22 10:23:16 -04:00 committed by Colin Lee
parent 80f386c411
commit a0cfedeeca
9 changed files with 163 additions and 10 deletions

View File

@ -19,6 +19,8 @@ class RadioButtonPreference : Preference {
private lateinit var summaryView: TextView
private lateinit var radioButton: RadioButton
private var clickListener: (() -> Unit)? = null
init {
layoutResource = R.layout.preference_widget_radiobutton
}
@ -35,6 +37,10 @@ class RadioButtonPreference : Preference {
radioGroups.add(radioPreference)
}
fun onClickListener(listener: (() -> Unit)) {
clickListener = listener
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
@ -48,6 +54,7 @@ class RadioButtonPreference : Preference {
updateRadioValue(true)
toggleRadioGroups()
clickListener?.invoke()
true
}
}

View File

@ -6,11 +6,17 @@ package org.mozilla.fenix.settings
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import org.jetbrains.anko.support.v4.defaultSharedPreferences
import org.mozilla.fenix.R
class SitePermissionsFragment : PreferenceFragmentCompat() {
private lateinit var categoryPhoneFeatures: Preference
private lateinit var radioRecommendSettings: RadioButtonPreference
private lateinit var radioCustomSettings: RadioButtonPreference
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activity as AppCompatActivity).title = getString(R.string.preferences_site_permissions)
@ -21,18 +27,57 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
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()
}
private fun setupPreferences() {
bindRadioRecommendedSettings()
bindRadioCustomSettings()
bindCategoryPhoneFeatures()
setupRadioGroups()
}
private fun setupRadioGroups() {
radioRecommendSettings.addToRadioGroup(radioCustomSettings)
radioCustomSettings.addToRadioGroup(radioRecommendSettings)
}
private fun bindRadioCustomSettings() {
val keyCustomSettings = getString(R.string.pref_key_custom_settings)
radioCustomSettings = requireNotNull(findPreference(keyCustomSettings))
radioCustomSettings.onClickListener {
toggleCategoryPhoneFeatureVisibility()
}
}
private fun bindRadioRecommendedSettings() {
val keyRecommendSettings = getString(R.string.pref_key_recommended_settings)
radioRecommendSettings = requireNotNull(findPreference(keyRecommendSettings))
radioRecommendSettings.onClickListener {
toggleCategoryPhoneFeatureVisibility()
}
}
private fun bindCategoryPhoneFeatures() {
val keyCategoryPhoneFeatures = getString(R.string.pref_key_category_phone_feature)
categoryPhoneFeatures = requireNotNull(findPreference(keyCategoryPhoneFeatures))
val isCategoryActivate = defaultSharedPreferences.getBoolean(radioCustomSettings.key, false)
if (isCategoryActivate) {
categoryPhoneFeatures.isVisible = true
}
}
private fun toggleCategoryPhoneFeatureVisibility() {
categoryPhoneFeatures.isVisible = !categoryPhoneFeatures.isVisible
}
}

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.0"
android:viewportHeight="24.0">
<path
android:fillColor="?attr/iconColor"
android:pathData="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
</vector>

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.0"
android:viewportHeight="24.0">
<path
android:fillColor="?attr/iconColor"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>

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="M17,11v-1c0,-0.552 0.448,-1 1,-1s1,0.448 1,1v1c0,3.526 -2.608,6.444 -6,6.93L13,21c0,0.552 -0.448,1 -1,1s-1,-0.448 -1,-1v-3.07c-3.392,-0.486 -6,-3.404 -6,-6.93v-1c0,-0.552 0.448,-1 1,-1s1,0.448 1,1v1c0,2.761 2.239,5 5,5s5,-2.239 5,-5zM12,2c1.657,0 3,1.343 3,3v6c0,1.657 -1.343,3 -3,3s-3,-1.343 -3,-3L9,5c0,-1.657 1.343,-3 3,-3z"
android:fillColor="?attr/iconColor"/>
</vector>

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.0"
android:viewportHeight="24.0">
<path
android:fillColor="?attr/iconColor"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z"/>
</vector>

View File

@ -43,5 +43,10 @@
<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>
<string name="pref_key_phone_feature_camera" translatable="false">pref_key_phone_feature_camera</string>
<string name="pref_key_phone_feature_location" translatable="false">pref_key_phone_feature_location</string>
<string name="pref_key_phone_feature_microphone" translatable="false">pref_key_phone_feature_microphone</string>
<string name="pref_key_phone_feature_notification" translatable="false">pref_key_phone_feature_notification</string>
<string name="pref_key_category_phone_feature" translatable="false">pref_key_category_phone_feature</string>
</resources>

View File

@ -137,6 +137,18 @@
<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>
<!-- Preference category for feature phone permissions likes Camera,Microphone, Location ... etc -->
<string name="preference_category_phone_feature">Phone Feature</string>
<!-- Preference for altering the camera access for all websites -->
<string name="preference_phone_feature_camera">Camera</string>
<!-- Preference for altering the microphone access for all websites -->
<string name="preference_phone_feature_microphone">Microphone</string>
<!-- Preference for altering the location access for all websites -->
<string name="preference_phone_feature_location">Location</string>
<!-- Preference for altering the notification access for all websites -->
<string name="preference_phone_feature_notification">Notification</string>
<!-- Preference option for altering the notification access for all websites -->
<string name="preference_option_phone_feature_ask_to_allow">Ask to allow</string>
<!-- Account Preferences -->
<!-- Preference for triggering sync -->

View File

@ -28,4 +28,36 @@
android:title="@string/preference_custom_settings"
android:defaultValue="false"/>
<androidx.preference.PreferenceCategory
android:key="@string/pref_key_category_phone_feature"
android:title="@string/preference_category_phone_feature"
app:iconSpaceReserved="false"
app:isPreferenceVisible="false">
<androidx.preference.Preference
android:icon="@drawable/ic_camera"
android:key="@string/pref_key_phone_feature_camera"
android:title="@string/preference_phone_feature_camera"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
<androidx.preference.Preference
android:icon="@drawable/ic_location"
android:key="@string/pref_key_phone_feature_location"
android:title="@string/preference_phone_feature_location"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
<androidx.preference.Preference
android:icon="@drawable/ic_microphone"
android:key="@string/pref_key_phone_feature_microphone"
android:title="@string/preference_phone_feature_microphone"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
<androidx.preference.Preference
android:icon="@drawable/ic_notification"
android:key="@string/pref_key_phone_feature_microphone"
android:title="@string/preference_phone_feature_microphone"
android:summary="@string/preference_option_phone_feature_ask_to_allow"/>
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>