For #13037 - Use email to sign in to fxa if device has no camera

App can be installed on devices with no camera modules. Like Android TV boxes.
Will skip presenting the option to sign in by scanning a qr code in this case
and default to login with email and password.
pull/35/head
Mugurell 4 years ago committed by Emily Kager
parent f763a50384
commit 84976f308a

@ -17,6 +17,7 @@ import kotlinx.android.synthetic.main.fragment_turn_on_sync.view.*
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.support.ktx.android.content.hasCamera
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
@ -26,15 +27,11 @@ import org.mozilla.fenix.ext.showToolbar
class TurnOnSyncFragment : Fragment(), AccountObserver {
private val args by navArgs<TurnOnSyncFragmentArgs>()
private var shouldLoginJustWithEmail = false
private var pairWithEmailStarted = false
private val signInClickListener = View.OnClickListener {
requireComponents.services.accountsAuthFeature.beginAuthentication(requireContext())
requireComponents.analytics.metrics.track(Event.SyncAuthUseEmail)
// TODO The sign-in web content populates session history,
// so pressing "back" after signing in won't take us back into the settings screen, but rather up the
// session history stack.
// We could auto-close this tab once we get to the end of the authentication process?
// Via an interceptor, perhaps.
navigateToPairWithEmail()
}
private val paringClickListener = View.OnClickListener {
@ -46,6 +43,14 @@ class TurnOnSyncFragment : Fragment(), AccountObserver {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requireComponents.analytics.metrics.track(Event.SyncAuthOpened)
// App can be installed on devices with no camera modules. Like Android TV boxes.
// Let's skip presenting the option to sign in by scanning a qr code in this case
// and default to login with email and password.
shouldLoginJustWithEmail = !requireContext().hasCamera()
if (shouldLoginJustWithEmail) {
navigateToPairWithEmail()
}
}
override fun onDestroy() {
@ -55,16 +60,28 @@ class TurnOnSyncFragment : Fragment(), AccountObserver {
override fun onResume() {
super.onResume()
if (requireComponents.backgroundServices.accountManager.authenticatedAccount() != null) {
if (pairWithEmailStarted ||
requireComponents.backgroundServices.accountManager.authenticatedAccount() != null) {
findNavController().popBackStack()
return
}
requireComponents.backgroundServices.accountManager.register(this, owner = this)
showToolbar(getString(R.string.preferences_sync))
if (shouldLoginJustWithEmail) {
// Next time onResume is called, after returning from pairing with email this Fragment will be popped.
pairWithEmailStarted = true
} else {
requireComponents.backgroundServices.accountManager.register(this, owner = this)
showToolbar(getString(R.string.preferences_sync))
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (shouldLoginJustWithEmail) {
// Headless fragment. Don't need UI if we're taking the user to another screen.
return null
}
val view = inflater.inflate(R.layout.fragment_turn_on_sync, container, false)
view.signInScanButton.setOnClickListener(paringClickListener)
view.signInEmailButton.setOnClickListener(signInClickListener)
@ -99,4 +116,14 @@ class TurnOnSyncFragment : Fragment(), AccountObserver {
.show()
}
}
private fun navigateToPairWithEmail() {
requireComponents.services.accountsAuthFeature.beginAuthentication(requireContext())
requireComponents.analytics.metrics.track(Event.SyncAuthUseEmail)
// TODO The sign-in web content populates session history,
// so pressing "back" after signing in won't take us back into the settings screen, but rather up the
// session history stack.
// We could auto-close this tab once we get to the end of the authentication process?
// Via an interceptor, perhaps.
}
}

Loading…
Cancel
Save