Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@

package com.duckduckgo.autofill.internal

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.Lifecycle.State.STARTED
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.tabs.BrowserNav
import com.duckduckgo.autofill.api.AutofillFeature
import com.duckduckgo.autofill.api.AutofillScreens.AutofillSettingsScreen
import com.duckduckgo.autofill.api.AutofillSettingsLaunchSource.InternalDevSettings
Expand All @@ -33,6 +37,8 @@ import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.autofill.impl.configuration.AutofillJavascriptEnvironmentConfiguration
import com.duckduckgo.autofill.impl.email.incontext.store.EmailProtectionInContextDataStore
import com.duckduckgo.autofill.impl.engagement.store.AutofillEngagementRepository
import com.duckduckgo.autofill.impl.importing.CsvPasswordImporter
import com.duckduckgo.autofill.impl.importing.CsvPasswordParser
import com.duckduckgo.autofill.impl.reporting.AutofillSiteBreakageReportingDataStore
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.store.NeverSavedSiteRepository
Expand Down Expand Up @@ -75,6 +81,12 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
@Inject
lateinit var autofillStore: InternalAutofillStore

@Inject
lateinit var csvPasswordParser: CsvPasswordParser

@Inject
lateinit var browserNav: BrowserNav

@Inject
lateinit var autofillPrefsStore: AutofillPrefsStore

Expand All @@ -101,6 +113,24 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
@Inject
lateinit var reportBreakageDataStore: AutofillSiteBreakageReportingDataStore

@Inject
lateinit var csvPasswordImporter: CsvPasswordImporter

private val importCsvLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
val data: Intent? = result.data
val fileUrl = data?.data

logcat { "cdr onActivityResult for CSV file request. resultCode=${result.resultCode}. uri=$fileUrl" }
if (fileUrl != null) {
lifecycleScope.launch {
val insertedIds = csvPasswordImporter.importCsv(fileUrl)
Toast.makeText(this@AutofillInternalSettingsActivity, "Imported ${insertedIds.size} passwords", Toast.LENGTH_LONG).show()
}
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
Expand Down Expand Up @@ -168,6 +198,7 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
configureEngagementEventHandlers()
configureReportBreakagesHandlers()
configureDeclineCounterHandlers()
configureImportPasswordsEventHandlers()
}

private fun configureReportBreakagesHandlers() {
Expand All @@ -179,6 +210,22 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
}
}

@SuppressLint("QueryPermissionsNeeded")
private fun configureImportPasswordsEventHandlers() {
binding.importPasswordsLaunchGooglePasswordWebpage.setClickListener {
val googlePasswordsUrl = "https://passwords.google.com/options?ep=1"
startActivity(browserNav.openInNewTab(this, googlePasswordsUrl))
}

binding.importPasswordsImportCsv.setClickListener {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "*/*"
}
importCsvLauncher.launch(intent)
}
}

private fun configureEngagementEventHandlers() {
binding.engagementClearEngagementHistoryButton.setOnClickListener {
lifecycleScope.launch(dispatchers.io()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@
android:layout_height="wrap_content"
app:primaryText="@string/autofillDevSettingsViewSavedLogins" />

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


<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/importPasswordsLaunchGooglePasswordWebpage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="@string/autofillDevSettingsImportPasswordsExportPasswordsOurAppTitle" />

<com.duckduckgo.common.ui.view.listitem.OneLineListItem
android:id="@+id/importPasswordsImportCsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:primaryText="@string/autofillDevSettingsImportPasswordsImportPasswordsCsvTitle" />


<com.duckduckgo.common.ui.view.divider.HorizontalDivider
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<string name="autofillDevSettingsNeverSavedSitesCountSubtitle" instruction="%1$d is count of how many websites have been added to a list">Number of sites: %1$d</string>
<string name="autofillDevSettingsNeverSavedSitesAddSampleButton">Add sample site (fill.dev)</string>

<string name="autofillDevSettingsImportPasswordsTitle">Import Passwords</string>
<string name="autofillDevSettingsImportPasswordsExportPasswordsOurAppTitle">Launch Google Passwords (normal tab)</string>
<string name="autofillDevSettingsImportPasswordsImportPasswordsCsvTitle">Import CSV</string>

<string name="autofillDevSettingsOverrideMaxInstallDialogTitle">Maximum number of days since install</string>
<string name="autofillDevSettingsOverrideMaxInstallDialogOkButtonText">OK</string>
<string name="autofillDevSettingsOverrideMaxInstallDialogCancelButtonText">Cancel</string>
Expand Down