1
0
Fork 0

Closes #1411: Added disabled style for permissions site info panel. (#2354)

master
Arturo Mejia 2019-05-10 21:23:18 -04:00 committed by Colin Lee
parent cfccb997fd
commit 744f1be0a9
10 changed files with 133 additions and 39 deletions

View File

@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- #2308 - Update the deprecated BitmapDrawable constructor - #2308 - Update the deprecated BitmapDrawable constructor
- #1311 - Enable downloads in custom tabs. - #1311 - Enable downloads in custom tabs.
- #1874 - Added TOP info panel dialog for custom tabs. - #1874 - Added TOP info panel dialog for custom tabs.
- #1411 - Added disabled style for disabled permissions items in site info panel.
- #1735 - Adds API to see the release channel - #1735 - Adds API to see the release channel
### Changed ### Changed

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix.settings.quicksettings package org.mozilla.fenix.settings.quicksettings
import android.graphics.drawable.Drawable
import android.view.View import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
@ -17,6 +18,7 @@ import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED
import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION
import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes import mozilla.components.support.ktx.android.net.hostWithoutCommonPrefixes
import mozilla.components.support.ktx.kotlin.toUri import mozilla.components.support.ktx.kotlin.toUri
@ -76,17 +78,13 @@ class QuickSettingsUIView(
bindSecurityInfo(state.mode.isSecured) bindSecurityInfo(state.mode.isSecured)
bindReportProblemAction(state.mode.url) bindReportProblemAction(state.mode.url)
bindTrackingProtectionInfo(state.mode.isTrackingProtectionOn) bindTrackingProtectionInfo(state.mode.isTrackingProtectionOn)
bindPhoneFeatureItem(cameraActionLabel, CAMERA, state.mode.sitePermissions) bindPhoneFeatureItem(CAMERA, state.mode.sitePermissions)
bindPhoneFeatureItem(microphoneActionLabel, MICROPHONE, state.mode.sitePermissions) bindPhoneFeatureItem(MICROPHONE, state.mode.sitePermissions)
bindPhoneFeatureItem(notificationActionLabel, NOTIFICATION, state.mode.sitePermissions) bindPhoneFeatureItem(NOTIFICATION, state.mode.sitePermissions)
bindPhoneFeatureItem(locationActionLabel, LOCATION, state.mode.sitePermissions) bindPhoneFeatureItem(LOCATION, state.mode.sitePermissions)
} }
is QuickSettingsState.Mode.ActionLabelUpdated -> { is QuickSettingsState.Mode.ActionLabelUpdated -> {
bindPhoneFeatureItem( bindPhoneFeatureItem(state.mode.phoneFeature, state.mode.sitePermissions)
state.mode.phoneFeature.labelAndAction.second,
state.mode.phoneFeature,
state.mode.sitePermissions
)
} }
is QuickSettingsState.Mode.CheckPendingFeatureBlockedByAndroid -> { is QuickSettingsState.Mode.CheckPendingFeatureBlockedByAndroid -> {
checkFeaturesBlockedByAndroid(state.mode.sitePermissions) checkFeaturesBlockedByAndroid(state.mode.sitePermissions)
@ -144,20 +142,16 @@ class QuickSettingsUIView(
securityInfoLabel.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) securityInfoLabel.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
} }
private fun bindPhoneFeatureItem( private fun bindPhoneFeatureItem(phoneFeature: PhoneFeature, sitePermissions: SitePermissions? = null) {
actionLabel: TextView,
phoneFeature: PhoneFeature,
sitePermissions: SitePermissions? = null
) {
if (phoneFeature.shouldBeHidden(sitePermissions)) { if (phoneFeature.shouldBeHidden(sitePermissions)) {
hide(phoneFeature) hide(phoneFeature)
return return
} }
show(phoneFeature) show(phoneFeature)
if (!phoneFeature.isAndroidPermissionGranted(context)) { if (!phoneFeature.isAndroidPermissionGranted(context)) {
handleBlockedByAndroidAction(actionLabel, phoneFeature) handleBlockedByAndroidAction(phoneFeature)
} else { } else {
bindPhoneAction(actionLabel, phoneFeature, sitePermissions) bindPhoneAction(phoneFeature, sitePermissions)
} }
} }
@ -177,10 +171,16 @@ class QuickSettingsUIView(
return getStatus(sitePermissions, settings) == NO_DECISION return getStatus(sitePermissions, settings) == NO_DECISION
} }
private fun handleBlockedByAndroidAction(actionLabel: TextView, phoneFeature: PhoneFeature) { private fun PhoneFeature.isPermissionBlocked(sitePermissions: SitePermissions?): Boolean {
actionLabel.setText(R.string.phone_feature_blocked_by_android) return getStatus(sitePermissions, settings) == BLOCKED
actionLabel.tag = phoneFeature }
actionLabel.setOnClickListener {
private fun handleBlockedByAndroidAction(phoneFeature: PhoneFeature) {
val (label, action) = phoneFeature.labelAndAction
action.setText(R.string.phone_feature_blocked_by_android)
action.tag = phoneFeature
action.setOnClickListener {
val feature = it.tag as PhoneFeature val feature = it.tag as PhoneFeature
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.SelectBlockedByAndroid( QuickSettingsAction.SelectBlockedByAndroid(
@ -188,27 +188,37 @@ class QuickSettingsUIView(
) )
) )
} }
label.setCompoundDrawablesWithIntrinsicBounds(phoneFeature.disabledIcon, null, null, null)
label.isEnabled = false
blockedByAndroidPhoneFeatures.add(phoneFeature) blockedByAndroidPhoneFeatures.add(phoneFeature)
} }
private fun bindPhoneAction( private fun bindPhoneAction(phoneFeature: PhoneFeature, sitePermissions: SitePermissions? = null) {
actionLabel: TextView, val (label, action) = phoneFeature.labelAndAction
phoneFeature: PhoneFeature,
sitePermissions: SitePermissions? = null action.text = phoneFeature.getActionLabel(
) {
actionLabel.text = phoneFeature.getActionLabel(
context = context, context = context,
sitePermissions = sitePermissions, sitePermissions = sitePermissions,
settings = settings settings = settings
) )
actionLabel.tag = phoneFeature action.tag = phoneFeature
actionLabel.setOnClickListener { action.setOnClickListener {
val feature = it.tag as PhoneFeature val feature = it.tag as PhoneFeature
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.TogglePermission(feature) QuickSettingsAction.TogglePermission(feature)
) )
} }
val icon = if (phoneFeature.isPermissionBlocked(sitePermissions)) {
label.isEnabled = false
phoneFeature.disabledIcon
} else {
label.isEnabled = true
phoneFeature.enabledIcon
}
label.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
blockedByAndroidPhoneFeatures.remove(phoneFeature) blockedByAndroidPhoneFeatures.remove(phoneFeature)
} }
@ -216,8 +226,7 @@ class QuickSettingsUIView(
val clonedList = blockedByAndroidPhoneFeatures.toTypedArray() val clonedList = blockedByAndroidPhoneFeatures.toTypedArray()
clonedList.forEach { phoneFeature -> clonedList.forEach { phoneFeature ->
if (phoneFeature.isAndroidPermissionGranted(context)) { if (phoneFeature.isAndroidPermissionGranted(context)) {
val actionLabel = phoneFeature.labelAndAction.second bindPhoneAction(phoneFeature, sitePermissions)
bindPhoneAction(actionLabel, phoneFeature, sitePermissions)
} }
} }
} }
@ -231,4 +240,26 @@ class QuickSettingsUIView(
NOTIFICATION -> notificationLabel to notificationActionLabel NOTIFICATION -> notificationLabel to notificationActionLabel
} }
} }
private val PhoneFeature.enabledIcon
get(): Drawable {
val drawableId = when (this) {
CAMERA -> R.drawable.ic_camera
LOCATION -> R.drawable.ic_location
MICROPHONE -> R.drawable.ic_microphone
NOTIFICATION -> R.drawable.ic_notification
}
return requireNotNull(AppCompatResources.getDrawable(context, drawableId))
}
private val PhoneFeature.disabledIcon
get(): Drawable {
val drawableId = when (this) {
CAMERA -> R.drawable.ic_camera_disabled
LOCATION -> R.drawable.ic_location_disabled
MICROPHONE -> R.drawable.ic_microphone_disabled
NOTIFICATION -> R.drawable.ic_notifications_disabled
}
return requireNotNull(AppCompatResources.getDrawable(context, drawableId))
}
} }

