forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#3134 - Add confirmation dialog to sign out of FxA
- Loading branch information
Showing
5 changed files
with
140 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/org/mozilla/fenix/settings/SignOutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!-- 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"> | ||
|
||
<androidx.constraintlayout.widget.Guideline | ||
android:id="@+id/guideline" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" /> | ||
|
||
<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_constraintEnd_toStartOf="@+id/sign_out_disconnect" | ||
app:layout_constraintHorizontal_chainStyle="packed" | ||
app:layout_constraintStart_toEndOf="@+id/guideline" | ||
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_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_chainStyle="packed" | ||
app:layout_constraintStart_toEndOf="@+id/sign_out_cancel" | ||
app:layout_constraintTop_toTopOf="@+id/sign_out_cancel" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters