From 2a1b9ce198edda61026c439544ad3c356f669fa2 Mon Sep 17 00:00:00 2001 From: dankito Date: Fri, 31 Jul 2020 00:30:18 +0200 Subject: [PATCH] Implemented IconedTitleView to display bank's icon alongside its name --- .../BankingiOSApp.xcodeproj/project.pbxproj | 8 ++ .../BankingiOSApp/ui/views/BankListItem.swift | 3 +- .../ui/views/IconedTitleView.swift | 80 +++++++++++++++++++ .../ui/views/TransferMoneyDialog.swift | 2 +- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 ui/BankingiOSApp/BankingiOSApp/ui/views/IconedTitleView.swift diff --git a/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj b/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj index 27d37f1d..2d5b9a0f 100644 --- a/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj +++ b/ui/BankingiOSApp/BankingiOSApp.xcodeproj/project.pbxproj @@ -59,6 +59,8 @@ 36BE06C624D080C900CBBB68 /* FaviconType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE06C524D080C900CBBB68 /* FaviconType.swift */; }; 36BE06C824D0DE7400CBBB68 /* UIKitTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36BE06C724D0DE7400CBBB68 /* UIKitTextField.swift */; }; 36C4009824D23580005227AD /* SwiftBankIconFinderTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C4009724D23580005227AD /* SwiftBankIconFinderTest.swift */; }; + 36C4009B24D2F9E4005227AD /* IconedTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C4009A24D2F9E4005227AD /* IconedTitleView.swift */; }; + 36C4009D24D3236B005227AD /* UrlUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C4009C24D3236B005227AD /* UrlUtil.swift */; }; 36E7BA1424B3D05C00757859 /* ViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E7BA1324B3D05C00757859 /* ViewExtensions.swift */; }; 36FC929C24B39A05002B12E9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929B24B39A05002B12E9 /* AppDelegate.swift */; }; 36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36FC929D24B39A05002B12E9 /* SceneDelegate.swift */; }; @@ -160,6 +162,8 @@ 36BE06C524D080C900CBBB68 /* FaviconType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FaviconType.swift; sourceTree = ""; }; 36BE06C724D0DE7400CBBB68 /* UIKitTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitTextField.swift; sourceTree = ""; }; 36C4009724D23580005227AD /* SwiftBankIconFinderTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = SwiftBankIconFinderTest.swift; path = BankingiOSAppTests/BankIconFinder/SwiftBankIconFinderTest.swift; sourceTree = SOURCE_ROOT; }; + 36C4009A24D2F9E4005227AD /* IconedTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconedTitleView.swift; sourceTree = ""; }; + 36C4009C24D3236B005227AD /* UrlUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlUtil.swift; sourceTree = ""; }; 36E7BA1324B3D05C00757859 /* ViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtensions.swift; sourceTree = ""; }; 36E7BA1824B9E70C00757859 /* xcode-frameworks */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "xcode-frameworks"; path = "../../tools/BankFinder/build/xcode-frameworks"; sourceTree = ""; }; 36FC929824B39A05002B12E9 /* BankingiOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankingiOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -237,6 +241,7 @@ 36BE06C324D0801A00CBBB68 /* Size.swift */, 36BE06B924D0783800CBBB68 /* FaviconFinder.swift */, 36BE06B724D077EC00CBBB68 /* SwiftBankIconFinder.swift */, + 36C4009C24D3236B005227AD /* UrlUtil.swift */, ); path = BankIconFinder; sourceTree = ""; @@ -375,6 +380,7 @@ 36BE065824CA3CAB00CBBB68 /* UIKitSearchBar.swift */, 36BE065A24CA4B3500CBBB68 /* SelectBankDialog.swift */, 36BE065C24CB08FB00CBBB68 /* LazyView.swift */, + 36C4009A24D2F9E4005227AD /* IconedTitleView.swift */, ); path = views; sourceTree = ""; @@ -577,6 +583,7 @@ 36BE06C424D0801A00CBBB68 /* Size.swift in Sources */, 36FC92A324B39A05002B12E9 /* ContentView.swift in Sources */, 366FA4E624C6EBF40094F009 /* EnterTanState.swift in Sources */, + 36C4009B24D2F9E4005227AD /* IconedTitleView.swift in Sources */, 36BE065724C9E04800CBBB68 /* UIKitImageView.swift in Sources */, 36BCF88724C0A310005BEC29 /* PreviewData.swift in Sources */, 366FA4DA24C472A90094F009 /* Extensions.swift in Sources */, @@ -587,6 +594,7 @@ 36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */, 36BCF88524C098C8005BEC29 /* BankAccountListItem.swift in Sources */, 36FC92EF24B3BB81002B12E9 /* AddAccountDialog.swift in Sources */, + 36C4009D24D3236B005227AD /* UrlUtil.swift in Sources */, 36BE066524CDE62800CBBB68 /* AccountTransactionListItem.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift index 5438f765..782081a3 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankListItem.swift @@ -11,8 +11,7 @@ struct BankListItem : View { Section { ZStack { HStack { - Text(bank.displayName) - .font(.headline) + IconedTitleView(bank, titleFont: .title) Spacer() diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/IconedTitleView.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/IconedTitleView.swift new file mode 100644 index 00000000..66683219 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/IconedTitleView.swift @@ -0,0 +1,80 @@ +import SwiftUI +import BankingUiSwift + + +struct IconedTitleView: View { + + private var title: String + + private var iconUrl: String? + + private var defaultIconName: String + + private var titleFont: Font? + + + @Inject private var persistence: CoreDataBankingPersistence + + + init(_ bank: Customer, titleFont: Font? = nil) { + self.init(accountTitle: bank.displayName, iconUrl: bank.iconUrl, defaultIconName: "accounts", titleFont: titleFont) + } + + init(_ account: BankAccount, titleFont: Font? = nil) { + self.init(accountTitle: account.displayName, iconUrl: account.customer.iconUrl, defaultIconName: "accounts", titleFont: titleFont) + } + + init(accountTitle: String, iconUrl: String?, defaultIconName: String, titleFont: Font? = nil) { + self.title = accountTitle + self.iconUrl = iconUrl + + self.defaultIconName = defaultIconName + self.titleFont = titleFont + } + + + var body: some View { + HStack { + getBankIcon(self.iconUrl) + .renderingMode(Image.TemplateRenderingMode.original) + .resizable() + .scaledToFit() + .frame(width: 24) + + getTitleView() + } + } + + + private func getBankIcon(_ iconUrl: String?) -> Image { + if let iconUrl = iconUrl { + if let iconData = persistence.readContentOfFile(iconUrl) { + if let uiImage = UIImage(data: iconData) { + return Image(uiImage: uiImage) + } + } + } + + return Image(defaultIconName) + } + + private func getTitleView() -> Text { + if let titleFont = titleFont { + return Text(self.title) + .font(titleFont) + } + else { + return Text(title) + } + } + +} + + +struct IconedAccountTitle_Previews: PreviewProvider { + + static var previews: some View { + IconedTitleView(accountTitle: "Abzockbank", iconUrl: nil, defaultIconName: "accounts") + } + +} diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift index 56f17dac..46b4f1e8 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift @@ -83,7 +83,7 @@ struct TransferMoneyDialog: View { Section { Picker("Account", selection: $selectedAccountIndex) { ForEach(0 ..< self.accountsSupportingTransferringMoney.count) { accountIndex in - Text(self.accountsSupportingTransferringMoney[accountIndex].displayName) + IconedTitleView(self.accountsSupportingTransferringMoney[accountIndex]) } } }