Implemented displaying bank icon for transaction if transactions of all banks are displayed. Extracted IconView for that

This commit is contained in:
dankito 2020-08-05 00:39:17 +02:00
parent 62c3677769
commit bb2343d4f4
5 changed files with 66 additions and 24 deletions

View File

@ -62,6 +62,7 @@
36C4009B24D2F9E4005227AD /* IconedTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C4009A24D2F9E4005227AD /* IconedTitleView.swift */; };
36C4009D24D3236B005227AD /* UrlUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36C4009C24D3236B005227AD /* UrlUtil.swift */; };
36E21ECB24D88DF000649DC8 /* UIKitExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E21ECA24D88DF000649DC8 /* UIKitExtensions.swift */; };
36E21ECF24DA0EEE00649DC8 /* IconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E21ECE24DA0EEE00649DC8 /* IconView.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 */; };
@ -166,6 +167,7 @@
36C4009A24D2F9E4005227AD /* IconedTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconedTitleView.swift; sourceTree = "<group>"; };
36C4009C24D3236B005227AD /* UrlUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlUtil.swift; sourceTree = "<group>"; };
36E21ECA24D88DF000649DC8 /* UIKitExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitExtensions.swift; sourceTree = "<group>"; };
36E21ECE24DA0EEE00649DC8 /* IconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconView.swift; sourceTree = "<group>"; };
36E7BA1324B3D05C00757859 /* ViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtensions.swift; sourceTree = "<group>"; };
36E7BA1824B9E70C00757859 /* xcode-frameworks */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "xcode-frameworks"; path = "../../tools/BankFinder/build/xcode-frameworks"; sourceTree = "<group>"; };
36FC929824B39A05002B12E9 /* BankingiOSApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BankingiOSApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -384,6 +386,7 @@
36BE065A24CA4B3500CBBB68 /* SelectBankDialog.swift */,
36BE065C24CB08FB00CBBB68 /* LazyView.swift */,
36C4009A24D2F9E4005227AD /* IconedTitleView.swift */,
36E21ECE24DA0EEE00649DC8 /* IconView.swift */,
);
path = views;
sourceTree = "<group>";
@ -596,6 +599,7 @@
36BE069124CEF52800CBBB68 /* UpdateButton.swift in Sources */,
366FA4DC24C479120094F009 /* BankInfoListItem.swift in Sources */,
36FC929E24B39A05002B12E9 /* SceneDelegate.swift in Sources */,
36E21ECF24DA0EEE00649DC8 /* IconView.swift in Sources */,
36BCF88524C098C8005BEC29 /* BankAccountListItem.swift in Sources */,
36FC92EF24B3BB81002B12E9 /* AddAccountDialog.swift in Sources */,
36C4009D24D3236B005227AD /* UrlUtil.swift in Sources */,

View File

@ -15,6 +15,8 @@ struct AccountTransactionListItem: View {
private let transaction: AccountTransaction
private let areMoreThanOneBanksTransactionsDisplayed: Bool
private var transferMoneyData: TransferMoneyData
@ -22,9 +24,11 @@ struct AccountTransactionListItem: View {
@Inject private var presenter: BankingPresenterSwift
init(_ transaction: AccountTransaction) {
init(_ transaction: AccountTransaction, _ areMoreThanOneBanksTransactionsDisplayed: Bool) {
self.transaction = transaction
self.areMoreThanOneBanksTransactionsDisplayed = areMoreThanOneBanksTransactionsDisplayed
self.transferMoneyData = TransferMoneyData.Companion().fromAccountTransaction(transaction: transaction)
}
@ -45,6 +49,12 @@ struct AccountTransactionListItem: View {
Spacer()
VStack(alignment: .trailing) {
if areMoreThanOneBanksTransactionsDisplayed {
IconView(iconUrl: transaction.bankAccount.customer.iconUrl, defaultIconName: "")
Spacer()
}
AmountLabel(amount: transaction.amount)
Spacer()
@ -83,6 +93,6 @@ struct AccountTransactionListItem: View {
struct AccountTransactionListItem_Previews: PreviewProvider {
static var previews: some View {
AccountTransactionListItem(AccountTransaction(bankAccount: previewBanks[0].accounts[0], otherPartyName: "Marieke Musterfrau", unparsedUsage: "Vielen Dank für Ihre Mühen", amount: CommonBigDecimal(double: 1234.56), valueDate: CommonDate(year: 2020, month: .march, day_: 27), bookingText: "SEPA Überweisung"))
AccountTransactionListItem(AccountTransaction(bankAccount: previewBanks[0].accounts[0], otherPartyName: "Marieke Musterfrau", unparsedUsage: "Vielen Dank für Ihre Mühen", amount: CommonBigDecimal(double: 1234.56), valueDate: CommonDate(year: 2020, month: .march, day_: 27), bookingText: "SEPA Überweisung"), false)
}
}

View File

@ -10,6 +10,8 @@ struct AccountTransactionsDialog: View {
private let balanceOfAllTransactions: CommonBigDecimal
private let areMoreThanOneBanksTransactionsDisplayed: Bool
@State private var filteredTransactions: [AccountTransaction]
@ -56,6 +58,8 @@ struct AccountTransactionsDialog: View {
self.balanceOfAllTransactions = balance
self._balanceOfFilteredTransactions = State(initialValue: balance)
self.areMoreThanOneBanksTransactionsDisplayed = Set(allTransactions.compactMap { $0.bankAccount }.compactMap { $0.customer }).count > 1
}
@ -74,7 +78,7 @@ struct AccountTransactionsDialog: View {
.padding(.horizontal)
List(filteredTransactions.sorted(by: { $0.valueDate.date > $1.valueDate.date } ), id: \.technicalId) { transaction in
AccountTransactionListItem(transaction)
AccountTransactionListItem(transaction, self.areMoreThanOneBanksTransactionsDisplayed)
}
}
.showNavigationBarTitle(LocalizedStringKey(title))

View File

@ -0,0 +1,43 @@
import SwiftUI
struct IconView: View {
let iconUrl: String?
let defaultIconName: String
@Inject private var persistence: CoreDataBankingPersistence
var body: some View {
getBankIcon(self.iconUrl)
.renderingMode(Image.TemplateRenderingMode.original)
.resizable()
.scaledToFit()
.frame(width: 24)
}
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)
}
}
struct IconView_Previews: PreviewProvider {
static var previews: some View {
IconView(iconUrl: nil, defaultIconName: "")
}
}

View File

@ -13,9 +13,6 @@ struct IconedTitleView: View {
private var titleFont: Font?
@Inject private var persistence: CoreDataBankingPersistence
init(_ bank: Customer, titleFont: Font? = nil) {
self.init(accountTitle: bank.displayName, iconUrl: bank.iconUrl, defaultIconName: Styles.AccountFallbackIcon, titleFont: titleFont)
}
@ -35,29 +32,13 @@ struct IconedTitleView: View {
var body: some View {
HStack {
getBankIcon(self.iconUrl)
.renderingMode(Image.TemplateRenderingMode.original)
.resizable()
.scaledToFit()
.frame(width: 24)
IconView(iconUrl: self.iconUrl, defaultIconName: self.defaultIconName)
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(title)