Bug 1796146 - Add learn more link to cookie banner handling settings page
This commit is contained in:
parent
aea7cbff9d
commit
9490561c75
|
@ -28,6 +28,7 @@ enum class BrowserDirection(@IdRes val fragmentId: Int) {
|
|||
FromAbout(R.id.aboutFragment),
|
||||
FromTrackingProtection(R.id.trackingProtectionFragment),
|
||||
FromHttpsOnlyMode(R.id.httpsOnlyFragment),
|
||||
FromCookieBanner(R.id.cookieBannerFragment),
|
||||
FromTrackingProtectionDialog(R.id.trackingProtectionPanelDialogFragment),
|
||||
FromSavedLoginsFragment(R.id.savedLoginsFragment),
|
||||
FromAddNewDeviceFragment(R.id.addNewDeviceFragment),
|
||||
|
|
|
@ -116,6 +116,7 @@ import org.mozilla.fenix.perf.StartupTimeline
|
|||
import org.mozilla.fenix.perf.StartupTypeTelemetry
|
||||
import org.mozilla.fenix.search.SearchDialogFragmentDirections
|
||||
import org.mozilla.fenix.session.PrivateNotificationService
|
||||
import org.mozilla.fenix.settings.CookieBannersFragmentDirections
|
||||
import org.mozilla.fenix.settings.HttpsOnlyFragmentDirections
|
||||
import org.mozilla.fenix.settings.SettingsFragmentDirections
|
||||
import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
|
||||
|
@ -850,6 +851,8 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
|
|||
HistoryMetadataGroupFragmentDirections.actionGlobalBrowser(customTabSessionId)
|
||||
BrowserDirection.FromTrackingProtectionExceptions ->
|
||||
TrackingProtectionExceptionsFragmentDirections.actionGlobalBrowser(customTabSessionId)
|
||||
BrowserDirection.FromCookieBanner ->
|
||||
CookieBannersFragmentDirections.actionGlobalBrowser(customTabSessionId)
|
||||
BrowserDirection.FromHttpsOnlyMode ->
|
||||
HttpsOnlyFragmentDirections.actionGlobalBrowser(customTabSessionId)
|
||||
BrowserDirection.FromAbout ->
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.mozilla.fenix.settings
|
|||
import android.os.Bundle
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreference
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.DISABLED
|
||||
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
|
||||
import mozilla.components.concept.engine.Settings
|
||||
|
@ -37,7 +37,7 @@ class CookieBannersFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
|
||||
private fun setupPreferences() {
|
||||
requirePreference<SwitchPreference>(R.string.pref_key_cookie_banner_v1).apply {
|
||||
requirePreference<SwitchPreferenceCompat>(R.string.pref_key_cookie_banner_v1).apply {
|
||||
onPreferenceChangeListener = object : SharedPreferenceUpdater() {
|
||||
override fun onPreferenceChange(
|
||||
preference: Preference,
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/* 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
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
||||
/**
|
||||
* Cookie banners switch preference with a learn more link.
|
||||
*/
|
||||
class CookieBannersSwitchPreference(context: Context, attrs: AttributeSet?) :
|
||||
LearnMoreSwitchPreference(context, attrs) {
|
||||
|
||||
override fun getLearnMoreUrl(): String {
|
||||
return SupportUtils.getGenericSumoURLForTopic(
|
||||
SupportUtils.SumoTopic.COOKIE_BANNER,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* 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
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.preference.PreferenceViewHolder
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import org.mozilla.fenix.BrowserDirection
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.asActivity
|
||||
|
||||
/**
|
||||
* A [SwitchPreferenceCompat] that include a learn more link.
|
||||
*/
|
||||
abstract class LearnMoreSwitchPreference(context: Context, attrs: AttributeSet?) :
|
||||
SwitchPreferenceCompat(context, attrs) {
|
||||
|
||||
init {
|
||||
layoutResource = R.layout.preference_switch_learn_more
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PreferenceViewHolder) {
|
||||
super.onBindViewHolder(holder)
|
||||
|
||||
getDescription()?.let {
|
||||
val summaryView = holder.findViewById(android.R.id.summary) as TextView
|
||||
summaryView.text = it
|
||||
summaryView.isVisible = true
|
||||
}
|
||||
|
||||
val learnMoreLink = holder.findViewById(R.id.link) as TextView
|
||||
learnMoreLink.paint?.isUnderlineText = true
|
||||
learnMoreLink.setOnClickListener {
|
||||
it.context.asActivity()?.let { activity ->
|
||||
(activity as HomeActivity).openToBrowserAndLoad(
|
||||
searchTermOrURL = getLearnMoreUrl(),
|
||||
newTab = true,
|
||||
from = BrowserDirection.FromCookieBanner,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val backgroundDrawableArray =
|
||||
context.obtainStyledAttributes(intArrayOf(R.attr.selectableItemBackground))
|
||||
val backgroundDrawable = backgroundDrawableArray.getDrawable(0)
|
||||
backgroundDrawableArray.recycle()
|
||||
learnMoreLink.background = backgroundDrawable
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description to be used the UI.
|
||||
*/
|
||||
open fun getDescription(): String? = null
|
||||
|
||||
/**
|
||||
* Returns the URL that should be used when the learn more link is clicked.
|
||||
*/
|
||||
abstract fun getLearnMoreUrl(): String
|
||||
}
|
|
@ -54,6 +54,7 @@ object SupportUtils {
|
|||
SMARTBLOCK("smartblock-enhanced-tracking-protection"),
|
||||
SPONSOR_PRIVACY("sponsor-privacy"),
|
||||
HTTPS_ONLY_MODE("https-only-mode-firefox-android"),
|
||||
COOKIE_BANNER("cookie-banner-reduction-firefox-android"),
|
||||
}
|
||||
|
||||
enum class MozillaPage(internal val path: String) {
|
||||
|
|
66
app/src/main/res/layout/preference_switch_learn_more.xml
Normal file
66
app/src/main/res/layout/preference_switch_learn_more.xml
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?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/. -->
|
||||
<LinearLayout 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"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceListItem"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="Send usage data" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="10"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="@android:id/title"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/title"
|
||||
tools:text="Mozilla strives to collect only what we need to provide and improve %1$s for everyone." />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/link"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:lineSpacingExtra="1sp"
|
||||
android:paddingBottom="4dp"
|
||||
android:text="@string/studies_learn_more"
|
||||
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
app:layout_constraintStart_toStartOf="@android:id/title"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/summary" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@android:id/widget_frame"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="end|center_vertical"
|
||||
android:minWidth="58dp"
|
||||
android:orientation="vertical" />
|
||||
|
||||
</LinearLayout>
|
|
@ -2,7 +2,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.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<SwitchPreference
|
||||
<org.mozilla.fenix.settings.CookieBannersSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="@string/pref_key_cookie_banner_v1"
|
||||
android:summary="@string/reduce_cookie_banner_summary"
|
||||
|
|
Loading…
Reference in New Issue
Block a user