diff --git a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt index d9f1dd7b58..a71fec6377 100644 --- a/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt +++ b/app/src/main/java/org/mozilla/fenix/home/sessioncontrol/viewholders/onboarding/OnboardingTrackingProtectionViewHolder.kt @@ -5,29 +5,71 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding import android.view.View +import android.widget.Switch import androidx.recyclerview.widget.RecyclerView import kotlinx.android.synthetic.main.onboarding_tracking_protection.view.* +import kotlinx.android.synthetic.main.onboarding_tracking_protection.view.description_text +import kotlinx.android.synthetic.main.onboarding_tracking_protection.view.header_text import org.mozilla.fenix.R import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings +import org.mozilla.fenix.onboarding.OnboardingRadioButton class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHolder(view) { + private var standardTrackingProtection: OnboardingRadioButton + private var strictTrackingProtection: OnboardingRadioButton + private var trackingProtectionToggle: Switch + init { view.header_text.setOnboardingIcon(R.drawable.ic_onboarding_tracking_protection) + trackingProtectionToggle = view.tracking_protection_toggle + standardTrackingProtection = view.tracking_protection_standard_option + strictTrackingProtection = view.tracking_protection_strict_default + val appName = view.context.getString(R.string.app_name) view.description_text.text = view.context.getString( R.string.onboarding_tracking_protection_description1, appName ) - view.tracking_protection_toggle.apply { + trackingProtectionToggle.apply { isChecked = view.context.settings().shouldUseTrackingProtection setOnCheckedChangeListener { _, isChecked -> updateTrackingProtectionSetting(isChecked) + updateRadioGroupState(view, isChecked) } } + + setupRadioGroup(view, trackingProtectionToggle.isChecked) + } + + private fun setupRadioGroup(view: View, isChecked: Boolean) { + + updateRadioGroupState(view, isChecked) + + standardTrackingProtection.addToRadioGroup(strictTrackingProtection) + strictTrackingProtection.addToRadioGroup(standardTrackingProtection) + + standardTrackingProtection.onClickListener { + updateTrackingProtectionPolicy() + } + + strictTrackingProtection.onClickListener { + updateTrackingProtectionPolicy() + } + } + + private fun updateRadioGroupState(view: View, isChecked: Boolean) { + standardTrackingProtection.isEnabled = isChecked + strictTrackingProtection.isEnabled = isChecked + + view.protection_standard_description.isEnabled = isChecked + view.protection_strict_description.isEnabled = isChecked + + view.protection_standard_title.isEnabled = isChecked + view.protection_strict_title.isEnabled = isChecked } private fun updateTrackingProtectionSetting(enabled: Boolean) { @@ -39,6 +81,14 @@ class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHold } } + private fun updateTrackingProtectionPolicy() { + itemView.context?.components?.let { + val policy = it.core.createTrackingProtectionPolicy() + it.useCases.settingsUseCases.updateTrackingProtection.invoke(policy) + it.useCases.sessionUseCases.reload.invoke() + } + } + companion object { const val LAYOUT_ID = R.layout.onboarding_tracking_protection } diff --git a/app/src/main/res/color/primary_state_list_text_color.xml b/app/src/main/res/color/primary_state_list_text_color.xml new file mode 100644 index 0000000000..68658629a1 --- /dev/null +++ b/app/src/main/res/color/primary_state_list_text_color.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/app/src/main/res/layout/onboarding_tracking_protection.xml b/app/src/main/res/layout/onboarding_tracking_protection.xml index 24fa76692a..efdaaba9cc 100644 --- a/app/src/main/res/layout/onboarding_tracking_protection.xml +++ b/app/src/main/res/layout/onboarding_tracking_protection.xml @@ -1,44 +1,116 @@ - - - + + + android:id="@+id/header_text" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:drawablePadding="12dp" + android:gravity="center_vertical" + android:lines="1" + android:text="@string/onboarding_tracking_protection_header" + android:textAppearance="@style/HeaderTextStyle" + app:layout_constraintEnd_toStartOf="@id/tracking_protection_toggle" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:drawableStart="@drawable/ic_onboarding_tracking_protection" /> + + android:id="@+id/tracking_protection_toggle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:layout_constraintBottom_toBottomOf="@id/header_text" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="@id/header_text" /> + + android:id="@+id/description_text" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:textAppearance="@style/Body14TextStyle" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@id/header_text" + tools:text="@string/onboarding_tracking_protection_description1" /> + + + + + + + + + + + + +