For #2399 - Wires up tracking protection onboarding card

nightly-build-test
Jeff Boek 5 years ago
parent a2a4524e51
commit b3650cacff

@ -17,7 +17,7 @@ class OnboardingPrivacyNoticeViewHolder(view: View) : RecyclerView.ViewHolder(vi
init {
val icon = view.context.getDrawable(R.drawable.ic_onboarding_privacy_notice)
val size = view.context.dimen(R.dimen.onboarding_privacy_notice_icon_height_width)
val size = view.context.dimen(R.dimen.onboarding_header_icon_height_width)
icon?.setBounds(0, 0, size, size)
view.header_text.setCompoundDrawables(icon, null, null, null)

@ -7,17 +7,53 @@ package org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.onboarding_tracking_protection.view.*
import org.jetbrains.anko.dimen
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.Settings
class OnboardingTrackingProtectionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
class OnboardingTrackingProtectionViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
init {
val icon = view.context.getDrawable(R.drawable.ic_onboarding_tracking_protection)
val size = view.context.dimen(R.dimen.onboarding_header_icon_height_width)
icon?.setBounds(0, 0, size, size)
view.header_text.setCompoundDrawables(icon, null, null, null)
val appName = view.context.getString(R.string.app_name)
view.description_text.text = view.context.getString(
R.string.onboarding_tracking_protection_description,
appName
)
val switch = view.tracking_protection_toggle
switch.isChecked = Settings.getInstance(view.context).shouldUseTrackingProtection
switch.setOnCheckedChangeListener { _, isChecked ->
updateTrackingProtectionSetting(isChecked)
}
}
private fun updateTrackingProtectionSetting(enabled: Boolean) {
Settings.getInstance(view.context).setTrackingProtection(enabled)
with(view.context.components.core) {
val policy = createTrackingProtectionPolicy(enabled)
engine.settings.trackingProtectionPolicy = policy
with(sessionManager) {
sessions.forEach {
if (enabled)
getEngineSession(it)?.enableTrackingProtection(policy) else
getEngineSession(it)?.disableTrackingProtection()
}
}
}
view.context.components.useCases.sessionUseCases.reload.invoke()
}
companion object {
const val LAYOUT_ID = R.layout.onboarding_tracking_protection
}

@ -30,6 +30,8 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
val trackingProtectionKey =
context!!.getPreferenceKey(R.string.pref_key_tracking_protection)
val preferenceTP = findPreference<SwitchPreference>(trackingProtectionKey)
preferenceTP?.isChecked = Settings.getInstance(context!!).shouldUseTrackingProtection
preferenceTP?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
Settings.getInstance(requireContext()).setTrackingProtection(newValue = newValue as Boolean)

@ -0,0 +1,19 @@
<?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 android:height="24dp" android:viewportHeight="64"
android:viewportWidth="64" android:width="24dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillType="evenOdd"
android:pathData="M59,11.6997C58.9881,8.1013 56.3932,5.0447 52.8778,4.4881L32,1L11.129,4.4846C7.6125,5.0438 5.0164,8.1 5,11.6997C5,17.4403 5.0405,25.0341 5.3746,28.6212C6.3871,39.5427 8.4864,45.5324 13.64,52.3379C18.081,58.0678 24.5178,61.8669 31.6355,62.959L32,63L32.3611,62.959C39.4788,61.8669 45.9156,58.0678 50.3566,52.3379C55.5136,45.5324 57.596,39.5461 58.622,28.6212L58.622,28.6212C58.9764,24.8191 59,16.3891 59,11.6997ZM51.9125,27.9727C51.0013,37.6792 49.388,42.4027 45.0106,48.1911C41.7528,52.3239 37.1358,55.1362 32,56.116C26.8673,55.1354 22.2537,52.323 18.9995,48.1911C14.612,42.3891 13.0055,37.6792 12.0976,27.9761C11.8546,25.3925 11.75,19.6177 11.75,11.7235C11.762,11.4601 11.963,11.2452 12.2225,11.2184L32,7.9181L51.7809,11.2218C52.0393,11.2441 52.2407,11.458 52.25,11.7201C52.2669,19.4846 52.142,25.4096 51.9125,27.9727ZM18.5,17.0887C18.5506,23.802 18.7227,26.4369 18.8071,27.3276C19.6711,36.5427 21.1494,39.8055 24.3489,44.0512C26.3036,46.5166 28.9832,48.2892 32,49.1126L32,14.8396L18.5,17.0887Z"
android:strokeColor="#00000000" android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient android:endX="21.592728" android:endY="43.40673"
android:startX="53.66253" android:startY="4.9456143" android:type="linear">
<item android:color="#FF6A11CB" android:offset="0"/>
<item android:color="#FF2575FC" android:offset="1"/>
</gradient>
</aapt:attr>
</path>
</vector>

@ -2,8 +2,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/. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/onboarding_card"
style="@style/OnboardingCardLight"
android:layout_width="match_parent"
@ -11,15 +11,29 @@
android:orientation="vertical">
<TextView
android:id="@+id/header_text"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:drawableStart="@drawable/ic_onboarding_tracking_protection"
android:drawablePadding="12dp"
android:text="@string/onboarding_tracking_protection_header"
android:textAppearance="@style/HeaderTextStyle" />
android:textAppearance="@style/HeaderTextStyle"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/tracking_protection_toggle"/>
<Switch
android:id="@+id/tracking_protection_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/onboarding_tracking_protection_description"
android:textAppearance="@style/Body14TextStyle" />
</LinearLayout>
android:textAppearance="@style/Body14TextStyle"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header_text"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

@ -33,6 +33,6 @@
<!--Quick Settings-->
<dimen name="quicksettings_item_height">46dp</dimen>
<dimen name="onboarding_privacy_notice_icon_height_width">32dp</dimen>
<dimen name="onboarding_header_icon_height_width">32dp</dimen>
</resources>
Loading…
Cancel
Save