Skip to content

Commit

Permalink
Add learn more link and disabled warning
Browse files Browse the repository at this point in the history
  • Loading branch information
laghee committed Feb 3, 2025
1 parent ff49fc8 commit c0d225b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.app.generalsettings

import android.os.Bundle
import android.view.View
import android.view.View.OnClickListener
import android.widget.CompoundButton
import androidx.core.view.isVisible
Expand All @@ -29,13 +30,18 @@ import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.databinding.ActivityGeneralSettingsBinding
import com.duckduckgo.app.generalsettings.GeneralSettingsViewModel.Command
import com.duckduckgo.app.generalsettings.GeneralSettingsViewModel.Command.LaunchShowOnAppLaunchScreen
import com.duckduckgo.app.generalsettings.GeneralSettingsViewModel.Command.OpenMaliciousLearnMore
import com.duckduckgo.app.generalsettings.showonapplaunch.ShowOnAppLaunchScreenNoParams
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.LastOpenedTab
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.NewTabPage
import com.duckduckgo.app.generalsettings.showonapplaunch.model.ShowOnAppLaunchOption.SpecificPage
import com.duckduckgo.app.global.view.fadeTransitionConfig
import com.duckduckgo.browser.api.ui.BrowserScreens.WebViewActivityWithParams
import com.duckduckgo.common.ui.DuckDuckGoActivity
import com.duckduckgo.common.ui.spans.DuckDuckGoClickableSpan
import com.duckduckgo.common.ui.view.addClickableSpan
import com.duckduckgo.common.ui.view.getColorFromAttr
import com.duckduckgo.common.ui.viewbinding.viewBinding
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.navigation.api.GlobalActivityStarter
Expand Down Expand Up @@ -79,6 +85,18 @@ class GeneralSettingsActivity : DuckDuckGoActivity() {
setContentView(binding.root)
setupToolbar(binding.includeToolbar.toolbar)

binding.maliciousLearnMore.addClickableSpan(
textSequence = getText(R.string.maliciousSiteSettingLearnMore),
spans = listOf(
"learn_more_link" to object : DuckDuckGoClickableSpan() {
override fun onClick(widget: View) {
viewModel.maliciousSiteLearnMoreClicked()
}
},
),
)
binding.maliciousDisabledMessage.setTextColor(getColorFromAttr(com.duckduckgo.mobile.android.R.attr.daxColorDestructive))

configureUiEventHandlers()
observeViewModel()
}
Expand All @@ -89,11 +107,6 @@ class GeneralSettingsActivity : DuckDuckGoActivity() {
binding.voiceSearchToggle.setOnCheckedChangeListener(voiceSearchChangeListener)
binding.showOnAppLaunchButton.setOnClickListener(showOnAppLaunchClickListener)
binding.maliciousToggle.setOnCheckedChangeListener(maliciousSiteProtectionToggleListener)
// binding.maliciousToggle.addClickableLink(
// annotation = "learn_more_link",
// textSequence = getText(R.string.maliciousSiteProtectionToggleHint),
// onClick = { viewModel.maliciousSitesSettingLearnMoreClicked() },
// )
}

private fun observeViewModel() {
Expand All @@ -115,6 +128,7 @@ class GeneralSettingsActivity : DuckDuckGoActivity() {
} else {
binding.autocompleteRecentlyVisitedSitesToggle.isVisible = false
}
binding.maliciousDisabledMessage.visibility = if (it.maliciousSiteProtectionEnabled) View.GONE else View.VISIBLE
binding.maliciousToggle.quietlySetIsChecked(
newCheckedState = it.maliciousSiteProtectionEnabled,
changeListener = maliciousSiteProtectionToggleListener,
Expand Down Expand Up @@ -149,6 +163,19 @@ class GeneralSettingsActivity : DuckDuckGoActivity() {
LaunchShowOnAppLaunchScreen -> {
globalActivityStarter.start(this, ShowOnAppLaunchScreenNoParams, fadeTransitionConfig())
}
OpenMaliciousLearnMore -> {
globalActivityStarter.start(
this,
WebViewActivityWithParams(
url = MALICIOUS_SITE_LEARN_MORE_URL,
screenTitle = getString(R.string.maliciousSiteLearnMoreTitle),
),
)
}
}
}

companion object {
private const val MALICIOUS_SITE_LEARN_MORE_URL = "https://duckduckgo.com/duckduckgo-help-pages/privacy/phishing-and-malware-protection/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class GeneralSettingsViewModel @Inject constructor(

sealed class Command {
data object LaunchShowOnAppLaunchScreen : Command()
data object OpenMaliciousLearnMore : Command()
}

private val _viewState = MutableStateFlow<ViewState?>(null)
Expand Down Expand Up @@ -168,6 +169,10 @@ class GeneralSettingsViewModel @Inject constructor(
}
}

fun maliciousSiteLearnMoreClicked() {
sendCommand(Command.OpenMaliciousLearnMore)
}

private fun observeShowOnAppLaunchOption() {
showOnAppLaunchOptionDataStore.optionFlow
.onEach { showOnAppLaunchOption ->
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/res/layout/activity_general_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,40 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_4"
app:primaryText="@string/maliciousSiteProtectionSettingTitle" />
app:primaryText="@string/maliciousSiteSettingTitle" />

<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/maliciousToggle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
app:primaryText="@string/maliciousSiteProtectionToggleHint"
app:primaryText="@string/maliciousSiteToggleHint"
app:primaryTextTruncated="false"
app:showSwitch="true" />

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/maliciousLearnMore"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/keyline_4"
android:layout_marginEnd="@dimen/keyline_4"
android:text="@string/maliciousSiteSettingLearnMore"
app:typography="body2"
app:textType="secondary" />

<com.duckduckgo.common.ui.view.text.DaxTextView
android:id="@+id/maliciousDisabledMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_4"
android:layout_marginStart="@dimen/keyline_4"
android:layout_marginEnd="@dimen/keyline_4"
android:text="@string/maliciousSiteSettingDisabled"
android:visibility="visible"
app:typography="body2"
app:textType="secondary" />

</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
5 changes: 5 additions & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<string name="maliciousSiteExpandedCTA"><![CDATA[<u>Accept Risk and Visit Site</u>]]></string>
<string name="maliciousSiteReportErrorTitle">Report a site incorrectly flagged as malicious</string>
<string name="maliciousSiteLearnMoreTitle">Learn more</string>
<string name="maliciousSiteSettingTitle">Site Safety Warnings</string>
<string name="maliciousSiteToggleHint">Warn me on sites flagged for phishing or malware</string>
<string name="maliciousSiteSettingLearnMore"><annotation type="learn_more_link">Learn More</annotation></string>
<string name="maliciousSiteSettingDisabled">Disabling this feature can put your information at risk.</string>


<!-- Broken Sites-->
<string name="brokenSitesLoginHint">What site are you signing in to? (required)</string>
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@

<!-- General Settings -->
<string name="generalSettingsActivityTitle" instruction="Title of the general settings screen">General</string>
<string name="maliciousSiteProtectionSettingTitle">Malicious Site Protection</string>
<string name="maliciousSiteProtectionToggleHint" instruction="Description of what protection the toggle enables">Warn me on sites flagged for phishing or malware\n<annotation type="learn_more_link">Learn More</annotation></string>

<!-- Web Tracking Protection -->
<string name="webTrackingProtectionActivityTitle">Web Tracking Protection</string>
Expand Down

0 comments on commit c0d225b

Please sign in to comment.