summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-10-29 21:38:45 +0100
committerMarc Stibane <marc@taler.net>2023-10-29 21:38:45 +0100
commitd63adacb8eb239ab117e19fff79a87391fbcfa93 (patch)
tree189f8b5175861ba2b502bd6461816162540d84bc
parentb21a0786eb90bb4a9a291d2cdeeb78a36dc6a3bc (diff)
downloadtaler-ios-d63adacb8eb239ab117e19fff79a87391fbcfa93.tar.gz
taler-ios-d63adacb8eb239ab117e19fff79a87391fbcfa93.tar.bz2
taler-ios-d63adacb8eb239ab117e19fff79a87391fbcfa93.zip
Use AmountRowV for transactions
-rw-r--r--TalerWallet1/Views/Balances/BalancesSectionView.swift11
-rw-r--r--TalerWallet1/Views/Balances/PendingRowView.swift33
-rw-r--r--TalerWallet1/Views/Transactions/TransactionRowView.swift97
-rw-r--r--TalerWallet1/Views/Transactions/TransactionsListView.swift11
4 files changed, 97 insertions, 55 deletions
diff --git a/TalerWallet1/Views/Balances/BalancesSectionView.swift b/TalerWallet1/Views/Balances/BalancesSectionView.swift
index ea56359..a588698 100644
--- a/TalerWallet1/Views/Balances/BalancesSectionView.swift
+++ b/TalerWallet1/Views/Balances/BalancesSectionView.swift
@@ -73,7 +73,8 @@ extension BalancesSectionView: View {
Section {
if "KUDOS" == currency && !balance.available.isZero {
- Text("You can spend these KUDOS in the [Demo Shop](https://shop.demo.taler.net), or send them to another wallet.")
+ Text(iconOnly ? "Visit the [Demo Shop](https://shop.demo.taler.net)" :
+ "You can spend these KUDOS in the [Demo Shop](https://shop.demo.taler.net), or send them to another wallet.")
.accessibilityFont(.body)
.multilineTextAlignment(.leading)
}
@@ -102,7 +103,7 @@ extension BalancesSectionView: View {
LazyView {
TransactionsListView(stack: stack.push(),
navTitle: String(localized: "Uncompleted"),
- currency: currency,
+ currencyInfo: currencyInfo,
transactions: uncompletedTransactions,
showUpDown: false,
reloadAllAction: reloadUncompleted,
@@ -147,7 +148,7 @@ extension BalancesSectionView: View {
let threeTransactions = Array(slice)
TransactionsRowsView(symLog: symLog,
stack: stack.push(),
- currency: currency,
+ currencyInfo: currencyInfo,
transactions: threeTransactions,
reloadOneAction: reloadOneAction)
} header: {
@@ -199,7 +200,7 @@ fileprivate struct BalancesPendingRowView: View {
LazyView {
TransactionsListView(stack: stack.push(),
navTitle: String(localized: "Pending"),
- currency: currency,
+ currencyInfo: currencyInfo,
transactions: pendingTransactions,
showUpDown: false,
reloadAllAction: reloadPending,
@@ -274,7 +275,7 @@ fileprivate struct BalancesNavigationLinksView: View {
NavigationLink(destination: LazyView {
TransactionsListView(stack: stack.push(),
navTitle: String(localized: "Transactions"),
- currency: currency,
+ currencyInfo: currencyInfo,
transactions: completedTransactions,
showUpDown: true,
reloadAllAction: reloadAllAction,
diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift b/TalerWallet1/Views/Balances/PendingRowView.swift
index a8b9293..3bcbebf 100644
--- a/TalerWallet1/Views/Balances/PendingRowView.swift
+++ b/TalerWallet1/Views/Balances/PendingRowView.swift
@@ -5,18 +5,17 @@
import SwiftUI
import taler_swift
-struct InOrOutView: View {
+struct PendingRowContentV: View {
let titles: (String, String?)
let isHorizontal: Bool
let incoming: Bool
- let imageName: String
- public static func width(image1: String, titles: (String, String?), isHorizontal: Bool) -> CGFloat {
+ public static func width(titles: (String, String?), isHorizontal: Bool) -> CGFloat {
let imageFont = TalerFont.uiFont(.largeTitle)
let uiFont = TalerFont.uiFont(.body)
- let image2 = "++"
- let imageWidth = image2.widthOfString(usingUIFont: imageFont) + 8.0 // spacing: 8
+ let image = "++"
+ let imageWidth = image.widthOfString(usingUIFont: imageFont) + 8.0 // spacing: 8
let (title1, title2) = titles
let title1Width = title1.widthOfString(usingUIFont: uiFont)
var title2Width = 0.0
@@ -29,16 +28,20 @@ struct InOrOutView: View {
// let logStr = String(format: "image: %.2f title: %.2f total: %.2f", imageWidth, max(title1Width, title2Width), totalWidth)
// print(logStr)
- return imageWidth + max(title1Width, title2Width)
+ return imageWidth + (isHorizontal ? totalWidth
+ : max(title1Width, title2Width))
}
var body: some View {
+ let pendingColor = WalletColors().pendingColor(incoming)
+ let imageName = incoming ? "plus.circle"
+ : "minus.circle"
HStack(spacing: 8) {
- let pendingColor = WalletColors().pendingColor(incoming)
Image(systemName: imageName)
.foregroundColor(pendingColor)
.accessibilityFont(.largeTitle)
.accessibility(hidden: true)
+
Text(title(titles, isHorizontal))
.lineLimit(4)
.accessibilityFont(.body)
@@ -61,14 +64,11 @@ struct PendingRowView: View {
let outTitle1 = String(localized: "Pending", comment: "Top of line <Pending outgoing>")
let outTitle2 = String(localized: "outgoing", comment: "Bottom of line <pending outgoing>")
- func needVStack(available: CGFloat, inOrOutWidth: CGFloat, valueWidth: CGFloat) -> Bool {
- available < (inOrOutWidth + valueWidth + 40)
+ func needVStack(available: CGFloat, contentWidth: CGFloat, valueWidth: CGFloat) -> Bool {
+ available < (contentWidth + valueWidth + 40)
}
var body: some View {
- let imageName = incoming ? "plus.circle" // .fill
- : "minus.circle" // .fill
- let imageStr = String("\(Image(systemName: imageName))")
let pendingColor = WalletColors().pendingColor(incoming)
SingleAxisGeometryReader { width in
Group {
@@ -80,15 +80,14 @@ struct PendingRowView: View {
: (outTitle1, outTitle2)
let title = incoming ? inTitle
: outTitle
- let inOrOutWidth = InOrOutView.width(image1: imageStr,
- titles: incoming ? inTitle : outTitle,
- isHorizontal: true)
+ let contentWidth = PendingRowContentV.width(titles: incoming ? inTitle : outTitle,
+ isHorizontal: true)
- let needVStack = needVStack(available: width, inOrOutWidth: inOrOutWidth, valueWidth: amountWidth)
+ let needVStack = needVStack(available: width, contentWidth: contentWidth, valueWidth: amountWidth)
AmountRowV(amountStr: amountStr, amountColor: pendingColor, largeAmountFont: false,
fitsHorizontal: !needVStack, vertAlignment: .center) {
// isHorizontal=true to try to fit "- Pending outgoing" + amount in 1 line
- InOrOutView(titles: title, isHorizontal: true, incoming: incoming, imageName: imageName)
+ PendingRowContentV(titles: title, isHorizontal: true, incoming: incoming)
}
}
}
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index 3eaaa76..0fb3e01 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -5,24 +5,64 @@
import SwiftUI
import taler_swift
-struct TransactionRowCenter: View {
+struct TransactionRowContentV: View {
var centerTop: String
var centerBottom: String
+ let isHorizontal: Bool
+ let incoming: Bool
+ let foreColor:Color
+
+ public static func width(titles: (String, String?), isHorizontal: Bool) -> CGFloat {
+ let imageFont = TalerFont.uiFont(.largeTitle)
+ let uiFont1 = TalerFont.uiFont(.headline)
+ let uiFont2 = TalerFont.uiFont(.callout)
+
+ let image = "++"
+ let imageWidth = image.widthOfString(usingUIFont: imageFont) + 8.0 // spacing: 8
+ let (title1, title2) = titles
+ let title1Width = title1.widthOfString(usingUIFont: uiFont1)
+ var title2Width = 0.0
+ var totalWidth = title1Width
+ if let title2 {
+ title2Width = title2.widthOfString(usingUIFont: uiFont2)
+ let blankStr = " "
+ totalWidth += blankStr.widthOfString(usingUIFont: uiFont1) + title2Width
+ }
+
+// let logStr = String(format: "image: %.2f title: %.2f total: %.2f", imageWidth, max(title1Width, title2Width), totalWidth)
+// print(logStr)
+ return imageWidth + (isHorizontal ? totalWidth
+ : max(title1Width, title2Width))
+ }
var body: some View {
- VStack(alignment: .leading) {
- Text(centerTop)
- .accessibilityFont(.headline)
-// .fontWeight(.medium) iOS 16
- .padding(.bottom, -2.0)
- Text(centerBottom)
- .accessibilityFont(.callout)
+ let imageName = incoming ? "plus.circle.fill"
+ : "minus.circle.fill"
+ HStack(spacing: 8) {
+ Image(systemName: imageName)
+ .foregroundColor(foreColor)
+ .accessibilityFont(.largeTitle)
+ .accessibility(hidden: true)
+
+ VStack(alignment: .leading) {
+ Text(centerTop)
+ .accessibilityFont(.headline)
+// .fontWeight(.medium) iOS 16
+ .padding(.bottom, -2.0)
+ Text(centerBottom)
+ .accessibilityFont(.callout)
+ }
}
}
}
struct TransactionRowView: View {
- var transaction : Transaction
+ let transaction : Transaction
+ let currencyInfo: CurrencyInfo?
+
+ func needVStack(available: CGFloat, contentWidth: CGFloat, valueWidth: CGFloat) -> Bool {
+ available < (contentWidth + valueWidth + 40)
+ }
var body: some View {
let common = transaction.common
@@ -38,26 +78,23 @@ struct TransactionRowView: View {
: done ? WalletColors().transactionColor(incoming)
: WalletColors().uncompletedColor
- HStack(spacing: 6) {
- Image(systemName: incoming ? "text.badge.plus" : "text.badge.minus")
- .foregroundColor(foreColor)
- .accessibilityFont(.largeTitle)
- .accessibility(hidden: true)
+ SingleAxisGeometryReader { width in
+ Group {
+ let amountStr = amount.string(currencyInfo)
+ let amountWidth = amountStr.width(largeAmountFont: false)
+
+ let contentWidth = PendingRowContentV.width(titles: (transaction.localizedType, dateString),
+ isHorizontal: true)
+ let needVStack = needVStack(available: width, contentWidth: contentWidth, valueWidth: amountWidth)
+
+ AmountRowV(amountStr: amountStr, amountColor: foreColor, largeAmountFont: false,
+ fitsHorizontal: !needVStack, vertAlignment: .center) {
- TransactionRowCenter(centerTop: transaction.localizedType,
- centerBottom: dateString)
- Spacer()
- VStack(alignment: .trailing) {
- let sign = incoming ? "+" : "-"
- let valueStr = sign + amount.valueStr
- Text(valueStr)
- .foregroundColor(foreColor)
- .accessibilityFont(.title)
- .monospacedDigit()
+ TransactionRowContentV(centerTop: transaction.localizedType,
+ centerBottom: dateString, isHorizontal: true, incoming: incoming, foreColor: foreColor)
+ }
}
}
- .accessibilityElement(children: .combine)
- .padding(.top)
}
}
// MARK: -
@@ -72,9 +109,13 @@ struct TransactionRow_Previews: PreviewProvider {
id: "some payment ID",
time: Timestamp(from: 1_666_666_000_000))
static var previews: some View {
+ let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0)
+ let demoInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 2)
+ let test = try! Amount(fromString: TESTCURRENCY + ":1.23")
+ let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.56")
List {
- TransactionRowView(transaction: withdrawal)
- TransactionRowView(transaction: payment)
+ TransactionRowView(transaction: withdrawal, currencyInfo: testInfo)
+ TransactionRowView(transaction: payment, currencyInfo: demoInfo)
}
}
}
diff --git a/TalerWallet1/Views/Transactions/TransactionsListView.swift b/TalerWallet1/Views/Transactions/TransactionsListView.swift
index 8322ba5..6dc1a4b 100644
--- a/TalerWallet1/Views/Transactions/TransactionsListView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionsListView.swift
@@ -11,7 +11,7 @@ struct TransactionsListView: View {
@AppStorage("myListStyle") var myListStyle: MyListStyle = .automatic
let navTitle: String
- let currency: String
+ let currencyInfo: CurrencyInfo?
let transactions: [Transaction]
let showUpDown: Bool
let reloadAllAction: (_ stack: CallStack) async -> ()
@@ -30,7 +30,7 @@ struct TransactionsListView: View {
List {
TransactionsRowsView(symLog: symLog,
stack: stack.push(),
- currency: currency,
+ currencyInfo: currencyInfo,
transactions: transactions,
// reloadAllAction: reloadAllAction,
reloadOneAction: reloadOneAction)
@@ -68,7 +68,8 @@ struct TransactionsListView: View {
}
.overlay {
if transactions.isEmpty {
- TransactionsEmptyView(stack: stack.push(), currency: currency)
+ let unknown = String(localized: "Unknown currency")
+ TransactionsEmptyView(stack: stack.push(), currency: currencyInfo?.scope.currency ?? unknown)
}
}
.onAppear {
@@ -81,7 +82,7 @@ struct TransactionsListView: View {
struct TransactionsRowsView: View {
let symLog: SymLogV?
let stack: CallStack
- let currency: String
+ let currencyInfo: CurrencyInfo?
let transactions: [Transaction]
// let reloadAllAction: (_ stack: CallStack) async -> ()
let reloadOneAction: ((_ transactionId: String) async throws -> Transaction)
@@ -112,7 +113,7 @@ struct TransactionsRowsView: View {
resumeAction: resumeAction)
}
} label: {
- TransactionRowView(transaction: transaction)
+ TransactionRowView(transaction: transaction, currencyInfo: currencyInfo)
}
.id(Int(index))
}