diff --git a/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt b/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt index 308f6531e0a5..bb3361967194 100644 --- a/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt +++ b/autofill/autofill-internal/src/main/java/com/duckduckgo/autofill/internal/AutofillInternalSettingsActivity.kt @@ -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 @@ -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 @@ -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 @@ -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) @@ -168,6 +198,7 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() { configureEngagementEventHandlers() configureReportBreakagesHandlers() configureDeclineCounterHandlers() + configureImportPasswordsEventHandlers() } private fun configureReportBreakagesHandlers() { @@ -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()) { diff --git a/autofill/autofill-internal/src/main/res/layout/activity_autofill_internal_settings.xml b/autofill/autofill-internal/src/main/res/layout/activity_autofill_internal_settings.xml index 9018dec4ab59..1646042b7d70 100644 --- a/autofill/autofill-internal/src/main/res/layout/activity_autofill_internal_settings.xml +++ b/autofill/autofill-internal/src/main/res/layout/activity_autofill_internal_settings.xml @@ -85,6 +85,27 @@ android:layout_height="wrap_content" app:primaryText="@string/autofillDevSettingsViewSavedLogins" /> + + + + + + + + diff --git a/autofill/autofill-internal/src/main/res/values/donottranslate.xml b/autofill/autofill-internal/src/main/res/values/donottranslate.xml index 247348c0325d..fc2841729d65 100644 --- a/autofill/autofill-internal/src/main/res/values/donottranslate.xml +++ b/autofill/autofill-internal/src/main/res/values/donottranslate.xml @@ -37,6 +37,10 @@ Number of sites: %1$d Add sample site (fill.dev) + Import Passwords + Launch Google Passwords (normal tab) + Import CSV + Maximum number of days since install OK Cancel