View File

@ -0,0 +1,8 @@
<?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/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/disabled_text" />
<item android:color="?primaryText"/>
</selector>

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:fillColor="@color/disabled_text"
android:pathData="M21.46,6.16L8.63,19h5.55A1.88,1.88 0,0 0,16 17.06v-2.73l4.4,3.41A1,1 0,0 0,22 17L22,7a1,1 0,0 0,-0.54 -0.84zM21.71,2.29a1,1 0,0 0,-1.42 0L16,6.62A1.84,1.84 0,0 0,14.18 5L3.81,5A1.88,1.88 0,0 0,2 6.94v10.12A1.89,1.89 0,0 0,3.61 19l-1.32,1.29a1,1 0,0 0,0 1.42,1 1,0 0,0 1.42,0l18,-18a1,1 0,0 0,0 -1.42z"/>
</vector>

View File

@ -3,11 +3,11 @@
- 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/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="24.0" android:viewportWidth="24"
android:viewportHeight="24.0"> android:viewportHeight="24">
<path <path
android:fillColor="?primaryText" android:fillColor="?primaryText"
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"/> android:pathData="M12,9a3,3 0,1 0,3 3,3 3,0 0,0 -3,-3zM21,11h-1.07A8,8 0,0 0,13 4.07L13,3a1,1 0,0 0,-2 0v1.07A8,8 0,0 0,4.07 11L3,11a1,1 0,0 0,0 2h1.07A8,8 0,0 0,11 19.93L11,21a1,1 0,0 0,2 0v-1.07A8,8 0,0 0,19.93 13L21,13a1,1 0,0 0,0 -2zM12,18a6,6 0,1 1,6 -6,6 6,0 0,1 -6,6z"/>
</vector> </vector>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -130,6 +130,7 @@
<color name="light_grey_05">#FBFBFE</color> <color name="light_grey_05">#FBFBFE</color>
<color name="dark_grey_90">#15141A</color> <color name="dark_grey_90">#15141A</color>
<color name="neutral_text">@color/white_color</color> <color name="neutral_text">@color/white_color</color>
<color name="disabled_text">#cccccc</color>
<!-- Reader View colors --> <!-- Reader View colors -->
<color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color> <color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color>

View File

@ -207,7 +207,7 @@
</style> </style>
<style name="QuickSettingsText"> <style name="QuickSettingsText">
<item name="android:textColor">?primaryText</item> <item name="android:textColor">@color/state_list_text_color</item>
<item name="android:textSize">14sp</item> <item name="android:textSize">14sp</item>
<item name="android:paddingStart">16dp</item> <item name="android:paddingStart">16dp</item>
<item name="android:gravity">center_vertical</item> <item name="android:gravity">center_vertical</item>
@ -223,6 +223,6 @@
<item name="android:paddingEnd">24dp</item> <item name="android:paddingEnd">24dp</item>
<item name="android:gravity">end|center_vertical</item> <item name="android:gravity">end|center_vertical</item>
<item name="android:background">?android:attr/selectableItemBackground</item> <item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:textColor">@color/photonBlue50</item> <item name="android:textColor">?accentBright</item>
</style> </style>
</resources> </resources>