diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a49269ee..3d6cfd750c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,4 +45,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - #1429 - Updated site permissions ui for MVP - #1599 - Fixed a crash creating a bookmark for a custom tab +- #1414 - Fixed site permissions settings getting reset in Android 6. ### Removed diff --git a/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt b/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt index 60d61beb6b..cf9fe3b2ae 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/Extensions.kt @@ -6,10 +6,13 @@ package org.mozilla.fenix.settings import android.content.Context import android.view.View +import android.widget.RadioButton import android.widget.TextView +import androidx.core.content.ContextCompat import androidx.core.text.HtmlCompat import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissionsRules +import org.mozilla.fenix.DefaultThemeManager import org.mozilla.fenix.R internal fun SitePermissionsRules.Action.toString(context: Context): String { @@ -95,6 +98,19 @@ fun PhoneFeature.getPreferenceKey(context: Context): String { } } +/* In devices with Android 6, when we use android:button="@null" android:drawableStart doesn't work via xml +* as a result we have to apply it programmatically. More info about this issue https://github.com/mozilla-mobile/fenix/issues/1414 +*/ +fun RadioButton.setStartCheckedIndicator() { + val attr = + DefaultThemeManager.resolveAttribute(android.R.attr.listChoiceIndicatorSingle, context) + val buttonDrawable = ContextCompat.getDrawable(context, attr) + buttonDrawable.apply { + this?.setBounds(0, 0, this.intrinsicWidth, this.intrinsicHeight) + } + this.setCompoundDrawables(buttonDrawable, null, null, null) +} + fun initBlockedByAndroidView(phoneFeature: PhoneFeature, blockedByAndroidView: View) { val context = blockedByAndroidView.context if (!phoneFeature.isAndroidPermissionGranted(context)) { diff --git a/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManageExceptionsPhoneFeatureFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManageExceptionsPhoneFeatureFragment.kt index f49561c1d5..eef204e69a 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManageExceptionsPhoneFeatureFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManageExceptionsPhoneFeatureFragment.kt @@ -99,6 +99,7 @@ class SitePermissionsManageExceptionsPhoneFeatureFragment : Fragment(), Coroutin private fun RadioButton.restoreState(status: SitePermissions.Status) { if (phoneFeature.getStatus(sitePermissions) == status) { this.isChecked = true + this.setStartCheckedIndicator() } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManagePhoneFeatureFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManagePhoneFeatureFragment.kt index 49aae024ee..2f0bb7c370 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManagePhoneFeatureFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SitePermissionsManagePhoneFeatureFragment.kt @@ -94,6 +94,7 @@ class SitePermissionsManagePhoneFeatureFragment : Fragment() { private fun RadioButton.restoreState(action: SitePermissionsRules.Action) { if (phoneFeature.action == action) { this.isChecked = true + this.setStartCheckedIndicator() } }