1
0
Fork 0

For #2399 - Wires up tracking protection onboarding card

master
Jeff Boek 2019-05-20 16:17:14 -07:00
parent a2a4524e51
commit b3650cacff
6 changed files with 81 additions and 10 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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)

File diff suppressed because one or more lines are too long

View File

@ -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>

View File

@ -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>