[fenix] For https://github.com/mozilla-mobile/fenix/issues/19886 - Add navigation from quick settings to tracking protection panel
parent
70d55f4746
commit
23d57b151f
@ -0,0 +1,67 @@
|
||||
/* 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.quicksettings
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.component_tracking_protection_panel.trackingProtectionSwitch
|
||||
import kotlinx.android.synthetic.main.quicksettings_tracking_protection.*
|
||||
import kotlinx.android.synthetic.main.switch_with_description.view.*
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.trackingprotection.TrackingProtectionState
|
||||
|
||||
/**
|
||||
* Contract declaring all possible user interactions with [TrackingProtectionView]
|
||||
*/
|
||||
interface TrackingProtectionInteractor {
|
||||
|
||||
/**
|
||||
* Called whenever the tracking protection toggle for this site is toggled
|
||||
*
|
||||
* @param isEnabled new status of session tracking protection
|
||||
*/
|
||||
fun onTrackingProtectionToggled(isEnabled: Boolean)
|
||||
|
||||
/**
|
||||
* Navigates to the tracking protection preferences. Called when a user clicks on the
|
||||
* "Blocked items" button.
|
||||
*/
|
||||
fun onBlockedItemsClicked()
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @param containerView [ViewGroup] in which this View will inflate itself.
|
||||
* @param interactor [TrackingProtectionInteractor] which will have delegated to all user interactions.
|
||||
*/
|
||||
class TrackingProtectionView(
|
||||
override val containerView: ViewGroup,
|
||||
val interactor: TrackingProtectionInteractor
|
||||
) : LayoutContainer {
|
||||
|
||||
private val context = containerView.context
|
||||
val view: View = LayoutInflater.from(context)
|
||||
.inflate(R.layout.quicksettings_tracking_protection, containerView, true)
|
||||
|
||||
fun update(state: TrackingProtectionState) {
|
||||
bindTrackingProtectionInfo(state.isTrackingProtectionEnabled)
|
||||
|
||||
trackingProtectionBlockedItems.setOnClickListener {
|
||||
interactor.onBlockedItemsClicked()
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindTrackingProtectionInfo(isTrackingProtectionEnabled: Boolean) {
|
||||
trackingProtectionSwitch.switch_widget.isChecked = isTrackingProtectionEnabled
|
||||
trackingProtectionSwitch.switch_widget.jumpDrawablesToCurrentState()
|
||||
|
||||
trackingProtectionSwitch.switch_widget.setOnCheckedChangeListener { _, isChecked ->
|
||||
interactor.onTrackingProtectionToggled(isChecked)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?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/. -->
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<org.mozilla.fenix.trackingprotection.SwitchWithDescription
|
||||
android:id="@+id/trackingProtectionSwitch"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="@dimen/tracking_protection_item_height"
|
||||
android:text="@string/preference_enhanced_tracking_protection"
|
||||
app:layout_constraintBottom_toTopOf="@id/trackingProtectionBlockedItems"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:switchDescription="@string/etp_panel_on"
|
||||
app:switchIcon="@drawable/ic_tracking_protection"
|
||||
app:switchTitle="@string/preference_enhanced_tracking_protection" />
|
||||
|
||||
<!-- TODO: Match drawablePadding with Design Spec. Using @style/QuickSettingsText.Icon as a placeholder -->
|
||||
<!-- TODO: Match layout_height with Design Spec. Using @dimen/quicksettings_item_height as a placeholder -->
|
||||
<TextView
|
||||
android:id="@+id/trackingProtectionBlockedItems"
|
||||
style="@style/QuickSettingsText.Icon"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="@dimen/quicksettings_item_height"
|
||||
android:gravity="end|center_vertical"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:text="@string/preference_enhanced_tracking_protection_blocked_items"
|
||||
app:drawableEndCompat="@drawable/ic_arrowhead_right"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue