[fenix] Closes https://github.com/mozilla-mobile/fenix/issues/1074: Added recommended settings UI under site permissions.
parent
38c0bcba38
commit
a09330e06e
@ -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
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
@ -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:fillColor="?attr/iconColor"
|
||||
android:pathData="M12,2C6.477,2 2,6.477 2,12s4.477,10 10,10 10,-4.477 10,-10c-0.006,-5.52 -4.48,-9.994 -10,-10zM19.931,11h-3.95c-0.026,-2.22 -0.437,-4.42 -1.217,-6.5 2.798,1.036 4.79,3.54 5.167,6.5zM12,20c-0.48,0 -1.808,-2.4 -1.981,-7h3.962c-0.173,4.6 -1.501,7 -1.981,7zM10.019,11c0.173,-4.6 1.5,-7 1.981,-7 0.481,0 1.808,2.4 1.981,7h-3.962zM9.236,4.5c-0.78,2.08 -1.191,4.28 -1.217,6.5h-3.95c0.378,-2.96 2.369,-5.464 5.167,-6.5zM4.069,13h3.95c0.026,2.22 0.437,4.42 1.217,6.5 -2.798,-1.036 -4.79,-3.54 -5.167,-6.5zM14.769,19.5c0.778,-2.08 1.188,-4.28 1.212,-6.5h3.95c-0.378,2.96 -2.369,5.464 -5.167,6.5h0.005z"/>
|
||||
</vector>
|
@ -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>
|
Loading…
Reference in New Issue