1
0
Fork 0

For #2422 If TP disabled globally disable quicksettings TP exception toggle

master
ekager 2019-05-13 11:42:55 -07:00 committed by Emily Kager
parent 573e215577
commit a078f9e48b
6 changed files with 158 additions and 133 deletions

View File

@ -100,6 +100,7 @@ data class QuickSettingsState(val mode: Mode) : ViewState {
sealed class QuickSettingsAction : Action { sealed class QuickSettingsAction : Action {
data class SelectReportProblem(val url: String) : QuickSettingsAction() data class SelectReportProblem(val url: String) : QuickSettingsAction()
object SelectTrackingProtectionSettings : QuickSettingsAction()
data class ToggleTrackingProtection(val trackingProtection: Boolean) : QuickSettingsAction() data class ToggleTrackingProtection(val trackingProtection: Boolean) : QuickSettingsAction()
data class SelectBlockedByAndroid(val permissions: Array<String>) : QuickSettingsAction() data class SelectBlockedByAndroid(val permissions: Array<String>) : QuickSettingsAction()
data class TogglePermission(val featurePhone: PhoneFeature) : QuickSettingsAction() data class TogglePermission(val featurePhone: PhoneFeature) : QuickSettingsAction()

View File

@ -36,6 +36,7 @@ import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getAutoDisposeObservable import org.mozilla.fenix.mvi.getAutoDisposeObservable
import org.mozilla.fenix.mvi.getManagedEmitter import org.mozilla.fenix.mvi.getManagedEmitter
import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.PhoneFeature
import org.mozilla.fenix.utils.ItsNotBrokenSnack
import java.net.MalformedURLException import java.net.MalformedURLException
import java.net.URL import java.net.URL
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -168,6 +169,12 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
is QuickSettingsAction.SelectBlockedByAndroid -> { is QuickSettingsAction.SelectBlockedByAndroid -> {
requestPermissions(it.permissions, REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS) requestPermissions(it.permissions, REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS)
} }
is QuickSettingsAction.SelectTrackingProtectionSettings -> {
context?.let {
ItsNotBrokenSnack(it).showSnackbar("2422")
}
dismiss()
}
is QuickSettingsAction.SelectReportProblem -> { is QuickSettingsAction.SelectReportProblem -> {
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
val reportUrl = val reportUrl =

View File

@ -43,7 +43,7 @@ class QuickSettingsUIView(
private val securityInfoLabel: TextView private val securityInfoLabel: TextView
private val urlLabel: TextView private val urlLabel: TextView
private val trackingProtectionSwitch: Switch private val trackingProtectionSwitch: Switch
private val reportProblemAction: TextView private val trackingProtectionAction: TextView
private val cameraActionLabel: TextView private val cameraActionLabel: TextView
private val cameraLabel: TextView private val cameraLabel: TextView
private val microphoneActionLabel: TextView private val microphoneActionLabel: TextView
@ -60,7 +60,7 @@ class QuickSettingsUIView(
urlLabel = view.findViewById<AppCompatTextView>(R.id.url) urlLabel = view.findViewById<AppCompatTextView>(R.id.url)
securityInfoLabel = view.findViewById<AppCompatTextView>(R.id.security_info) securityInfoLabel = view.findViewById<AppCompatTextView>(R.id.security_info)
trackingProtectionSwitch = view.findViewById(R.id.tracking_protection) trackingProtectionSwitch = view.findViewById(R.id.tracking_protection)
reportProblemAction = view.findViewById(R.id.report_problem) trackingProtectionAction = view.findViewById(R.id.tracking_protection_action)
cameraActionLabel = view.findViewById<AppCompatTextView>(R.id.camera_action_label) cameraActionLabel = view.findViewById<AppCompatTextView>(R.id.camera_action_label)
cameraLabel = view.findViewById<AppCompatTextView>(R.id.camera_icon) cameraLabel = view.findViewById<AppCompatTextView>(R.id.camera_icon)
microphoneActionLabel = view.findViewById<AppCompatTextView>(R.id.microphone_action_label) microphoneActionLabel = view.findViewById<AppCompatTextView>(R.id.microphone_action_label)
@ -76,7 +76,7 @@ class QuickSettingsUIView(
is QuickSettingsState.Mode.Normal -> { is QuickSettingsState.Mode.Normal -> {
bindUrl(state.mode.url) bindUrl(state.mode.url)
bindSecurityInfo(state.mode.isSecured) bindSecurityInfo(state.mode.isSecured)
bindReportProblemAction(state.mode.url) bindTrackingProtectionAction(state.mode.url)
bindTrackingProtectionInfo(state.mode.isTrackingProtectionOn) bindTrackingProtectionInfo(state.mode.isTrackingProtectionOn)
bindPhoneFeatureItem(CAMERA, state.mode.sitePermissions) bindPhoneFeatureItem(CAMERA, state.mode.sitePermissions)
bindPhoneFeatureItem(MICROPHONE, state.mode.sitePermissions) bindPhoneFeatureItem(MICROPHONE, state.mode.sitePermissions)
@ -97,12 +97,14 @@ class QuickSettingsUIView(
} }
private fun bindTrackingProtectionInfo(isTrackingProtectionOn: Boolean) { private fun bindTrackingProtectionInfo(isTrackingProtectionOn: Boolean) {
val globalTPSetting = Settings.getInstance(context).shouldUseTrackingProtection
val drawableId = val drawableId =
if (isTrackingProtectionOn) R.drawable.ic_tracking_protection else if (isTrackingProtectionOn) R.drawable.ic_tracking_protection else
R.drawable.ic_tracking_protection_disabled R.drawable.ic_tracking_protection_disabled
val icon = AppCompatResources.getDrawable(context, drawableId) val icon = AppCompatResources.getDrawable(context, drawableId)
trackingProtectionSwitch.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) trackingProtectionSwitch.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
trackingProtectionSwitch.isChecked = isTrackingProtectionOn trackingProtectionSwitch.isChecked = isTrackingProtectionOn
trackingProtectionSwitch.isEnabled = globalTPSetting
trackingProtectionSwitch.setOnCheckedChangeListener { _, isChecked -> trackingProtectionSwitch.setOnCheckedChangeListener { _, isChecked ->
actionEmitter.onNext( actionEmitter.onNext(
@ -113,11 +115,22 @@ class QuickSettingsUIView(
} }
} }
private fun bindReportProblemAction(url: String) { private fun bindTrackingProtectionAction(url: String) {
reportProblemAction.setOnClickListener { val globalTPSetting = Settings.getInstance(context).shouldUseTrackingProtection
trackingProtectionAction.text =
if (globalTPSetting)
context.getString(R.string.browser_menu_report_issue) else
context.getString(R.string.preferences_tracking_protection_turned_off_globally)
trackingProtectionAction.setOnClickListener {
if (globalTPSetting) {
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.SelectReportProblem(url) QuickSettingsAction.SelectReportProblem(url)
) )
} else {
actionEmitter.onNext(
QuickSettingsAction.SelectTrackingProtectionSettings
)
}
} }
} }

View File

@ -3,8 +3,7 @@
- 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/. -->
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -25,7 +24,7 @@
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="https://wikipedia.org"/> tools:text="https://wikipedia.org" />
<TextView <TextView
android:id="@+id/security_info" android:id="@+id/security_info"
@ -36,7 +35,7 @@
app:layout_constraintTop_toBottomOf="@id/url" app:layout_constraintTop_toBottomOf="@id/url"
tools:drawableStartCompat="@drawable/mozac_ic_lock" tools:drawableStartCompat="@drawable/mozac_ic_lock"
tools:drawableTint="@color/photonGreen50" tools:drawableTint="@color/photonGreen50"
tools:text="Secure connection"/> tools:text="Secure connection" />
<View <View
android:id="@+id/line_divider_security" android:id="@+id/line_divider_security"
@ -46,7 +45,7 @@
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="?neutralFaded" android:background="?neutralFaded"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/security_info"/> app:layout_constraintTop_toBottomOf="@id/security_info" />
<Switch <Switch
android:id="@+id/tracking_protection" android:id="@+id/tracking_protection"
@ -56,11 +55,11 @@
android:drawableStart="@drawable/ic_tracking_protection" android:drawableStart="@drawable/ic_tracking_protection"
android:paddingEnd="24dp" android:paddingEnd="24dp"
android:text="@string/preferences_tracking_protection" android:text="@string/preferences_tracking_protection"
app:layout_constraintBottom_toTopOf="@id/report_problem" app:layout_constraintBottom_toTopOf="@id/tracking_protection_action"
app:layout_constraintTop_toBottomOf="@id/line_divider_security"/> app:layout_constraintTop_toBottomOf="@id/line_divider_security" />
<TextView <TextView
android:id="@+id/report_problem" android:id="@+id/tracking_protection_action"
style="@style/QuickSettingsText.Icon" style="@style/QuickSettingsText.Icon"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
@ -70,7 +69,7 @@
android:textColor="?accentBright" android:textColor="?accentBright"
android:textSize="12sp" android:textSize="12sp"
app:layout_constraintBottom_toTopOf="@id/line_divider" app:layout_constraintBottom_toTopOf="@id/line_divider"
app:layout_constraintTop_toBottomOf="@id/tracking_protection"/> app:layout_constraintTop_toBottomOf="@id/tracking_protection" />
<View <View
android:id="@+id/line_divider" android:id="@+id/line_divider"
@ -80,7 +79,7 @@
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:background="?neutralFaded" android:background="?neutralFaded"
app:layout_constraintBottom_toTopOf="@id/camera_icon" app:layout_constraintBottom_toTopOf="@id/camera_icon"
app:layout_constraintStart_toStartOf="parent"/> app:layout_constraintStart_toStartOf="parent" />
<TextView <TextView
android:id="@+id/camera_icon" android:id="@+id/camera_icon"
@ -90,7 +89,7 @@
android:text="@string/preference_phone_feature_camera" android:text="@string/preference_phone_feature_camera"
app:drawableStartCompat="@drawable/ic_camera" app:drawableStartCompat="@drawable/ic_camera"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/line_divider"/> app:layout_constraintTop_toBottomOf="@id/line_divider" />
<TextView <TextView
android:id="@+id/camera_action_label" android:id="@+id/camera_action_label"
@ -99,7 +98,7 @@
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/line_divider" app:layout_constraintTop_toBottomOf="@id/line_divider"
tools:text="Allowed"/> tools:text="Allowed" />
<TextView <TextView
android:id="@+id/microphone_icon" android:id="@+id/microphone_icon"
@ -109,7 +108,7 @@
android:text="@string/preference_phone_feature_microphone" android:text="@string/preference_phone_feature_microphone"
app:drawableStartCompat="@drawable/ic_microphone" app:drawableStartCompat="@drawable/ic_microphone"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/camera_icon"/> app:layout_constraintTop_toBottomOf="@id/camera_icon" />
<TextView <TextView
@ -119,7 +118,7 @@
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/camera_action_label" app:layout_constraintTop_toBottomOf="@id/camera_action_label"
tools:text="Blocked by Android"/> tools:text="Blocked by Android" />
<TextView <TextView
android:id="@+id/notification_icon" android:id="@+id/notification_icon"
@ -129,7 +128,7 @@
android:text="@string/preference_phone_feature_notification" android:text="@string/preference_phone_feature_notification"
app:drawableStartCompat="@drawable/ic_notification" app:drawableStartCompat="@drawable/ic_notification"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/microphone_icon"/> app:layout_constraintTop_toBottomOf="@id/microphone_icon" />
<TextView <TextView
android:id="@+id/notification_action_label" android:id="@+id/notification_action_label"
@ -138,7 +137,7 @@
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/microphone_action_label" app:layout_constraintTop_toBottomOf="@id/microphone_action_label"
tools:text="Blocked"/> tools:text="Blocked" />
<TextView <TextView
android:id="@+id/location_icon" android:id="@+id/location_icon"
@ -148,7 +147,7 @@
android:text="@string/preference_phone_feature_location" android:text="@string/preference_phone_feature_location"
app:drawableStartCompat="@drawable/ic_location" app:drawableStartCompat="@drawable/ic_location"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/notification_icon"/> app:layout_constraintTop_toBottomOf="@id/notification_icon" />
<TextView <TextView
android:id="@+id/location_action_label" android:id="@+id/location_action_label"
@ -157,7 +156,7 @@
android:layout_height="@dimen/quicksettings_item_height" android:layout_height="@dimen/quicksettings_item_height"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/notification_action_label" app:layout_constraintTop_toBottomOf="@id/notification_action_label"
tools:text="Blocked"/> tools:text="Blocked" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>

View File

@ -338,5 +338,8 @@
android:name="gravity" android:name="gravity"
app:argType="integer" app:argType="integer"
android:defaultValue="80" /> android:defaultValue="80" />
<action
android:id="@+id/action_quickSettingsSheetDialogFragment_to_trackingProtectionFragment"
app:destination="@id/trackingProtectionFragment" />
</dialog> </dialog>
</navigation> </navigation>

View File

@ -171,6 +171,8 @@
<string name="preferences_tracking_protection_exceptions_description">Tracking Protection is off for these websites</string> <string name="preferences_tracking_protection_exceptions_description">Tracking Protection is off for these websites</string>
<!-- Button in Exceptions Preference to turn on tracking protection for all sites (remove all exceptions) --> <!-- Button in Exceptions Preference to turn on tracking protection for all sites (remove all exceptions) -->
<string name="preferences_tracking_protection_exceptions_turn_on_for_all">Turn on for all sites</string> <string name="preferences_tracking_protection_exceptions_turn_on_for_all">Turn on for all sites</string>
<!-- Description in Quick Settings that tells user tracking protection is off globally for all sites, and links to Settings to turn it on -->
<string name="preferences_tracking_protection_turned_off_globally">Turned off globally, go to Settings to turn it on.</string>
<!-- Preference switch for Telemetry --> <!-- Preference switch for Telemetry -->
<string name="preferences_telemetry">Telemetry</string> <string name="preferences_telemetry">Telemetry</string>