Mercurial > public > simoleon
changeset 17:4a81e39186f1 v1.0
Minor UI changes
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 15 Jul 2021 20:24:13 +0100 |
parents | aec2e86e5dbd |
children | a3512b689bbe |
files | Simoleon.xcodeproj/project.pbxproj Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/ContentView.swift Simoleon/Helpers/CurrencyConversion.swift Simoleon/Helpers/CurrencyRow.swift Simoleon/Models/CurrencyQuoteModel.swift |
diffstat | 6 files changed, 29 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj Thu Jul 15 19:03:24 2021 +0100 +++ b/Simoleon.xcodeproj/project.pbxproj Thu Jul 15 20:24:13 2021 +0100 @@ -529,7 +529,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -553,7 +553,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 3; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES;
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon/ContentView.swift Thu Jul 15 19:03:24 2021 +0100 +++ b/Simoleon/ContentView.swift Thu Jul 15 20:24:13 2021 +0100 @@ -19,7 +19,6 @@ List(filterCurrencies(), id: \.self) { currency in NavigationLink(destination: CurrencyConversion(currency: currency)) { CurrencyRow(currency: currency) - .padding(.vertical, 7) } } .id(UUID())
--- a/Simoleon/Helpers/CurrencyConversion.swift Thu Jul 15 19:03:24 2021 +0100 +++ b/Simoleon/Helpers/CurrencyConversion.swift Thu Jul 15 20:24:13 2021 +0100 @@ -10,9 +10,10 @@ struct CurrencyConversion: View { var currency: String - @State private var price: Float = 1 + @State private var price: Double = 1.00 @State private var amountToConvert = "100" @State private var isEditing = false + @State private var showConversion = false let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") var body: some View { @@ -46,6 +47,8 @@ isEditing = false } } + .keyboardType(.decimalPad) + .lineLimit(1) .padding(.horizontal) Text("\(mainCurrency)") @@ -68,8 +71,14 @@ .clipShape(Circle()) .overlay(Circle().stroke(Color(.systemGray), lineWidth: 1)) - Text("\(makeConversion(), specifier: "%.2f")") - .padding(.horizontal) + if showConversion { + Text("\(makeConversion(), specifier: "%.4f")") + .lineLimit(1) + .padding(.horizontal) + } else { + ProgressView() + .padding(.horizontal) + } Spacer() Text("\(secondaryCurrency)") @@ -80,8 +89,10 @@ .frame(height: 50) .cornerRadius(13) - Text("From \(currencyMetadata[secondaryCurrency]!.name) to \(currencyMetadata[mainCurrency]!.name) at \(price, specifier: "%.2f") exchange rate.") - .multilineTextAlignment(.center) + if showConversion { + Text("From \(currencyMetadata[mainCurrency]!.name) to \(currencyMetadata[secondaryCurrency]!.name) at \(price, specifier: "%.4f") exchange rate.") + .multilineTextAlignment(.center) + } } .padding() @@ -90,11 +101,11 @@ .navigationTitle("Conversion") } - private func makeConversion() -> Float { + private func makeConversion() -> Double { if amountToConvert.isEmpty { /// Avoid nil error when string is empty return 0 } else { - let conversion = Float(amountToConvert)! * price + let conversion = Double(amountToConvert)! * price return conversion } @@ -103,8 +114,11 @@ private func requestApi(_ mainCurrency: String, _ secondaryCurrency: String) { let url = "https://api.simoleon.app/quotes=\(mainCurrency)-\(secondaryCurrency)" AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in - if let price = response.value![0].price { - self.price = price + if let currencyQuotes = response.value { + if let price = currencyQuotes[0].price { + self.price = price + } + self.showConversion = true } else { // Handle error }
--- a/Simoleon/Helpers/CurrencyRow.swift Thu Jul 15 19:03:24 2021 +0100 +++ b/Simoleon/Helpers/CurrencyRow.swift Thu Jul 15 20:24:13 2021 +0100 @@ -44,6 +44,7 @@ } .padding(.horizontal) } + .padding(.vertical, 7) } }
--- a/Simoleon/Models/CurrencyQuoteModel.swift Thu Jul 15 19:03:24 2021 +0100 +++ b/Simoleon/Models/CurrencyQuoteModel.swift Thu Jul 15 20:24:13 2021 +0100 @@ -9,9 +9,9 @@ struct CurrencyQuoteModel: Codable, Hashable { var symbol: String? - var price: Float? - var bid: Float? - var ask: Float? + var price: Double? + var bid: Double? + var ask: Double? var timeStamp: Int? private enum CodingKeys: String, CodingKey {