1
0
Fork 0

For #2327: Fixes nits

master
Sawyer Blatz 2019-05-29 14:31:06 -07:00
parent fe50e88fc8
commit b8c04e02e9
13 changed files with 74 additions and 85 deletions

View File

@ -34,9 +34,9 @@ import org.mozilla.fenix.library.bookmarks.BookmarkFragmentDirections
import org.mozilla.fenix.library.bookmarks.selectfolder.SelectBookmarkFolderFragmentDirections import org.mozilla.fenix.library.bookmarks.selectfolder.SelectBookmarkFolderFragmentDirections
import org.mozilla.fenix.library.history.HistoryFragmentDirections import org.mozilla.fenix.library.history.HistoryFragmentDirections
import org.mozilla.fenix.search.SearchFragmentDirections import org.mozilla.fenix.search.SearchFragmentDirections
import org.mozilla.fenix.settings.AccountProblemFragmentDirections
import org.mozilla.fenix.settings.PairFragmentDirections import org.mozilla.fenix.settings.PairFragmentDirections
import org.mozilla.fenix.settings.SettingsFragmentDirections import org.mozilla.fenix.settings.SettingsFragmentDirections
import org.mozilla.fenix.settings.SyncProblemFragmentDirections
import org.mozilla.fenix.settings.TurnOnSyncFragmentDirections import org.mozilla.fenix.settings.TurnOnSyncFragmentDirections
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
@ -201,8 +201,8 @@ open class HomeActivity : AppCompatActivity() {
BrowserDirection.FromTurnOnSync -> TurnOnSyncFragmentDirections.actionTurnOnSyncFragmentToBrowserFragment( BrowserDirection.FromTurnOnSync -> TurnOnSyncFragmentDirections.actionTurnOnSyncFragmentToBrowserFragment(
customTabSessionId customTabSessionId
) )
BrowserDirection.FromSyncProblem -> BrowserDirection.FromAccountProblem ->
SyncProblemFragmentDirections.actionSyncProblemFragmentToBrowserFragment(customTabSessionId) AccountProblemFragmentDirections.actionAccountProblemFragmentToBrowserFragment(customTabSessionId)
} }
if (sessionObserver == null) if (sessionObserver == null)
sessionObserver = subscribeToSessions() sessionObserver = subscribeToSessions()
@ -292,5 +292,5 @@ open class HomeActivity : AppCompatActivity() {
enum class BrowserDirection { enum class BrowserDirection {
FromGlobal, FromHome, FromSearch, FromSettings, FromBookmarks, FromGlobal, FromHome, FromSearch, FromSettings, FromBookmarks,
FromBookmarksFolderSelect, FromHistory, FromPair, FromTurnOnSync, FromBookmarksFolderSelect, FromHistory, FromPair, FromTurnOnSync,
FromSyncProblem FromAccountProblem
} }

View File

@ -19,7 +19,7 @@ import org.mozilla.fenix.ext.components
class DefaultToolbarMenu( class DefaultToolbarMenu(
private val context: Context, private val context: Context,
private val hasSyncError: Boolean = false, private val hasAccountProblem: Boolean = false,
private val requestDesktopStateProvider: () -> Boolean = { false }, private val requestDesktopStateProvider: () -> Boolean = { false },
private val onItemTapped: (ToolbarMenu.Item) -> Unit = {} private val onItemTapped: (ToolbarMenu.Item) -> Unit = {}
) : ToolbarMenu { ) : ToolbarMenu {
@ -107,13 +107,13 @@ class DefaultToolbarMenu(
BrowserMenuHighlightableItem( BrowserMenuHighlightableItem(
label = context.getString(R.string.browser_menu_settings), label = context.getString(R.string.browser_menu_settings),
imageResource = R.drawable.ic_settings, imageResource = R.drawable.ic_settings,
iconTintColorResource = if (hasSyncError) iconTintColorResource = if (hasAccountProblem)
R.color.sync_error_text_color else R.color.sync_error_text_color else
DefaultThemeManager.resolveAttribute(R.attr.primaryText, context), DefaultThemeManager.resolveAttribute(R.attr.primaryText, context),
textColorResource = if (hasSyncError) textColorResource = if (hasAccountProblem)
R.color.sync_error_text_color else R.color.sync_error_text_color else
DefaultThemeManager.resolveAttribute(R.attr.primaryText, context), DefaultThemeManager.resolveAttribute(R.attr.primaryText, context),
highlight = if (hasSyncError) { highlight = if (hasAccountProblem) {
BrowserMenuHighlightableItem.Highlight( BrowserMenuHighlightableItem.Highlight(
imageResource = R.drawable.ic_alert, imageResource = R.drawable.ic_alert,
backgroundResource = R.color.sync_error_color backgroundResource = R.color.sync_error_color

View File

@ -20,7 +20,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.CustomTabToolbarMenu import org.mozilla.fenix.customtabs.CustomTabToolbarMenu
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.mvi.UIView import org.mozilla.fenix.mvi.UIView
import org.mozilla.fenix.utils.Settings
class ToolbarUIView( class ToolbarUIView(
sessionId: String?, sessionId: String?,
@ -105,7 +104,7 @@ class ToolbarUIView(
) )
} else { } else {
DefaultToolbarMenu(this, DefaultToolbarMenu(this,
hasSyncError = Settings.getInstance(this).hasSyncProblem, hasAccountProblem = components.backgroundServices.accountManager.accountNeedsReauth(),
requestDesktopStateProvider = { session?.desktopMode ?: false }, requestDesktopStateProvider = { session?.desktopMode ?: false },
onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) } onItemTapped = { actionEmitter.onNext(SearchAction.ToolbarMenuItemTapped(it)) }
) )

View File

@ -683,10 +683,7 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver {
Mode.Normal Mode.Normal
} }
override fun onAuthenticationProblems() { override fun onAuthenticationProblems() { emitAccountChanges() }
Settings.getInstance(context!!).setHasAuthenticationProblem(true)
emitAccountChanges()
}
override fun onAuthenticated(account: OAuthAccount) { emitAccountChanges() } override fun onAuthenticated(account: OAuthAccount) { emitAccountChanges() }
override fun onError(error: Exception) { emitAccountChanges() } override fun onError(error: Exception) { emitAccountChanges() }
override fun onLoggedOut() { emitAccountChanges() } override fun onLoggedOut() { emitAccountChanges() }

View File

@ -50,7 +50,6 @@ import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getAutoDisposeObservable import org.mozilla.fenix.mvi.getAutoDisposeObservable
import org.mozilla.fenix.mvi.getManagedEmitter import org.mozilla.fenix.mvi.getManagedEmitter
import org.mozilla.fenix.utils.allowUndo import org.mozilla.fenix.utils.allowUndo
import org.mozilla.fenix.utils.Settings
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@SuppressWarnings("TooManyFunctions", "LargeClass") @SuppressWarnings("TooManyFunctions", "LargeClass")
@ -365,7 +364,6 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
} }
override fun onAuthenticationProblems() { override fun onAuthenticationProblems() {
Settings.getInstance(context!!).setHasAuthenticationProblem(true)
} }
override fun onProfileUpdated(profile: Profile) { override fun onProfileUpdated(profile: Profile) {

View File

@ -46,7 +46,6 @@ import org.mozilla.fenix.library.bookmarks.SignInViewModel
import org.mozilla.fenix.mvi.ActionBusFactory import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.getAutoDisposeObservable import org.mozilla.fenix.mvi.getAutoDisposeObservable
import org.mozilla.fenix.mvi.getManagedEmitter import org.mozilla.fenix.mvi.getManagedEmitter
import org.mozilla.fenix.utils.Settings
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@SuppressWarnings("TooManyFunctions") @SuppressWarnings("TooManyFunctions")
@ -158,7 +157,6 @@ class SelectBookmarkFolderFragment : Fragment(), CoroutineScope, AccountObserver
} }
override fun onAuthenticationProblems() { override fun onAuthenticationProblems() {
Settings.getInstance(context!!).setHasAuthenticationProblem(true)
} }
override fun onAuthenticated(account: OAuthAccount) { override fun onAuthenticated(account: OAuthAccount) {

View File

@ -15,7 +15,7 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
class SyncProblemFragment : PreferenceFragmentCompat() { class AccountProblemFragment : PreferenceFragmentCompat() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
@ -46,7 +46,7 @@ class SyncProblemFragment : PreferenceFragmentCompat() {
// We could auto-close this tab once we get to the end of the authentication process? // We could auto-close this tab once we get to the end of the authentication process?
// Via an interceptor, perhaps. // Via an interceptor, perhaps.
view?.let { view?.let {
(activity as HomeActivity).openToBrowser(BrowserDirection.FromSyncProblem) (activity as HomeActivity).openToBrowser(BrowserDirection.FromAccountProblem)
} }
true true
} }

View File

@ -178,9 +178,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
navigateToAbout() navigateToAbout()
} }
resources.getString(pref_key_account) -> { resources.getString(pref_key_account) -> {
if (org.mozilla.fenix.utils.Settings.getInstance(preference.context).preferences if (requireComponents.backgroundServices.accountManager.accountNeedsReauth()) {
.getBoolean(context!!.getPreferenceKey(R.string.pref_key_sync_problem), false)) { navigateToAccountProblem()
navigateToSyncProblem()
} else { } else {
navigateToAccountSettings() navigateToAccountSettings()
} }
@ -314,8 +313,8 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
private fun navigateToSyncProblem() { private fun navigateToAccountProblem() {
val directions = SettingsFragmentDirections.actionSettingsFragmentToSyncProblemFragment() val directions = SettingsFragmentDirections.actionSettingsFragmentToAccountProblemFragment()
Navigation.findNavController(view!!).navigate(directions) Navigation.findNavController(view!!).navigate(directions)
} }
@ -333,7 +332,6 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
override fun onAuthenticated(account: OAuthAccount) { override fun onAuthenticated(account: OAuthAccount) {
updateAuthState(account) updateAuthState(account)
updateSignInVisibility() updateSignInVisibility()
displayAccountErrorIfNecessary()
} }
override fun onError(error: Exception) { override fun onError(error: Exception) {
@ -347,7 +345,6 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
override fun onLoggedOut() { override fun onLoggedOut() {
updateAuthState() updateAuthState()
updateSignInVisibility() updateSignInVisibility()
displayAccountErrorIfNecessary()
} }
override fun onProfileUpdated(profile: Profile) { override fun onProfileUpdated(profile: Profile) {
@ -355,7 +352,6 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
} }
override fun onAuthenticationProblems() { override fun onAuthenticationProblems() {
org.mozilla.fenix.utils.Settings.getInstance(context!!).setHasAuthenticationProblem(true)
displayAccountErrorIfNecessary() displayAccountErrorIfNecessary()
} }
@ -363,9 +359,6 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
private fun updateAuthState(account: OAuthAccount? = null) { private fun updateAuthState(account: OAuthAccount? = null) {
// Cache the user's auth state to improve performance of sign in visibility // Cache the user's auth state to improve performance of sign in visibility
org.mozilla.fenix.utils.Settings.getInstance(context!!).setHasCachedAccount(account != null) org.mozilla.fenix.utils.Settings.getInstance(context!!).setHasCachedAccount(account != null)
// Unset sync problems
org.mozilla.fenix.utils.Settings.getInstance(context!!).setHasAuthenticationProblem(false)
} }
private fun updateSignInVisibility() { private fun updateSignInVisibility() {
@ -390,59 +383,63 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
} }
} }
private fun updateAccountProfile(profile: Profile, error: Boolean = false) { private fun updateAccountProfile(profile: Profile) {
launch { launch {
val preferenceFirefoxAccount = context?.let { context ->
findPreference<AccountPreference>(context!!.getPreferenceKey(pref_key_account)) val preferenceFirefoxAccount =
findPreference<AccountPreference>(context.getPreferenceKey(pref_key_account))
preferenceFirefoxAccount?.title?.setTextColor( preferenceFirefoxAccount?.title?.setTextColor(
R.attr.primaryText.getColorFromAttr(context!!) R.attr.primaryText.getColorFromAttr(context)
) )
preferenceFirefoxAccount?.title?.text = profile.displayName.orEmpty() preferenceFirefoxAccount?.title?.text = profile.displayName.orEmpty()
preferenceFirefoxAccount?.title?.visibility = preferenceFirefoxAccount?.title?.visibility =
if (preferenceFirefoxAccount?.title?.text.isNullOrEmpty()) View.GONE else View.VISIBLE if (preferenceFirefoxAccount?.title?.text.isNullOrEmpty()) View.GONE else View.VISIBLE
preferenceFirefoxAccount?.summary?.setTextColor( preferenceFirefoxAccount?.summary?.setTextColor(
R.attr.primaryText.getColorFromAttr(context!!) R.attr.primaryText.getColorFromAttr(context)
) )
preferenceFirefoxAccount?.summary?.text = profile.email.orEmpty() preferenceFirefoxAccount?.summary?.text = profile.email.orEmpty()
preferenceFirefoxAccount?.icon = ContextCompat.getDrawable(context!!, R.drawable.ic_shortcuts) preferenceFirefoxAccount?.icon = ContextCompat.getDrawable(context, R.drawable.ic_shortcuts)
preferenceFirefoxAccount?.errorIcon?.visibility = View.GONE preferenceFirefoxAccount?.errorIcon?.visibility = View.GONE
preferenceFirefoxAccount?.background?.background = null preferenceFirefoxAccount?.background?.background = null
}
} }
} }
private fun displayAccountErrorIfNecessary() { private fun displayAccountErrorIfNecessary() {
if (!org.mozilla.fenix.utils.Settings.getInstance(context!!).hasSyncProblem) { return }
launch { launch {
val preferenceFirefoxAccount = context?.let { context ->
findPreference<AccountPreference>(context!!.getPreferenceKey(pref_key_account)) if (context.components.backgroundServices.accountManager.accountNeedsReauth()) { return@launch }
preferenceFirefoxAccount?.title?.setTextColor( val preferenceFirefoxAccount =
ContextCompat.getColor( findPreference<AccountPreference>(context.getPreferenceKey(pref_key_account))
context!!,
R.color.sync_error_text_color preferenceFirefoxAccount?.title?.setTextColor(
ContextCompat.getColor(
context,
R.color.sync_error_text_color
)
) )
) preferenceFirefoxAccount?.title?.text = context.getString(R.string.preferences_account_sync_error)
preferenceFirefoxAccount?.title?.text = context!!.getString(R.string.preferences_account_sync_error) preferenceFirefoxAccount?.title?.visibility =
preferenceFirefoxAccount?.title?.visibility = if (preferenceFirefoxAccount?.title?.text.isNullOrEmpty()) View.GONE else View.VISIBLE
if (preferenceFirefoxAccount?.title?.text.isNullOrEmpty()) View.GONE else View.VISIBLE
preferenceFirefoxAccount?.summary?.setTextColor( preferenceFirefoxAccount?.summary?.setTextColor(
ContextCompat.getColor( ContextCompat.getColor(
context!!, context,
R.color.sync_error_text_color R.color.sync_error_text_color
)
) )
) preferenceFirefoxAccount?.summary?.text =
preferenceFirefoxAccount?.summary?.text = context.components.backgroundServices.accountManager.accountProfile()?.email.orEmpty()
requireComponents.backgroundServices.accountManager.accountProfile()?.email.orEmpty()
preferenceFirefoxAccount?.icon = ContextCompat.getDrawable(context!!, R.drawable.ic_account_warning) preferenceFirefoxAccount?.icon = ContextCompat.getDrawable(context, R.drawable.ic_account_warning)
preferenceFirefoxAccount?.errorIcon?.visibility = View.VISIBLE preferenceFirefoxAccount?.errorIcon?.visibility = View.VISIBLE
preferenceFirefoxAccount?.background?.background = preferenceFirefoxAccount?.background?.background =
ContextCompat.getDrawable(context!!, R.color.sync_error_color) ContextCompat.getDrawable(context, R.color.sync_error_color)
}
} }
} }
} }

View File

@ -155,9 +155,6 @@ class Settings private constructor(context: Context) {
val hasCachedAccount: Boolean val hasCachedAccount: Boolean
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_cached_account), false) get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_cached_account), false)
val hasSyncProblem: Boolean
get() = preferences.getBoolean(appContext.getPreferenceKey(R.string.pref_key_sync_problem), false)
private val autoBounceQuickActionSheetCount: Int private val autoBounceQuickActionSheetCount: Int
get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0)) get() = (preferences.getInt(appContext.getPreferenceKey(R.string.pref_key_bounce_quick_action), 0))
@ -238,12 +235,6 @@ class Settings private constructor(context: Context) {
.apply() .apply()
} }
fun setHasAuthenticationProblem(hasProblem: Boolean) {
preferences.edit()
.putBoolean(appContext.getPreferenceKey(R.string.pref_key_sync_problem), hasProblem)
.apply()
}
private val SitePermissionsRules.Action.id: Int private val SitePermissionsRules.Action.id: Int
get() { get() {
return when (this) { return when (this) {

View File

@ -1,3 +1,7 @@
<!-- 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/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"

View File

@ -1,3 +1,7 @@
<!-- 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/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"

View File

@ -290,8 +290,8 @@
<action <action
android:id="@+id/action_settingsFragment_to_deleteBrowsingDataFragment" android:id="@+id/action_settingsFragment_to_deleteBrowsingDataFragment"
app:destination="@id/deleteBrowsingDataFragment" /> app:destination="@id/deleteBrowsingDataFragment" />
<action android:id="@+id/action_settingsFragment_to_syncProblemFragment" <action android:id="@+id/action_settingsFragment_to_accountProblemFragment"
app:destination="@id/syncProblemFragment"/> app:destination="@id/accountProblemFragment"/>
</fragment> </fragment>
<fragment <fragment
android:id="@+id/dataChoicesFragment" android:id="@+id/dataChoicesFragment"
@ -457,8 +457,9 @@
app:popUpTo="@id/quickSettingsSheetDialogFragment" app:popUpTo="@id/quickSettingsSheetDialogFragment"
app:popUpToInclusive="true" /> app:popUpToInclusive="true" />
</dialog> </dialog>
<fragment android:id="@+id/syncProblemFragment" android:name="org.mozilla.fenix.settings.SyncProblemFragment" <fragment android:id="@+id/accountProblemFragment" android:name="org.mozilla.fenix.settings.AccountProblemFragment"
android:label="SyncProblemFragment"> android:label="AccountProblemFragment">
<action android:id="@+id/action_syncProblemFragment_to_browserFragment" app:destination="@id/browserFragment"/> <action android:id="@+id/action_accountProblemFragment_to_browserFragment"
app:destination="@id/browserFragment"/>
</fragment> </fragment>
</navigation> </navigation>

View File

@ -35,7 +35,7 @@ private object Versions {
// The version number below tracks the application-services version // The version number below tracks the application-services version
// that we depend on directly for tests, and it's important that it // that we depend on directly for tests, and it's important that it
// be kept in sync with the version used by android-components above. // be kept in sync with the version used by android-components above.
const val mozilla_appservices = "0.28.1" const val mozilla_appservices = "0.29.0"
const val autodispose = "1.1.0" const val autodispose = "1.1.0"
const val adjust = "4.11.4" const val adjust = "4.11.4"