From ae1b209db438c0bc6bb8d594cd85cea8ccaf2637 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 31 Jul 2020 01:07:36 +0200 Subject: [PATCH] Implemented hiding update all accounts' transaction when no account has been added; Implemented array extension property isNotEmpty --- ui/BankingiOSApp/BankingiOSApp/ContentView.swift | 8 +++++--- ui/BankingiOSApp/BankingiOSApp/persistence/AppData.swift | 4 ++++ ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift | 9 +++++++++ .../BankingiOSApp/ui/views/AccountsTab.swift | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ContentView.swift b/ui/BankingiOSApp/BankingiOSApp/ContentView.swift index 1690cca8..f4cc7e52 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ContentView.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ContentView.swift @@ -113,9 +113,11 @@ struct ContentView: View { // due to a SwiftUI bug this cannot be set in AccountsTab directly, so i have to do it here self.navigationBarTitle = "Accounts" - self.leadingNavigationBarItem = AnyView(UpdateButton { _ in - self.presenter.updateAccountsTransactionsAsync { _ in } - }) + if data.hasAtLeastOneAccountBeenAdded { + self.leadingNavigationBarItem = AnyView(UpdateButton { _ in + self.presenter.updateAccountsTransactionsAsync { _ in } + }) + } } } diff --git a/ui/BankingiOSApp/BankingiOSApp/persistence/AppData.swift b/ui/BankingiOSApp/BankingiOSApp/persistence/AppData.swift index dcf0160f..8bc57669 100644 --- a/ui/BankingiOSApp/BankingiOSApp/persistence/AppData.swift +++ b/ui/BankingiOSApp/BankingiOSApp/persistence/AppData.swift @@ -8,12 +8,16 @@ class AppData : ObservableObject { @Published var banks: [Customer] = [] + @Published var hasAtLeastOneAccountBeenAdded: Bool = false + init() { banks = presenter.customers + hasAtLeastOneAccountBeenAdded = banks.isNotEmpty presenter.addAccountsChangedListener { banks in self.banks = banks + self.hasAtLeastOneAccountBeenAdded = banks.isNotEmpty } } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift index 203bf4f5..3fa81ad0 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/SwiftExtensions.swift @@ -90,6 +90,15 @@ extension Array where Element == NSDecimalNumber { } +extension Array { + + var isNotEmpty: Bool { + return !isEmpty + } + +} + + extension NSObject { var className: String { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift index 36dcc3a6..016231f7 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountsTab.swift @@ -11,7 +11,7 @@ struct AccountsTab: View { var body: some View { VStack { - if data.banks.isEmpty == false { + if data.banks.isNotEmpty { Form { AllBanksListItem(banks: data.banks)