2019-07-15 23:21:13 +00:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-09-14 04:29:11 +00:00
|
|
|
package org.mozilla.fenix.settings.account
|
2019-07-15 23:21:13 +00:00
|
|
|
|
|
|
|
import android.app.Dialog
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.FrameLayout
|
2022-11-03 02:37:21 +00:00
|
|
|
import androidx.appcompat.app.AppCompatDialogFragment
|
2019-07-15 23:21:13 +00:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.navigation.fragment.findNavController
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
2022-11-03 02:37:21 +00:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
2019-07-15 23:21:13 +00:00
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import mozilla.components.service.fxa.manager.FxaAccountManager
|
|
|
|
import org.mozilla.fenix.R
|
2021-07-05 15:18:20 +00:00
|
|
|
import org.mozilla.fenix.databinding.FragmentSignOutBinding
|
2019-07-15 23:21:13 +00:00
|
|
|
import org.mozilla.fenix.ext.requireComponents
|
2021-01-05 21:15:22 +00:00
|
|
|
import org.mozilla.fenix.ext.runIfFragmentIsAttached
|
2019-07-15 23:21:13 +00:00
|
|
|
|
2020-12-02 21:48:01 +00:00
|
|
|
class SignOutFragment : AppCompatDialogFragment() {
|
2019-07-15 23:21:13 +00:00
|
|
|
private lateinit var accountManager: FxaAccountManager
|
|
|
|
|
2021-07-05 15:18:20 +00:00
|
|
|
private var _binding: FragmentSignOutBinding? = null
|
|
|
|
private val binding get() = _binding!!
|
|
|
|
|
2019-07-15 23:21:13 +00:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2020-12-02 21:48:01 +00:00
|
|
|
setStyle(STYLE_NO_TITLE, R.style.BottomSheet)
|
2019-07-15 23:21:13 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 21:48:01 +00:00
|
|
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog =
|
|
|
|
BottomSheetDialog(requireContext(), this.theme).apply {
|
|
|
|
setOnShowListener {
|
|
|
|
val bottomSheet =
|
|
|
|
findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout
|
|
|
|
val behavior = BottomSheetBehavior.from(bottomSheet)
|
|
|
|
behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
|
|
|
}
|
2019-07-15 23:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateView(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
|
|
|
savedInstanceState: Bundle?,
|
|
|
|
): View? {
|
|
|
|
accountManager = requireComponents.backgroundServices.accountManager
|
2021-07-05 15:18:20 +00:00
|
|
|
_binding = FragmentSignOutBinding.inflate(inflater, container, false)
|
|
|
|
|
|
|
|
binding.signOutMessage.text = String.format(
|
|
|
|
binding.root.context.getString(
|
2020-10-03 00:58:11 +00:00
|
|
|
R.string.sign_out_confirmation_message_2,
|
|
|
|
),
|
2021-07-05 15:18:20 +00:00
|
|
|
binding.root.context.getString(R.string.app_name),
|
2020-04-10 00:48:20 +00:00
|
|
|
)
|
2021-08-11 15:32:43 +00:00
|
|
|
return binding.root
|
2019-07-15 23:21:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
|
|
super.onViewCreated(view, savedInstanceState)
|
|
|
|
|
2021-07-05 15:18:20 +00:00
|
|
|
binding.signOutDisconnect.setOnClickListener {
|
2020-12-02 21:48:01 +00:00
|
|
|
lifecycleScope.launch {
|
2019-11-07 01:46:22 +00:00
|
|
|
requireComponents
|
|
|
|
.backgroundServices.accountAbnormalities.userRequestedLogout()
|
2020-07-28 02:46:36 +00:00
|
|
|
accountManager.logout()
|
2019-07-15 23:21:13 +00:00
|
|
|
}.invokeOnCompletion {
|
2020-12-02 21:48:01 +00:00
|
|
|
runIfFragmentIsAttached {
|
2021-04-28 09:52:08 +00:00
|
|
|
if (this.isVisible) {
|
2020-12-02 21:48:01 +00:00
|
|
|
dismiss()
|
|
|
|
}
|
2021-04-28 09:52:08 +00:00
|
|
|
findNavController().popBackStack()
|
2019-07-15 23:21:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 15:18:20 +00:00
|
|
|
binding.signOutCancel.setOnClickListener {
|
2019-07-15 23:21:13 +00:00
|
|
|
dismiss()
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 15:18:20 +00:00
|
|
|
|
|
|
|
override fun onDestroyView() {
|
|
|
|
super.onDestroyView()
|
|
|
|
_binding = null
|
|
|
|
}
|
2019-07-15 23:21:13 +00:00
|
|
|
}
|