diff --git a/app/src/main/java/org/mozilla/fenix/components/tips/providers/MasterPasswordTipProvider.kt b/app/src/main/java/org/mozilla/fenix/components/tips/providers/MasterPasswordTipProvider.kt deleted file mode 100644 index f54a5f253..000000000 --- a/app/src/main/java/org/mozilla/fenix/components/tips/providers/MasterPasswordTipProvider.kt +++ /dev/null @@ -1,252 +0,0 @@ -/* 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.components.tips.providers - -import android.annotation.SuppressLint -import android.content.Context -import android.text.Editable -import android.text.TextWatcher -import android.view.LayoutInflater -import androidx.appcompat.app.AlertDialog -import androidx.appcompat.content.res.AppCompatResources -import androidx.core.view.isVisible -import com.google.android.material.button.MaterialButton -import com.google.android.material.textfield.TextInputEditText -import com.google.android.material.textfield.TextInputLayout -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Dispatchers.IO -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import mozilla.components.concept.storage.Login -import mozilla.components.service.sync.logins.InvalidRecordException -import mozilla.components.service.sync.logins.LoginsStorageException -import mozilla.components.support.migration.FennecLoginsMPImporter -import mozilla.components.support.migration.FennecProfile -import org.mozilla.fenix.R -import org.mozilla.fenix.components.tips.Tip -import org.mozilla.fenix.components.tips.TipProvider -import org.mozilla.fenix.components.tips.TipType -import org.mozilla.fenix.ext.components -import org.mozilla.fenix.ext.settings - -/** - * Tip explaining to master password users how to migrate their logins. - */ -class MasterPasswordTipProvider( - private val context: Context, - private val navigateToLogins: () -> Unit, - private val dismissTip: (Tip) -> Unit -) : TipProvider { - - private val fennecLoginsMPImporter: FennecLoginsMPImporter? by lazy { - FennecProfile.findDefault( - context, - context.components.analytics.crashReporter - )?.let { - FennecLoginsMPImporter( - it - ) - } - } - - override val tip: Tip? by lazy { masterPasswordMigrationTip() } - - override val shouldDisplay: Boolean by lazy { - context.settings().shouldDisplayMasterPasswordMigrationTip && - fennecLoginsMPImporter?.hasMasterPassword() == true - } - - private fun masterPasswordMigrationTip(): Tip = - Tip( - type = TipType.Button( - text = context.getString(R.string.mp_homescreen_button), - action = ::showMasterPasswordMigration - ), - identifier = context.getString(R.string.pref_key_master_password_tip), - title = context.getString(R.string.mp_homescreen_tip_title), - description = context.getString(R.string.mp_homescreen_tip_message), - learnMoreURL = null, - titleDrawable = AppCompatResources.getDrawable(context, R.drawable.ic_login) - ) - - @SuppressLint("InflateParams") - private fun showMasterPasswordMigration() { - val dialogView = LayoutInflater.from(context).inflate(R.layout.mp_migration_dialog, null) - - val dialogBuilder = AlertDialog.Builder(context).apply { - setTitle(context.getString(R.string.mp_dialog_title_recovery_transfer_saved_logins)) - setMessage(context.getString(R.string.mp_dialog_message_recovery_transfer_saved_logins)) - setView(dialogView) - create() - } - - val dialog = dialogBuilder.show() - - val passwordErrorText = context.getString(R.string.mp_dialog_error_transfer_saved_logins) - val migrationContinueButton = - dialogView.findViewById(R.id.migration_continue).apply { - alpha = HALF_OPACITY - isEnabled = false - } - val passwordView = dialogView.findViewById(R.id.password_field) - val passwordLayout = - dialogView.findViewById(R.id.password_text_input_layout) - passwordView.addTextChangedListener( - object : TextWatcher { - var isValid = false - override fun afterTextChanged(p: Editable?) { - when { - p.toString().isEmpty() -> { - isValid = false - passwordLayout.error = passwordErrorText - } - else -> { - val possiblePassword = passwordView.text.toString() - isValid = - fennecLoginsMPImporter?.checkPassword(possiblePassword) == true - passwordLayout.error = if (isValid) null else passwordErrorText - } - } - migrationContinueButton.alpha = if (isValid) 1F else HALF_OPACITY - migrationContinueButton.isEnabled = isValid - } - - override fun beforeTextChanged( - p: CharSequence?, - start: Int, - count: Int, - after: Int - ) { - // NOOP - } - - override fun onTextChanged(p: CharSequence?, start: Int, before: Int, count: Int) { - // NOOP - } - }) - - migrationContinueButton.apply { - setOnClickListener { - // Step 1: Verify the password again before trying to use it - val possiblePassword = passwordView.text.toString() - val isValid = fennecLoginsMPImporter?.checkPassword(possiblePassword) == true - - // Step 2: With valid MP, get logins and complete the migration - if (isValid) { - val logins = fennecLoginsMPImporter?.getLoginRecords( - possiblePassword, - context.components.analytics.crashReporter - ) - - if (logins.isNullOrEmpty()) { - showFailureDialog() - dialog.dismiss() - } else { - saveLogins(logins, dialog) - } - } else { - passwordView.error = - context?.getString(R.string.mp_dialog_error_transfer_saved_logins) - } - } - } - - dialogView.findViewById(R.id.migration_cancel).apply { - setOnClickListener { - dialog.dismiss() - } - } - } - - @SuppressLint("InflateParams") - private fun showFailureDialog() { - val dialogView = - LayoutInflater.from(context).inflate(R.layout.mp_migration_done_dialog, null) - - val dialogBuilder = AlertDialog.Builder(context).apply { - setTitle(context.getString(R.string.mp_dialog_title_transfer_failure)) - setMessage(context.getString(R.string.mp_dialog_message_transfer_failure)) - setView(dialogView) - create() - } - - val dialog = dialogBuilder.show() - - dialogView.findViewById(R.id.positive_button).apply { - text = context.getString(R.string.mp_dialog_close_transfer) - setOnClickListener { - dismissMPTip() - dialog.dismiss() - } - } - dialogView.findViewById(R.id.negative_button).apply { - isVisible = false - } - } - - private fun saveLogins(logins: List, dialog: AlertDialog) { - CoroutineScope(IO).launch { - try { - context.components.core.passwordsStorage.importLoginsAsync(logins) - } catch (e: InvalidRecordException) { - // This record was invalid and we couldn't save this login - context.components.analytics.crashReporter.submitCaughtException(e) - } catch (e: LoginsStorageException) { - // Some other error occurred - context.components.analytics.crashReporter.submitCaughtException(e) - } - withContext(Dispatchers.Main) { - // Step 3: Dismiss this dialog and show the success dialog - showSuccessDialog() - dialog.dismiss() - } - } - } - - private fun dismissMPTip() { - tip?.let { - context.components.settings.preferences - .edit() - .putBoolean(it.identifier, false) - .apply() - - dismissTip(it) - } - } - - @SuppressLint("InflateParams") - private fun showSuccessDialog() { - dismissMPTip() - - val dialogView = - LayoutInflater.from(context).inflate(R.layout.mp_migration_done_dialog, null) - - val dialogBuilder = AlertDialog.Builder(context).apply { - setTitle(context.getString(R.string.mp_dialog_title_transfer_success)) - setMessage(context.getString(R.string.mp_dialog_message_transfer_success)) - setView(dialogView) - create() - } - - val dialog = dialogBuilder.show() - - dialogView.findViewById(R.id.positive_button).apply { - setOnClickListener { - navigateToLogins() - dialog.dismiss() - } - } - dialogView.findViewById(R.id.negative_button).apply { - setOnClickListener { - dialog.dismiss() - } - } - } - - companion object { - private const val HALF_OPACITY = .5F - } -} diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 36f1c7f67..0aef9018c 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -90,8 +90,6 @@ import org.mozilla.fenix.components.TabCollectionStorage import org.mozilla.fenix.components.accounts.AccountState import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.tips.FenixTipManager -import org.mozilla.fenix.components.tips.Tip -import org.mozilla.fenix.components.tips.providers.MasterPasswordTipProvider import org.mozilla.fenix.components.toolbar.FenixTabCounterMenu import org.mozilla.fenix.components.toolbar.ToolbarPosition import org.mozilla.fenix.databinding.FragmentHomeBinding @@ -248,13 +246,7 @@ class HomeFragment : Fragment() { topSites = getTopSites(components), tip = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { FenixTipManager( - listOf( - MasterPasswordTipProvider( - requireContext(), - ::navToSavedLogins, - ::dismissTip - ) - ) + listOf() ).getTip() }, recentBookmarks = emptyList(), @@ -424,10 +416,6 @@ class HomeFragment : Fragment() { displayWallpaperIfEnabled() } - private fun dismissTip(tip: Tip) { - sessionControlInteractor.onCloseTip(tip) - } - /** * Returns a [TopSitesConfig] which specifies how many top sites to display and whether or * not frequently visited sites should be displayed. @@ -710,13 +698,7 @@ class HomeFragment : Fragment() { topSites = getTopSites(components), tip = components.strictMode.resetAfter(StrictMode.allowThreadDiskReads()) { FenixTipManager( - listOf( - MasterPasswordTipProvider( - requireContext(), - ::navToSavedLogins, - ::dismissTip - ) - ) + listOf() ).getTip() }, showCollectionPlaceholder = components.settings.showCollectionsPlaceholderOnHome, @@ -790,12 +772,6 @@ class HomeFragment : Fragment() { } } - private fun navToSavedLogins() { - findNavController().navigate( - HomeFragmentDirections.actionGlobalSavedLoginsAuthFragment() - ) - } - private fun dispatchModeChanges(mode: Mode) { if (mode != Mode.fromBrowsingMode(browsingModeManager.mode)) { homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(mode)) diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 67d7465dd..81f8647c7 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -204,11 +204,6 @@ class Settings(private val appContext: Context) : PreferencesHolder { default = false ) - var shouldDisplayMasterPasswordMigrationTip by booleanPreference( - appContext.getString(R.string.pref_key_master_password_tip), - true - ) - var shouldReturnToBrowser by booleanPreference( appContext.getString(R.string.pref_key_return_to_browser), false diff --git a/app/src/main/res/drawable/ic_login.xml b/app/src/main/res/drawable/ic_login.xml deleted file mode 100644 index 49c2fd3f8..000000000 --- a/app/src/main/res/drawable/ic_login.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/app/src/main/res/layout/mp_migration_dialog.xml b/app/src/main/res/layout/mp_migration_dialog.xml deleted file mode 100644 index 7ae50ae55..000000000 --- a/app/src/main/res/layout/mp_migration_dialog.xml +++ /dev/null @@ -1,71 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/mp_migration_done_dialog.xml b/app/src/main/res/layout/mp_migration_done_dialog.xml deleted file mode 100644 index 672949bbc..000000000 --- a/app/src/main/res/layout/mp_migration_done_dialog.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/values/preference_keys.xml b/app/src/main/res/values/preference_keys.xml index 076a41518..547425010 100644 --- a/app/src/main/res/values/preference_keys.xml +++ b/app/src/main/res/values/preference_keys.xml @@ -226,8 +226,6 @@ pref_key_should_show_jump_back_in_tabs_popup - pref_key_master_password_tip - pref_key_debug_settings pref_key_open_tabs_count diff --git a/app/src/main/res/values/static_strings.xml b/app/src/main/res/values/static_strings.xml index 77f76c697..95f7e6eae 100644 --- a/app/src/main/res/values/static_strings.xml +++ b/app/src/main/res/values/static_strings.xml @@ -55,22 +55,6 @@ Firefox Daylight - - Looking for your logins? - If you had a master password before Firefox updated, you’ll need to enter it to transfer your saved logins. - Enter master password - Transfer saved logins - Enter your previous master password. - Continue and transfer - Cancel - Invalid password - Transfer successful - Your saved logins have been transferred to Firefox. - View saved logins - Close - Transfer failed - An unknown error occurred and logins could not be transferred. - Home region Current region