Styled AccountTransactionListItem

This commit is contained in:
dankito 2020-07-26 19:49:37 +02:00
parent 293ab59eb6
commit be2b6f201c
3 changed files with 24 additions and 4 deletions

View File

@ -37,9 +37,14 @@ extension View {
.foregroundColor(Color.gray) .foregroundColor(Color.gray)
} }
func detailFont() -> some View {
return self
.font(.callout)
}
func styleAsDetail() -> some View { func styleAsDetail() -> some View {
return self return self
.font(.callout) .detailFont()
.detailForegroundColor() .detailForegroundColor()
} }

View File

@ -13,28 +13,43 @@ struct AccountTransactionListItem: View {
}() }()
let transaction: AccountTransaction private let transaction: AccountTransaction
private let amountColor: Color
@Inject private var presenter: BankingPresenterSwift @Inject private var presenter: BankingPresenterSwift
init(_ transaction: AccountTransaction) {
self.transaction = transaction
self.amountColor = transaction.amount.decimal.doubleValue < 0.0 ? Color.red : Color.green
}
var body: some View { var body: some View {
HStack { HStack {
VStack(alignment: .leading) { VStack(alignment: .leading) {
Text(getTransactionLabel(transaction)) Text(getTransactionLabel(transaction))
.font(.headline)
.padding(.bottom, 4)
Text(transaction.usage) Text(transaction.usage)
.styleAsDetail()
} }
Spacer() Spacer()
VStack(alignment: .trailing) { VStack(alignment: .trailing) {
Text(presenter.formatAmount(amount: transaction.amount)) Text(presenter.formatAmount(amount: transaction.amount))
.detailFont()
.foregroundColor(amountColor)
Spacer() Spacer()
Text(Self.ValueDateFormat.string(from: transaction.valueDate.date)) Text(Self.ValueDateFormat.string(from: transaction.valueDate.date))
.styleAsDetail()
} }
} }
} }
@ -56,6 +71,6 @@ struct AccountTransactionListItem: View {
struct AccountTransactionListItem_Previews: PreviewProvider { struct AccountTransactionListItem_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
AccountTransactionListItem(transaction: 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"))
} }
} }

View File

@ -14,7 +14,7 @@ struct AccountTransactionsDialog: View {
var body: some View { var body: some View {
List(transactions.sorted(by: { $0.valueDate.date > $1.valueDate.date } ), id: \.technicalId) { transaction in List(transactions.sorted(by: { $0.valueDate.date > $1.valueDate.date } ), id: \.technicalId) { transaction in
AccountTransactionListItem(transaction: transaction) AccountTransactionListItem(transaction)
} }
.showNavigationBarTitle(LocalizedStringKey(title)) .showNavigationBarTitle(LocalizedStringKey(title))
.navigationBarHidden(false) .navigationBarHidden(false)