Skip to content

Commit

Permalink
Add dev settings to clear previously seen surveys so they can be test…
Browse files Browse the repository at this point in the history
…ed again
  • Loading branch information
CDRussell committed Apr 26, 2024
1 parent 3d103c3 commit 166194d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.withContext
interface AutofillSurveyStore {
suspend fun hasSurveyBeenTaken(id: String): Boolean
suspend fun recordSurveyWasShown(id: String)
suspend fun resetPreviousSurveys()
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -60,6 +61,14 @@ class AutofillSurveyStoreImpl @Inject constructor(
}
}

override suspend fun resetPreviousSurveys() {
withContext(dispatchers.io()) {
prefs.edit {
remove(SURVEY_IDS)
}
}
}

companion object {
private const val PREFS_FILE_NAME = "autofill_survey_store"
private const val SURVEY_IDS = "survey_ids"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.duckduckgo.autofill.impl.configuration.AutofillJavascriptEnvironmentC
import com.duckduckgo.autofill.impl.email.incontext.store.EmailProtectionInContextDataStore
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.store.NeverSavedSiteRepository
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurveyStore
import com.duckduckgo.autofill.internal.databinding.ActivityAutofillInternalSettingsBinding
import com.duckduckgo.browser.api.UserBrowserProperties
import com.duckduckgo.common.ui.DuckDuckGoActivity
Expand Down Expand Up @@ -83,6 +84,9 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
@Inject
lateinit var autofillJavascriptEnvironmentConfiguration: AutofillJavascriptEnvironmentConfiguration

@Inject
lateinit var autofillSurveyStore: AutofillSurveyStore

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
Expand Down Expand Up @@ -132,6 +136,16 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
configureLoginsUiEventHandlers()
configureNeverSavedSitesEventHandlers()
configureAutofillJsConfigEventHandlers()
configureSurveyEventHandlers()
}

private fun configureSurveyEventHandlers() {
binding.autofillSurveyResetButton.setOnClickListener {
lifecycleScope.launch(dispatchers.io()) {
autofillSurveyStore.resetPreviousSurveys()
}
Toast.makeText(this, getString(R.string.autofillDevSettingsSurveySectionResetted), Toast.LENGTH_SHORT).show()
}
}

private fun configureNeverSavedSitesEventHandlers() = with(binding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,24 @@
app:primaryText="@string/autofillDevSettingsConfigDebugTitle"
app:secondaryText="@string/autofillDevSettingsConfigDebugSubtitle" />

<com.duckduckgo.common.ui.view.divider.HorizontalDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<com.duckduckgo.common.ui.view.listitem.SectionHeaderListItem
android:id="@+id/autofillSurveySectionTitle"
android:layout_width="match_parent"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
app:primaryText="@string/autofillDevSettingsSurveySectionTitle" />

<com.duckduckgo.common.ui.view.listitem.TwoLineListItem
android:id="@+id/autofillSurveyResetButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="@string/autofillDevSettingsSurveySectionResetPreviousSurveysTitle"
app:secondaryText="@string/autofillDevSettingsSurveySectionInstruction" />


</LinearLayout>
</androidx.core.widget.NestedScrollView>
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@
<string name="autofillDevSettingsAddSampleLoginsSameSubdomainSubtitle">Adds multiple logins for https://fill.dev with same username and password</string>
<string name="autofillDevSettingsAddSampleLoginsMultipleSubdomains">Add duplicate logins (across different subdomains)</string>
<string name="autofillDevSettingsAddSampleLoginsMultipleSubdomainsSubtitle">Adds multiple logins for https://fill.dev with same username and password but across different subdomains</string>

<string name="autofillDevSettingsSurveySectionTitle">Autofill Survey</string>
<string name="autofillDevSettingsSurveySectionResetPreviousSurveysTitle">Previously Seen Surveys</string>
<string name="autofillDevSettingsSurveySectionInstruction">Tap to reset available surveys</string>
<string name="autofillDevSettingsSurveySectionResetted">Previously seen surveys available again</string>
</resources>

0 comments on commit 166194d

Please sign in to comment.