From 54b7fd8834d03b26811680e375d1a1c82f5973d0 Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 31 Mar 2020 15:21:25 -0700 Subject: [PATCH] Make sure reconnect item is displayed in HomeMenu in case of account problems AccountObserver listeners were being triggered correctly, however, during every time we open HomeFragment, home menu gets re-created, which causes us to re-run the initialization block. Before this patch, the init block would never touch the account manager. After this patch, it will query it if account manager has already been initialized. --- app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt | 9 +++++++++ .../java/org/mozilla/fenix/utils/RunWhenReadyQueue.kt | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt index 19581bbae..d58cd7a93 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeMenu.kt @@ -121,7 +121,16 @@ class HomeMenu( onItemTapped.invoke(Item.Help) } + // Only query account manager if it has been initialized. + // We don't want to cause its initialization just for this check. + val accountAuthItem = if (context.components.backgroundServices.accountManagerAvailableQueue.isReady()) { + if (context.components.backgroundServices.accountManager.accountNeedsReauth()) reconnectToSyncItem else null + } else { + null + } + listOfNotNull( + accountAuthItem, whatsNewItem, BrowserMenuDivider(), BrowserMenuCategory( diff --git a/app/src/main/java/org/mozilla/fenix/utils/RunWhenReadyQueue.kt b/app/src/main/java/org/mozilla/fenix/utils/RunWhenReadyQueue.kt index 2a820a652..9b7167d1c 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/RunWhenReadyQueue.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/RunWhenReadyQueue.kt @@ -19,6 +19,13 @@ class RunWhenReadyQueue { private val tasks = CopyOnWriteArrayList<() -> Unit>() private val isReady = AtomicBoolean(false) + /** + * Was this queue ever marked as 'ready' via a call to [ready]? + * + * @return Boolean value indicating if this queue is 'ready'. + */ + fun isReady(): Boolean = isReady.get() + /** * Runs the [task] if this queue is marked as ready, or queues it for later execution. * Task will be executed on the main thread.