# HG changeset patch # User Dennis Concepción Martín # Date 1626108295 -3600 # Node ID ed35ef4738b91e93ceae2472a818cd0a9de01fe4 # Parent 7e6d9c74ca8177a1cb4b6d0bc28631440a9c505c Implementing currency conversion and search diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon.xcodeproj/project.pbxproj --- a/Simoleon.xcodeproj/project.pbxproj Mon Jul 12 10:54:46 2021 +0100 +++ b/Simoleon.xcodeproj/project.pbxproj Mon Jul 12 17:44:55 2021 +0100 @@ -26,6 +26,9 @@ 95C5B23F2697752700941585 /* SimoleonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C5B23E2697752700941585 /* SimoleonTests.swift */; }; 95C5B24A2697752700941585 /* SimoleonUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95C5B2492697752700941585 /* SimoleonUITests.swift */; }; 95DD4ABB269B33810027CA1F /* CurrencyPairs.json in Resources */ = {isa = PBXBuildFile; fileRef = 95DD4ABA269B33810027CA1F /* CurrencyPairs.json */; }; + 95E137CD269C9A0600D2C5DC /* SearchCurrencyRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */; }; + 95E137CF269C9D8B00D2C5DC /* CurrencyConversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */; }; + 95E137D1269C9F0D00D2C5DC /* SingleFlag.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */; }; 95FE659C269AFB54008745DE /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FE659B269AFB54008745DE /* SearchBar.swift */; }; /* End PBXBuildFile section */ @@ -71,6 +74,9 @@ 95C5B2492697752700941585 /* SimoleonUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimoleonUITests.swift; sourceTree = ""; }; 95C5B24B2697752700941585 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 95DD4ABA269B33810027CA1F /* CurrencyPairs.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CurrencyPairs.json; sourceTree = ""; }; + 95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchCurrencyRow.swift; sourceTree = ""; }; + 95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyConversion.swift; sourceTree = ""; }; + 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleFlag.swift; sourceTree = ""; }; 95FE659B269AFB54008745DE /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -100,13 +106,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 951E3F332698C9F400DAD692 /* Tests */ = { - isa = PBXGroup; - children = ( - ); - path = Tests; - sourceTree = ""; - }; 95559331269B094A000FD726 /* Models */ = { isa = PBXGroup; children = ( @@ -166,7 +165,6 @@ 95559331269B094A000FD726 /* Models */, 95559338269B0AAA000FD726 /* Functions */, 9555933B269B0DF9000FD726 /* Resources */, - 951E3F332698C9F400DAD692 /* Tests */, 95C5B22D2697752700941585 /* Preview Content */, ); path = Simoleon; @@ -205,8 +203,11 @@ 95FE659B269AFB54008745DE /* SearchBar.swift */, 9555932B269B0390000FD726 /* BigFlagsPair.swift */, 956C28CB269B58A0005A4595 /* SmallFlagsPair.swift */, + 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */, 9555932F269B08CE000FD726 /* MainCurrencyRow.swift */, 956C28C9269B5893005A4595 /* CurrencyRow.swift */, + 95E137CC269C9A0600D2C5DC /* SearchCurrencyRow.swift */, + 95E137CE269C9D8B00D2C5DC /* CurrencyConversion.swift */, ); path = Helpers; sourceTree = ""; @@ -355,9 +356,12 @@ 95559330269B08CE000FD726 /* MainCurrencyRow.swift in Sources */, 95C5B2312697752700941585 /* Persistence.swift in Sources */, 9555933A269B0AB8000FD726 /* ParseJson.swift in Sources */, + 95E137CD269C9A0600D2C5DC /* SearchCurrencyRow.swift in Sources */, 9555932C269B0390000FD726 /* BigFlagsPair.swift in Sources */, + 95E137CF269C9D8B00D2C5DC /* CurrencyConversion.swift in Sources */, 95C5B22A2697752600941585 /* ContentView.swift in Sources */, 95FE659C269AFB54008745DE /* SearchBar.swift in Sources */, + 95E137D1269C9F0D00D2C5DC /* SingleFlag.swift in Sources */, 95559333269B0965000FD726 /* CurrencyQuoteModel.swift in Sources */, 95C5B2282697752600941585 /* SimoleonApp.swift in Sources */, 95C5B2342697752700941585 /* Simoleon.xcdatamodeld in Sources */, diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon/Helpers/CurrencyConversion.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Helpers/CurrencyConversion.swift Mon Jul 12 17:44:55 2021 +0100 @@ -0,0 +1,79 @@ +// +// CurrencyConversion.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 12/07/2021. +// + +import SwiftUI + +struct CurrencyConversion: View { + var currencyQuote: CurrencyQuoteModel + let currencies: [String: CurrencyModel] = parseJson("Currencies.json") + @State private var inputAmount: Float = 100 + + var body: some View { + VStack { + let symbols = currencyQuote.symbol.split(separator: "/") + // MARK: - First currency row + VStack { + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color("Bone"), 80) + + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 80) + .overlay( + HStack { + SingleFlag(flag: currencies[String(symbols[0])]!.flag) + Text(String(symbols[0])) + .fontWeight(.semibold) + .padding(.leading) + + TextField("Amount", value: $inputAmount, formatter: NumberFormatter()) + .padding(.leading) + } + .padding(.horizontal) + ) + .offset(x: -10.0, y: -100.0) + .padding(.bottom, -100) + } + .padding(.leading, 10) + .padding([.horizontal, .bottom]) + + // MARK: - Second currency row + VStack { + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color("Bone"), 80) + + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 80) + .overlay( + HStack { + SingleFlag(flag: currencies[String(symbols[1])]!.flag) + Text(String(symbols[1])) + .fontWeight(.semibold) + .padding(.leading) + + let conversion = inputAmount * currencyQuote.price + Text("\(conversion, specifier: "%.2f")") + .padding(.leading) + Spacer() + } + .padding(.horizontal) + ) + .offset(x: -10.0, y: -100.0) + .padding(.bottom, -100) + } + .padding(.leading, 10) + .padding(.horizontal) + } + } +} + +struct CurrencyConversion_Previews: PreviewProvider { + static var previews: some View { + let currencyQuote: CurrencyQuoteModel = parseJson("CurrencyQuoteData.json") + + CurrencyConversion(currencyQuote: currencyQuote) + } +} diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon/Helpers/CurrencyRow.swift --- a/Simoleon/Helpers/CurrencyRow.swift Mon Jul 12 10:54:46 2021 +0100 +++ b/Simoleon/Helpers/CurrencyRow.swift Mon Jul 12 17:44:55 2021 +0100 @@ -22,9 +22,9 @@ HStack { let symbols = currencyQuote.symbol.split(separator: "/") let mainCurrencyFlag = currencies[String(symbols[0])]!.flag - let SecondaryCurrencyFlag = currencies[String(symbols[1])]!.flag + let secondaryCurrencyFlag = currencies[String(symbols[1])]!.flag - SmallFlagsPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: SecondaryCurrencyFlag) + SmallFlagsPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) VStack(alignment: .leading) { Text("\(String(symbols[0]))") diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon/Helpers/SearchCurrencyRow.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Helpers/SearchCurrencyRow.swift Mon Jul 12 17:44:55 2021 +0100 @@ -0,0 +1,59 @@ +// +// SearchCurrencyRow.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 12/07/2021. +// + +import SwiftUI + +struct SearchCurrencyRow: View { + var currencyPair: String + let currencies: [String: CurrencyModel] = parseJson("Currencies.json") + + var body: some View { + VStack { + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color("Bone"), 100) + + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 100) + .overlay( + HStack { + let symbols = currencyPair.split(separator: "/") + let mainCurrencyFlag = currencies[String(symbols[0])]!.flag + let secondaryCurrencyFlag = currencies[String(symbols[1])]!.flag + + SmallFlagsPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) + + VStack(alignment: .leading) { + Text("\(currencyPair)") + .fontWeight(.semibold) + + Group { + Text("\(currencies[String(symbols[0])]!.name)") + Text("\(currencies[String(symbols[1])]!.name)") + } + .font(.callout) + .opacity(0.7) + .lineLimit(1) + } + .padding(.horizontal) + + Spacer() + } + .padding(.horizontal) + ) + .offset(x: -10.0, y: -120.0) + .padding(.bottom, -120) + } + .padding(.leading, 10) + .padding(.horizontal) + } +} + +struct SearchCurrencyRow_Previews: PreviewProvider { + static var previews: some View { + SearchCurrencyRow(currencyPair: "USD/GBP") + } +} diff -r 7e6d9c74ca81 -r ed35ef4738b9 Simoleon/Helpers/SingleFlag.swift --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Helpers/SingleFlag.swift Mon Jul 12 17:44:55 2021 +0100 @@ -0,0 +1,23 @@ +// +// SingleFlag.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 12/07/2021. +// + +import SwiftUI + +struct SingleFlag: View { + var flag: String + + var body: some View { + Image(flag) + .flagModifier(50) + } +} + +struct SingleFlag_Previews: PreviewProvider { + static var previews: some View { + SingleFlag(flag: "EU") + } +}