Mercurial > public > simoleon
changeset 15:a02f463aa906
Testing three column ipad navigation
line wrap: on
line diff
--- a/Simoleon.xcodeproj/project.pbxproj Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon.xcodeproj/project.pbxproj Thu Jul 15 10:58:29 2021 +0100 @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 954DB2EB269F43C80069F317 /* Sidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954DB2EA269F43C80069F317 /* Sidebar.swift */; }; 95559333269B0965000FD726 /* CurrencyQuoteModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95559332269B0965000FD726 /* CurrencyQuoteModel.swift */; }; 95559337269B0A7B000FD726 /* CurrencyQuoteData.json in Resources */ = {isa = PBXBuildFile; fileRef = 95559336269B0A7B000FD726 /* CurrencyQuoteData.json */; }; 9555933A269B0AB8000FD726 /* ParseJson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95559339269B0AB8000FD726 /* ParseJson.swift */; }; @@ -30,6 +31,10 @@ 95E76434269DF63D008E9F31 /* SearchedCurrencyList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95E76433269DF63D008E9F31 /* SearchedCurrencyList.swift */; }; 95E76436269DFC1A008E9F31 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95E76435269DFC1A008E9F31 /* LaunchScreen.storyboard */; }; 95E7643A269E0037008E9F31 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95E76439269E0037008E9F31 /* CloudKit.framework */; }; + 95EA4F4226A0346800AF89F6 /* SidebarNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95EA4F4126A0346800AF89F6 /* SidebarNavigation.swift */; }; + 95EA4F4426A034CC00AF89F6 /* PrimaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95EA4F4326A034CC00AF89F6 /* PrimaryView.swift */; }; + 95EA4F4626A034D800AF89F6 /* SupplementaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95EA4F4526A034D800AF89F6 /* SupplementaryView.swift */; }; + 95EA4F4826A034E000AF89F6 /* SecondaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95EA4F4726A034E000AF89F6 /* SecondaryView.swift */; }; 95FE659C269AFB54008745DE /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95FE659B269AFB54008745DE /* SearchBar.swift */; }; /* End PBXBuildFile section */ @@ -51,6 +56,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 954DB2EA269F43C80069F317 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; }; 95559332269B0965000FD726 /* CurrencyQuoteModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrencyQuoteModel.swift; sourceTree = "<group>"; }; 95559336269B0A7B000FD726 /* CurrencyQuoteData.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CurrencyQuoteData.json; sourceTree = "<group>"; }; 95559339269B0AB8000FD726 /* ParseJson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseJson.swift; sourceTree = "<group>"; }; @@ -80,6 +86,10 @@ 95E76435269DFC1A008E9F31 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; }; 95E76437269E0033008E9F31 /* Simoleon.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Simoleon.entitlements; sourceTree = "<group>"; }; 95E76439269E0037008E9F31 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; }; + 95EA4F4126A0346800AF89F6 /* SidebarNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SidebarNavigation.swift; sourceTree = "<group>"; }; + 95EA4F4326A034CC00AF89F6 /* PrimaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryView.swift; sourceTree = "<group>"; }; + 95EA4F4526A034D800AF89F6 /* SupplementaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupplementaryView.swift; sourceTree = "<group>"; }; + 95EA4F4726A034E000AF89F6 /* SecondaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondaryView.swift; sourceTree = "<group>"; }; 95FE659B269AFB54008745DE /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; }; /* End PBXFileReference section */ @@ -173,6 +183,7 @@ 95559331269B094A000FD726 /* Models */, 95559338269B0AAA000FD726 /* Functions */, 9555933B269B0DF9000FD726 /* Resources */, + 95EA4F4026A0343B00AF89F6 /* Pad */, 95C5B22D2697752700941585 /* Preview Content */, ); path = Simoleon; @@ -213,6 +224,17 @@ name = Frameworks; sourceTree = "<group>"; }; + 95EA4F4026A0343B00AF89F6 /* Pad */ = { + isa = PBXGroup; + children = ( + 95EA4F4126A0346800AF89F6 /* SidebarNavigation.swift */, + 95EA4F4326A034CC00AF89F6 /* PrimaryView.swift */, + 95EA4F4526A034D800AF89F6 /* SupplementaryView.swift */, + 95EA4F4726A034E000AF89F6 /* SecondaryView.swift */, + ); + path = Pad; + sourceTree = "<group>"; + }; 95FE659A269AFB44008745DE /* Helpers */ = { isa = PBXGroup; children = ( @@ -222,6 +244,7 @@ 956C28CB269B58A0005A4595 /* FlagPair.swift */, 95E137D0269C9F0D00D2C5DC /* SingleFlag.swift */, 956C28C9269B5893005A4595 /* CurrencyRow.swift */, + 954DB2EA269F43C80069F317 /* Sidebar.swift */, ); path = Helpers; sourceTree = "<group>"; @@ -366,6 +389,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 95EA4F4626A034D800AF89F6 /* SupplementaryView.swift in Sources */, 956C28CA269B5893005A4595 /* CurrencyRow.swift in Sources */, 956C28CC269B58A0005A4595 /* FlagPair.swift in Sources */, 9555933F269B0E47000FD726 /* CurrencyMetadataModel.swift in Sources */, @@ -376,8 +400,12 @@ 95FE659C269AFB54008745DE /* SearchBar.swift in Sources */, 95E137D1269C9F0D00D2C5DC /* SingleFlag.swift in Sources */, 95559333269B0965000FD726 /* CurrencyQuoteModel.swift in Sources */, + 95EA4F4826A034E000AF89F6 /* SecondaryView.swift in Sources */, 95C5B2282697752600941585 /* SimoleonApp.swift in Sources */, + 95EA4F4426A034CC00AF89F6 /* PrimaryView.swift in Sources */, + 95EA4F4226A0346800AF89F6 /* SidebarNavigation.swift in Sources */, 95C5B2342697752700941585 /* Simoleon.xcdatamodeld in Sources */, + 954DB2EB269F43C80069F317 /* Sidebar.swift in Sources */, 95E76434269DF63D008E9F31 /* SearchedCurrencyList.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -537,7 +565,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -550,7 +578,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.dennistech.Simoleon; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -561,7 +589,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -574,7 +602,7 @@ PRODUCT_BUNDLE_IDENTIFIER = io.dennistech.Simoleon; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = 1; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; };
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon/Assets.xcassets/AppIcon.appiconset/Contents.json Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/Assets.xcassets/AppIcon.appiconset/Contents.json Thu Jul 15 10:58:29 2021 +0100 @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "icon_20pt@2x.png", + "filename" : "icon_20pt@2x-1.png", "idiom" : "iphone", "scale" : "2x", "size" : "20x20" @@ -13,7 +13,7 @@ "size" : "20x20" }, { - "filename" : "icon_29pt@2x.png", + "filename" : "icon_29pt@2x-1.png", "idiom" : "iphone", "scale" : "2x", "size" : "29x29" @@ -25,7 +25,7 @@ "size" : "29x29" }, { - "filename" : "icon_40pt@2x.png", + "filename" : "icon_40pt@2x-1.png", "idiom" : "iphone", "scale" : "2x", "size" : "40x40" @@ -55,7 +55,7 @@ "size" : "20x20" }, { - "filename" : "icon_20pt@2x-1.png", + "filename" : "icon_20pt@2x.png", "idiom" : "ipad", "scale" : "2x", "size" : "20x20" @@ -67,7 +67,7 @@ "size" : "29x29" }, { - "filename" : "icon_29pt@2x-1.png", + "filename" : "icon_29pt@2x.png", "idiom" : "ipad", "scale" : "2x", "size" : "29x29" @@ -79,7 +79,7 @@ "size" : "40x40" }, { - "filename" : "icon_40pt@2x-1.png", + "filename" : "icon_40pt@2x.png", "idiom" : "ipad", "scale" : "2x", "size" : "40x40"
--- a/Simoleon/Assets.xcassets/LaunchLogo.imageset/Contents.json Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/Assets.xcassets/LaunchLogo.imageset/Contents.json Thu Jul 15 10:58:29 2021 +0100 @@ -2,46 +2,7 @@ "images" : [ { "filename" : "LaunchLogo.png", - "idiom" : "universal", - "scale" : "1x" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "scale" : "1x" - }, - { - "idiom" : "universal", - "scale" : "2x" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "scale" : "2x" - }, - { - "idiom" : "universal", - "scale" : "3x" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "scale" : "3x" + "idiom" : "universal" } ], "info" : {
--- a/Simoleon/ContentView.swift Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/ContentView.swift Thu Jul 15 10:58:29 2021 +0100 @@ -18,10 +18,10 @@ let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") var body: some View { - if showingView { - NavigationView { + NavigationView { + if showingView { ScrollView(showsIndicators: false) { - VStack(spacing: 30) { + VStack(spacing: 20) { SearchBar(text: $text, isEditing: $isEditing) .padding(.top) @@ -39,7 +39,7 @@ CurrencyConversion(currencyQuote: currencyQuote) } } - .navigationTitle("Simoleon") + .navigationTitle("Currencies") .toolbar { ToolbarItem(placement: .cancellationAction) { if isEditing { @@ -51,10 +51,10 @@ } } } + } else { + ProgressView() + .onAppear(perform: requestCurrencyPairsQuote) } - } else { - ProgressView() - .onAppear(perform: requestCurrencyPairsQuote) } } @@ -82,10 +82,10 @@ Dismiss keyboard on cancel textfield */ extension UIApplication { - func dismissKeyboard() { - sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) - } + func dismissKeyboard() { + sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } +} struct ContentView_Previews: PreviewProvider {
--- a/Simoleon/Helpers/CurrencyConversion.swift Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/Helpers/CurrencyConversion.swift Thu Jul 15 10:58:29 2021 +0100 @@ -18,60 +18,43 @@ ScrollView(showsIndicators: false) { VStack(spacing: 20) { let symbols = currencyQuote.symbol!.split(separator: "/") + // MARK: - First currency row - VStack { - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color("Shadow"), 65) - - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color(.systemBackground), 65) - .overlay( - HStack { - SingleFlag(flag: currenciesMetadata[String(symbols[0])]!.flag) - Text(String(symbols[0])) - .fontWeight(.semibold) - .padding(.leading) - - TextField("Amount", text: $inputAmount) - .keyboardType(.decimalPad) - .padding(.leading) - } - .padding(.horizontal) - ) - .offset(x: -6.0, y: -80.0) - .padding(.bottom, -80) - } - .padding(.leading, 6) - .padding(.horizontal) - + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 65) + .overlay( + HStack { + SingleFlag(flag: currenciesMetadata[String(symbols[0])]!.flag) + Text(String(symbols[0])) + .fontWeight(.semibold) + .padding(.leading) + + TextField("Amount", text: $inputAmount) + .keyboardType(.decimalPad) + .padding(.leading) + } + .padding(.horizontal) + ) + // MARK: - Second currency row - VStack { - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color("Shadow"), 65) - - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color(.systemBackground), 65) - .overlay( - HStack { - SingleFlag(flag: currenciesMetadata[String(symbols[1])]!.flag) - Text(String(symbols[1])) - .fontWeight(.semibold) - .padding(.leading) - - Text("\(makeConversion(inputAmount), specifier: "%.2f")") - .padding(.leading) - Spacer() - } - .padding(.horizontal) - ) - .offset(x: -6, y: -80) - .padding(.bottom, -80) - } - .padding(.leading, 6) - .padding(.horizontal) + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 65) + .overlay( + HStack { + SingleFlag(flag: currenciesMetadata[String(symbols[1])]!.flag) + Text(String(symbols[1])) + .fontWeight(.semibold) + .padding(.leading) + + Text("\(makeConversion(inputAmount), specifier: "%.2f")") + .padding(.leading) + Spacer() + } + .padding(.horizontal) + ) } - .padding(.vertical) + .padding() } .padding(.top) .navigationTitle("Conversion")
--- a/Simoleon/Helpers/CurrencyRow.swift Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/Helpers/CurrencyRow.swift Thu Jul 15 10:58:29 2021 +0100 @@ -12,58 +12,50 @@ let currenciesMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") var body: some View { - VStack(alignment: .leading) { - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color("Shadow"), 80) - - RoundedRectangle(cornerRadius: 10) - .rectangleModifier(Color(.systemBackground), 80) - .overlay( - HStack { - let symbols = currencyQuote.symbol!.split(separator: "/") - let mainCurrencyFlag = currenciesMetadata[String(symbols[0])]!.flag - let secondaryCurrencyFlag = currenciesMetadata[String(symbols[1])]!.flag - - FlagPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 80) + .overlay( + HStack { + let symbols = currencyQuote.symbol!.split(separator: "/") + let mainCurrencyFlag = currenciesMetadata[String(symbols[0])]!.flag + let secondaryCurrencyFlag = currenciesMetadata[String(symbols[1])]!.flag + + FlagPair(mainCurrencyFlag: mainCurrencyFlag, secondaryCurrencyFlag: secondaryCurrencyFlag) + + VStack(alignment: .leading) { + Text("\(String(symbols[0]))") + .fontWeight(.semibold) - VStack(alignment: .leading) { - Text("\(String(symbols[0]))") - .fontWeight(.semibold) - - Text("\(String(symbols[1]))") - .fontWeight(.semibold) - } - .padding(.horizontal) - - VStack(alignment: .leading) { - Text("Bid") - let bid = currencyQuote.bid! - Text("\(bid, specifier: createSpecifier(bid))") - .fontWeight(.semibold) - .lineLimit(1) - - } - .padding(.trailing) - - VStack(alignment: .leading) { - Text("Ask") - let ask = currencyQuote.ask! - Text("\(ask, specifier: createSpecifier(ask))") - .fontWeight(.semibold) - .lineLimit(1) - - } - - Spacer() - + Text("\(String(symbols[1]))") + .fontWeight(.semibold) } .padding(.horizontal) - ) - .offset(x: -6.0, y: -95.0) - .padding(.bottom, -95) - } - .padding(.leading, 6) - .padding(.horizontal) + + VStack(alignment: .leading) { + Text("Bid") + let bid = currencyQuote.bid! + Text("\(bid, specifier: createSpecifier(bid))") + .fontWeight(.semibold) + .lineLimit(1) + + } + .padding(.trailing) + + VStack(alignment: .leading) { + Text("Ask") + let ask = currencyQuote.ask! + Text("\(ask, specifier: createSpecifier(ask))") + .fontWeight(.semibold) + .lineLimit(1) + + } + + Spacer() + + } + .padding(.horizontal) + ) + .padding(.horizontal) } /*
--- a/Simoleon/Helpers/SearchedCurrencyList.swift Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/Helpers/SearchedCurrencyList.swift Thu Jul 15 10:58:29 2021 +0100 @@ -22,7 +22,6 @@ ForEach(searchedCurrencyPairsQuote, id: \.self) { currencyQuote in CurrencyRow(currencyQuote: currencyQuote) .onTapGesture { self.searchedSelectedCurrencyPairQuote = currencyQuote } - .padding(.bottom) } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Helpers/Sidebar.swift Thu Jul 15 10:58:29 2021 +0100 @@ -0,0 +1,27 @@ +// +// Sidebar.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 14/07/2021. +// + +import SwiftUI + +struct Sidebar: View { + @Binding var selectedView: String? + + var body: some View { + List { + NavigationLink(destination: ContentView(), tag: "Currencies", selection: $selectedView) { + Text("Currencies") + } + } + .listStyle(SidebarListStyle()) + } +} + +struct Sidebar_Previews: PreviewProvider { + static var previews: some View { + Sidebar(selectedView: .constant("")) + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Pad/PrimaryView.swift Thu Jul 15 10:58:29 2021 +0100 @@ -0,0 +1,28 @@ +// +// PrimaryView.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 15/07/2021. +// + +import SwiftUI + +struct PrimaryView: View { + @State var popularCurrencyPairsQuote: [CurrencyQuoteModel] + + var body: some View { + List { + NavigationLink(destination: SupplementaryView(popularCurrencyPairsQuote: $popularCurrencyPairsQuote)) { + Text("Currencies") + } + } + .listStyle(SidebarListStyle()) + .navigationBarTitle("Categories") + } +} + +struct PrimaryView_Previews: PreviewProvider { + static var previews: some View { + PrimaryView(popularCurrencyPairsQuote: [CurrencyQuoteModel()]) + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Pad/SecondaryView.swift Thu Jul 15 10:58:29 2021 +0100 @@ -0,0 +1,81 @@ +// +// SecondaryView.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 15/07/2021. +// + +import SwiftUI + +struct SecondaryView: View { + var currencyQuote: CurrencyQuoteModel + let currenciesMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") + @State private var inputAmount: String = "100" + + var body: some View { + if let symbol = currencyQuote.symbol { + ScrollView(showsIndicators: false) { + VStack(spacing: 20) { + let symbols = symbol.split(separator: "/") + + // MARK: - First currency row + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 65) + .overlay( + HStack { + SingleFlag(flag: currenciesMetadata[String(symbols[0])]!.flag) + Text(String(symbols[0])) + .fontWeight(.semibold) + .padding(.leading) + + TextField("Amount", text: $inputAmount) + .keyboardType(.decimalPad) + .padding(.leading) + } + .padding(.horizontal) + ) + + // MARK: - Second currency row + RoundedRectangle(cornerRadius: 10) + .rectangleModifier(Color(.systemBackground), 65) + .overlay( + HStack { + SingleFlag(flag: currenciesMetadata[String(symbols[1])]!.flag) + Text(String(symbols[1])) + .fontWeight(.semibold) + .padding(.leading) + + Text("\(makeConversion(inputAmount), specifier: "%.2f")") + .padding(.leading) + Spacer() + } + .padding(.horizontal) + ) + + } + .padding() + } + .padding(.top) + .navigationTitle("Conversion") + } + } + + /* + Make currency conversion + */ + private func makeConversion(_ inputAmount: String) -> Float { + if inputAmount.isEmpty { /// Avoid nil error when string is empty + return 0 + } else { + let conversion = Float(inputAmount)! * currencyQuote.price! + + return conversion + } + } +} + +struct SecondaryView_Previews: PreviewProvider { + static var previews: some View { + SecondaryView(currencyQuote: CurrencyQuoteModel()) + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Pad/SidebarNavigation.swift Thu Jul 15 10:58:29 2021 +0100 @@ -0,0 +1,26 @@ +// +// SidebarNavigation.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 15/07/2021. +// + +import SwiftUI + +struct SidebarNavigation: View { + @State var popularCurrencyPairsQuote = [CurrencyQuoteModel()] + + var body: some View { + NavigationView { + PrimaryView(popularCurrencyPairsQuote: popularCurrencyPairsQuote) + SupplementaryView(popularCurrencyPairsQuote: $popularCurrencyPairsQuote) + SecondaryView(currencyQuote: popularCurrencyPairsQuote[0]) + } + } +} + +struct SidebarNavigation_Previews: PreviewProvider { + static var previews: some View { + SidebarNavigation() + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Pad/SupplementaryView.swift Thu Jul 15 10:58:29 2021 +0100 @@ -0,0 +1,84 @@ +// +// SupplementaryView.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 15/07/2021. +// + +import SwiftUI +import Alamofire + +struct SupplementaryView: View { + @Binding var popularCurrencyPairsQuote: [CurrencyQuoteModel] + + @State private var showingView = false + @State private var text = "" + @State private var isEditing = false + + let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") + + var body: some View { + if showingView { + ScrollView(showsIndicators: false) { + VStack(spacing: 20) { + SearchBar(text: $text, isEditing: $isEditing) + .padding(.top) + + if text.isEmpty { + ForEach(popularCurrencyPairsQuote, id: \.self) { currencyQuote in + NavigationLink(destination: SecondaryView(currencyQuote: currencyQuote)) { + CurrencyRow(currencyQuote: currencyQuote) + } + .buttonStyle(PlainButtonStyle()) + } + } else { + SearchedCurrencyList(text: $text) + } + } + .padding(.vertical) + } + .navigationTitle("Currencies") + .toolbar { + ToolbarItem(placement: .cancellationAction) { + if isEditing { + Button("Cancel", action: { + text = "" + isEditing = false + UIApplication.shared.dismissKeyboard() + }) + } + } + } + } else { + ProgressView() + .onAppear(perform: requestCurrencyPairsQuote) + } + } + + /* + Request API + */ + private func requestCurrencyPairsQuote() { + let popularCurrencyPairsArray: [String] = parseJson("PopularCurrencyPairs.json") + let popularCurrencyPairsString = popularCurrencyPairsArray.joined(separator: ",") + let quotes = popularCurrencyPairsString.replacingOccurrences(of: "/", with: "-") + let url = "https://api.simoleon.app/quotes=\(quotes)" + + // Request popular currencies + AF.request(url).responseDecodable(of: [CurrencyQuoteModel].self) { response in + if let currencyPairsQuote = response.value { + self.popularCurrencyPairsQuote = currencyPairsQuote + self.showingView = true + } else { + // Handle error + } + } + } +} + + +struct SupplementaryView_Previews: PreviewProvider { + static var previews: some View { + SupplementaryView(popularCurrencyPairsQuote: .constant([CurrencyQuoteModel()])) + } +}
--- a/Simoleon/SimoleonApp.swift Wed Jul 14 10:06:37 2021 +0100 +++ b/Simoleon/SimoleonApp.swift Thu Jul 15 10:58:29 2021 +0100 @@ -13,8 +13,12 @@ var body: some Scene { WindowGroup { - ContentView() - .environment(\.managedObjectContext, persistenceController.container.viewContext) + if UIDevice.current.userInterfaceIdiom == .pad { + SidebarNavigation() + } else { + ContentView() + .environment(\.managedObjectContext, persistenceController.container.viewContext) + } } } }