parent
ec099a6e11
commit
13b7e64c9b
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/* 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.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import kotlinx.android.synthetic.main.fragment_sign_out.view.*
|
||||
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 onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val dialog = super.onCreateDialog(savedInstanceState)
|
||||
|
||||
dialog.setOnShowListener {
|
||||
val bottomSheet = dialog.findViewById<View>(
|
||||
com.google.android.material.R.id.design_bottom_sheet
|
||||
) as? FrameLayout
|
||||
val behavior = BottomSheetBehavior.from(bottomSheet)
|
||||
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
return dialog
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
view.sign_out_disconnect.setOnClickListener {
|
||||
requireComponents.analytics.metrics.track(Event.SyncAccountSignOut)
|
||||
lifecycleScope.launch {
|
||||
accountManager.logoutAsync().await()
|
||||
}.invokeOnCompletion {
|
||||
if (!findNavController().popBackStack(R.id.settingsFragment, false)) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.sign_out_cancel.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
<!-- 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/. -->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/sign_out_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?foundation"
|
||||
android:padding="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sign_out_message"
|
||||
style="@style/QuickSettingsText.Icon"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:drawableStart="@drawable/ic_info"
|
||||
android:text="@string/sign_out_confirmation_message"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/sign_out_cancel"
|
||||
style="@style/SitePermissionCancelButton"
|
||||
android:text="@string/sign_out_cancel"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/sign_out_disconnect"
|
||||
app:layout_constraintTop_toBottomOf="@+id/sign_out_message" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/sign_out_disconnect"
|
||||
style="@style/SitePermissionPrimaryButton"
|
||||
android:text="@string/sign_out_disconnect"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/sign_out_message" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -186,9 +186,9 @@
|
|||
app:argType="string" />
|
||||
<action
|
||||
android:id="@+id/action_bookmarkFragment_to_browserFragment"
|
||||
app:destination="@id/browserFragment"
|
||||
app:popUpTo="@id/libraryFragment"
|
||||
app:popUpToInclusive="true"
|
||||
app:destination="@id/browserFragment" />
|
||||
app:popUpToInclusive="true" />
|
||||
<action
|
||||
android:id="@+id/action_bookmarkFragment_self"
|
||||
app:destination="@id/bookmarkFragment" />
|
||||
|
@ -291,8 +291,9 @@
|
|||
<action
|
||||
android:id="@+id/action_settingsFragment_to_deleteBrowsingDataFragment"
|
||||
app:destination="@id/deleteBrowsingDataFragment" />
|
||||
<action android:id="@+id/action_settingsFragment_to_accountProblemFragment"
|
||||
app:destination="@id/accountProblemFragment"/>
|
||||
<action
|
||||
android:id="@+id/action_settingsFragment_to_accountProblemFragment"
|
||||
app:destination="@id/accountProblemFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/dataChoicesFragment"
|
||||
|
@ -319,7 +320,11 @@
|
|||
<fragment
|
||||
android:id="@+id/accountSettingsFragment"
|
||||
android:name="org.mozilla.fenix.settings.AccountSettingsFragment"
|
||||
android:label="@string/preferences_account_settings" />
|
||||
android:label="@string/preferences_account_settings">
|
||||
<action
|
||||
android:id="@+id/action_accountSettingsFragment_to_signOutFragment"
|
||||
app:destination="@id/signOutFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/searchEngineFragment"
|
||||
android:name="org.mozilla.fenix.settings.SearchEngineFragment"
|
||||
|
@ -380,8 +385,7 @@
|
|||
<fragment
|
||||
android:id="@+id/deleteBrowsingDataFragment"
|
||||
android:name="org.mozilla.fenix.settings.DeleteBrowsingDataFragment"
|
||||
android:label="@string/preferences_delete_browsing_data">
|
||||
</fragment>
|
||||
android:label="@string/preferences_delete_browsing_data"></fragment>
|
||||
<fragment
|
||||
android:id="@+id/exceptionsFragment"
|
||||
android:name="org.mozilla.fenix.exceptions.ExceptionsFragment"
|
||||
|
@ -394,7 +398,7 @@
|
|||
<dialog
|
||||
android:id="@+id/shareFragment"
|
||||
android:name="org.mozilla.fenix.share.ShareFragment"
|
||||
tools:layout="@layout/fragment_share" >
|
||||
tools:layout="@layout/fragment_share">
|
||||
<argument
|
||||
android:name="url"
|
||||
android:defaultValue="@null"
|
||||
|
@ -446,9 +450,17 @@
|
|||
app:popUpTo="@id/quickSettingsSheetDialogFragment"
|
||||
app:popUpToInclusive="true" />
|
||||
</dialog>
|
||||
<fragment android:id="@+id/accountProblemFragment" android:name="org.mozilla.fenix.settings.AccountProblemFragment"
|
||||
android:label="AccountProblemFragment">
|
||||
<action android:id="@+id/action_accountProblemFragment_to_browserFragment"
|
||||
app:destination="@id/browserFragment"/>
|
||||
<fragment
|
||||
android:id="@+id/accountProblemFragment"
|
||||
android:name="org.mozilla.fenix.settings.AccountProblemFragment">
|
||||
<action
|
||||
android:id="@+id/action_accountProblemFragment_to_signOutFragment"
|
||||
app:destination="@id/signOutFragment" />
|
||||
</fragment>
|
||||
<action
|
||||
android:id="@+id/action_accountProblemFragment_to_browserFragment"
|
||||
app:destination="@id/browserFragment" />
|
||||
<dialog
|
||||
android:id="@+id/signOutFragment"
|
||||
android:name="org.mozilla.fenix.settings.SignOutFragment" />
|
||||
</navigation>
|
Loading…
Reference in New Issue