From 8a50f1c19cd9b86be6170188c12e8e67c3c2188c Mon Sep 17 00:00:00 2001 From: vladikoff Date: Sun, 21 Apr 2019 22:07:36 -0400 Subject: [PATCH] [fenix] Initial view for the "Turn on Sync" fragment UX: https://mozilla.invisionapp.com/share/QSR2F8UD4PN#/screens/357470308 --- CHANGELOG.md | 1 + .../fenix/settings/SettingsFragment.kt | 11 +--- .../fenix/settings/TurnOnSyncFragment.kt | 50 +++++++++++++++++++ app/src/main/res/drawable/ic_sign_in.xml | 13 +++++ app/src/main/res/navigation/nav_graph.xml | 13 +++++ app/src/main/res/values/preference_keys.xml | 2 + app/src/main/res/values/strings.xml | 8 +++ .../main/res/xml/turn_on_sync_preferences.xml | 16 ++++++ 8 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt create mode 100644 app/src/main/res/drawable/ic_sign_in.xml create mode 100644 app/src/main/res/xml/turn_on_sync_preferences.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6cfd750c..7cada00e03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - #113 - Added QR code scanner - #975 - Added telemetry for preference switches - #1955 - Added a confirmation dialog for QR code and barcode searches +- #1874 - Added a "Turn on Sync" fragment for Firefox Accounts login and sign up ### Changed - #1429 - Updated site permissions ui for MVP diff --git a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt index eb7f2ecb84..8df75d5d48 100644 --- a/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt @@ -188,15 +188,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse private fun getClickListenerForSignIn(): OnPreferenceClickListener { return OnPreferenceClickListener { - requireComponents.services.accountsAuthFeature.beginAuthentication() - // 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. - view?.let { - (activity as HomeActivity).openToBrowser(BrowserDirection.FromSettings) - } + val directions = SettingsFragmentDirections.actionSettingsFragmentToSyncFragment() + Navigation.findNavController(view!!).navigate(directions) true } } diff --git a/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt b/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt new file mode 100644 index 0000000000..dd3cb51de3 --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/settings/TurnOnSyncFragment.kt @@ -0,0 +1,50 @@ +/* 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 androidx.appcompat.app.AppCompatActivity +import androidx.preference.Preference +import androidx.preference.PreferenceFragmentCompat +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.requireComponents + +class TurnOnSyncFragment : PreferenceFragmentCompat() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + (activity as AppCompatActivity).title = getString(R.string.preferences_sync) + (activity as AppCompatActivity).supportActionBar?.show() + } + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + setPreferencesFromResource(R.xml.turn_on_sync_preferences, rootKey) + + val preferenceSignIn = + findPreference(context!!.getPreferenceKey(R.string.pref_key_sync_sign_in)) + val preferenceNewAccount = + findPreference(context!!.getPreferenceKey(R.string.pref_key_sync_create_account)) + preferenceSignIn?.onPreferenceClickListener = getClickListenerForSignIn() + preferenceNewAccount?.onPreferenceClickListener = getClickListenerForSignIn() + } + + private fun getClickListenerForSignIn(): Preference.OnPreferenceClickListener { + return Preference.OnPreferenceClickListener { + requireComponents.services.accountsAuthFeature.beginAuthentication() + // 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. + view?.let { + (activity as HomeActivity).openToBrowser(BrowserDirection.FromSettings) + } + true + } + } +} diff --git a/app/src/main/res/drawable/ic_sign_in.xml b/app/src/main/res/drawable/ic_sign_in.xml new file mode 100644 index 0000000000..e02a2ef304 --- /dev/null +++ b/app/src/main/res/drawable/ic_sign_in.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 47d136e45d..a7469568fe 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -226,6 +226,9 @@ + @@ -261,6 +264,16 @@ android:name="org.mozilla.fenix.settings.SearchEngineFragment" android:label="SearchEngineFragment" /> + + + + pref_key_sync_bookmarks pref_key_sign_out pref_key_cached_account + pref_key_sync_sign_in + pref_key_sync_create_account pref_key_show_search_suggestions diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c22c47171..a0b38a866b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -179,6 +179,14 @@ %s health report + + + Turn on Sync + + Sign in + + Create an account + Light diff --git a/app/src/main/res/xml/turn_on_sync_preferences.xml b/app/src/main/res/xml/turn_on_sync_preferences.xml new file mode 100644 index 0000000000..a6fb9fbc82 --- /dev/null +++ b/app/src/main/res/xml/turn_on_sync_preferences.xml @@ -0,0 +1,16 @@ + + + + + + +