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 {
data class SelectReportProblem(val url: String) : QuickSettingsAction()
object SelectTrackingProtectionSettings : QuickSettingsAction()
data class ToggleTrackingProtection(val trackingProtection: Boolean) : QuickSettingsAction()
data class SelectBlockedByAndroid(val permissions: Array<String>) : 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.getManagedEmitter
import org.mozilla.fenix.settings.PhoneFeature
import org.mozilla.fenix.utils.ItsNotBrokenSnack
import java.net.MalformedURLException
import java.net.URL
import kotlin.coroutines.CoroutineContext
@ -168,6 +169,12 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment(), CoroutineSco
is QuickSettingsAction.SelectBlockedByAndroid -> {
requestPermissions(it.permissions, REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS)
}
is QuickSettingsAction.SelectTrackingProtectionSettings -> {
context?.let {
ItsNotBrokenSnack(it).showSnackbar("2422")
}
dismiss()
}
is QuickSettingsAction.SelectReportProblem -> {
launch(Dispatchers.Main) {
val reportUrl =

View File

@ -43,7 +43,7 @@ class QuickSettingsUIView(
private val securityInfoLabel: TextView
private val urlLabel: TextView
private val trackingProtectionSwitch: Switch
private val reportProblemAction: TextView
private val trackingProtectionAction: TextView
private val cameraActionLabel: TextView
private val cameraLabel: TextView
private val microphoneActionLabel: TextView
@ -60,7 +60,7 @@ class QuickSettingsUIView(
urlLabel = view.findViewById<AppCompatTextView>(R.id.url)
securityInfoLabel = view.findViewById<AppCompatTextView>(R.id.security_info)
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)
cameraLabel = view.findViewById<AppCompatTextView>(R.id.camera_icon)
microphoneActionLabel = view.findViewById<AppCompatTextView>(R.id.microphone_action_label)
@ -76,7 +76,7 @@ class QuickSettingsUIView(
is QuickSettingsState.Mode.Normal -> {
bindUrl(state.mode.url)
bindSecurityInfo(state.mode.isSecured)
bindReportProblemAction(state.mode.url)
bindTrackingProtectionAction(state.mode.url)
bindTrackingProtectionInfo(state.mode.isTrackingProtectionOn)
bindPhoneFeatureItem(CAMERA, state.mode.sitePermissions)
bindPhoneFeatureItem(MICROPHONE, state.mode.sitePermissions)
@ -97,12 +97,14 @@ class QuickSettingsUIView(
}
private fun bindTrackingProtectionInfo(isTrackingProtectionOn: Boolean) {
val globalTPSetting = Settings.getInstance(context).shouldUseTrackingProtection
val drawableId =
if (isTrackingProtectionOn) R.drawable.ic_tracking_protection else
R.drawable.ic_tracking_protection_disabled
val icon = AppCompatResources.getDrawable(context, drawableId)
trackingProtectionSwitch.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
trackingProtectionSwitch.isChecked = isTrackingProtectionOn
trackingProtectionSwitch.isEnabled = globalTPSetting
trackingProtectionSwitch.setOnCheckedChangeListener { _, isChecked ->
actionEmitter.onNext(
@ -113,11 +115,22 @@ class QuickSettingsUIView(
}
}
private fun bindReportProblemAction(url: String) {
reportProblemAction.setOnClickListener {
private fun bindTrackingProtectionAction(url: String) {
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(
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
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -56,11 +55,11 @@
android:drawableStart="@drawable/ic_tracking_protection"
android:paddingEnd="24dp"
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" />
<TextView
android:id="@+id/report_problem"
android:id="@+id/tracking_protection_action"
style="@style/QuickSettingsText.Icon"
android:layout_width="match_parent"
android:layout_height="@dimen/quicksettings_item_height"

View File

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

View File

@ -171,6 +171,8 @@
<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) -->
<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 -->
<string name="preferences_telemetry">Telemetry</string>