From da1566977688c50f0af1a33b5efb7160abc3870a Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 9 Jul 2019 17:06:06 -0700 Subject: [PATCH] For #3134 - Add confirmation dialog to sign out of FxA --- .../fenix/settings/AccountProblemFragment.kt | 10 ++-- .../fenix/settings/AccountSettingsFragment.kt | 9 +-- .../mozilla/fenix/settings/SignOutFragment.kt | 59 +++++++++++++++++++ app/src/main/res/layout/fragment_sign_out.xml | 47 +++++++++++++++ app/src/main/res/navigation/nav_graph.xml | 36 +++++++---- 5 files changed, 140 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/settings/SignOutFragment.kt create mode 100644 app/src/main/res/layout/fragment_sign_out.xml diff --git a/app/src/main/java/org/mozilla/fenix/settings/AccountProblemFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AccountProblemFragment.kt index 9f73d192af56..d0fb059a2620 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AccountProblemFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AccountProblemFragment.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.settings import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope -import androidx.navigation.Navigation import androidx.navigation.fragment.NavHostFragment import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat @@ -19,6 +18,7 @@ import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.ext.getPreferenceKey +import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents class AccountProblemFragment : PreferenceFragmentCompat(), AccountObserver { @@ -67,10 +67,10 @@ class AccountProblemFragment : PreferenceFragmentCompat(), AccountObserver { private fun getClickListenerForSignOut(): Preference.OnPreferenceClickListener { return Preference.OnPreferenceClickListener { - lifecycleScope.launch { - requireComponents.backgroundServices.accountManager.logoutAsync().await() - } - Navigation.findNavController(view!!).popBackStack() + nav( + R.id.accountProblemFragment, + AccountProblemFragmentDirections.actionAccountProblemFragmentToSignOutFragment() + ) true } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt index 2551b2299e1c..c3dbe083d1e3 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/AccountSettingsFragment.kt @@ -34,6 +34,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.ext.getPreferenceKey +import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.requireComponents class AccountSettingsFragment : PreferenceFragmentCompat() { @@ -124,10 +125,10 @@ class AccountSettingsFragment : PreferenceFragmentCompat() { private fun getClickListenerForSignOut(): Preference.OnPreferenceClickListener { return Preference.OnPreferenceClickListener { - requireComponents.analytics.metrics.track(Event.SyncAccountSignOut) - lifecycleScope.launch { - accountManager.logoutAsync().await() - } + nav( + R.id.accountSettingsFragment, + AccountSettingsFragmentDirections.actionAccountSettingsFragmentToSignOutFragment() + ) true } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/SignOutFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SignOutFragment.kt new file mode 100644 index 000000000000..a8e74cc97419 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/settings/SignOutFragment.kt @@ -0,0 +1,59 @@ +/* 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.settings + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.fragment.app.DialogFragment +import androidx.lifecycle.lifecycleScope +import androidx.navigation.fragment.findNavController +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import kotlinx.coroutines.launch +import mozilla.components.service.fxa.manager.FxaAccountManager +import org.mozilla.fenix.R +import org.mozilla.fenix.components.metrics.Event +import org.mozilla.fenix.ext.requireComponents + +class SignOutFragment : BottomSheetDialogFragment() { + private lateinit var accountManager: FxaAccountManager + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(DialogFragment.STYLE_NO_TITLE, R.style.FirefoxAccountsDialogStyle) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + accountManager = requireComponents.backgroundServices.accountManager + return inflater.inflate(R.layout.fragment_sign_out, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val signOut = view.findViewById(R.id.sign_out_disconnect) as Button + signOut.setOnClickListener { + requireComponents.analytics.metrics.track(Event.SyncAccountSignOut) + lifecycleScope.launch { + accountManager.logoutAsync().await() + }.invokeOnCompletion { + if (!findNavController().popBackStack(R.id.settingsFragment, false)) { + dismiss() + } + } + } + + val cancelSignOut = view.findViewById(R.id.sign_out_cancel) as Button + cancelSignOut.setOnClickListener { + dismiss() + } + } +} diff --git a/app/src/main/res/layout/fragment_sign_out.xml b/app/src/main/res/layout/fragment_sign_out.xml new file mode 100644 index 000000000000..f5615a99e88e --- /dev/null +++ b/app/src/main/res/layout/fragment_sign_out.xml @@ -0,0 +1,47 @@ + + + + + + + +