Mercurial > public > simoleon
changeset 60:7b98dd60381c
Added search bar to default currency picker
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Tue, 27 Jul 2021 18:45:20 +0100 |
parents | 1303c1e50843 |
children | 84ce5e5f0381 |
files | Simoleon/Helpers/SearchBar.swift Simoleon/Settings.swift |
diffstat | 2 files changed, 59 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Simoleon/Helpers/SearchBar.swift Tue Jul 27 18:45:20 2021 +0100 @@ -0,0 +1,29 @@ +// +// SearchBar.swift +// Simoleon +// +// Created by Dennis Concepción Martín on 27/07/2021. +// + +import SwiftUI + +struct SearchBar: View { + var placeholder: LocalizedStringKey + @Binding var text: String + + var body: some View { + TextField(placeholder, text: $text) + .disableAutocorrection(true) + .padding(10) + .background( + RoundedRectangle(cornerRadius: 15) + .foregroundColor(Color(.systemGray6)) + ) + } +} + +struct SearchBar_Previews: PreviewProvider { + static var previews: some View { + SearchBar(placeholder: "Search ...", text: .constant("")) + } +}
--- a/Simoleon/Settings.swift Tue Jul 27 18:31:54 2021 +0100 +++ b/Simoleon/Settings.swift Tue Jul 27 18:45:20 2021 +0100 @@ -18,18 +18,22 @@ @State private var alertTitle = "" @State private var alertMessage = "" @State private var showingAlert = false + @State private var searchCurrency = "" let currencyPairs: [String] = parseJson("CurrencyPairs.json") var body: some View { List { - Section(header: Text("Preferences", comment: "Section header in settings")) { + Section(header: Text("Preferences")) { if entitlementIsActive { - Picker(selection: $selectedDefaultCurrency, label: Text("Default currency", comment: "Picker to select default currency"), content: { - ForEach(currencyPairs.sorted(), id: \.self) { currencyPair in + Picker("Default currency", selection: $selectedDefaultCurrency) { + SearchBar(placeholder: "Search...", text: $searchCurrency) + .padding(5) + + ForEach(searchResults, id: \.self) { currencyPair in Text(currencyPair) } - }) + } } else { LockedCurrencyPicker() .contentShape(Rectangle()) @@ -37,14 +41,14 @@ } } - Section(header: Text("Stay in touch", comment: "Section header in settings")) { + Section(header: Text("Stay in touch")) { Link(destination: URL(string: "https://itunes.apple.com/app/id1576390953?action=write-review")!) { HStack { Image(systemName: "heart.fill") .foregroundColor(Color(.systemRed)) .imageScale(.large) - Text("Rate Simoleon", comment: "Button to rate app in Settings") + Text("Rate Simoleon") } } @@ -54,7 +58,7 @@ .resizable() .frame(width: 30, height: 30) - Text("Developer's Twitter", comment: "Button to go to Twitter in Settings") + Text("Developer's Twitter") } } @@ -64,22 +68,22 @@ .renderingMode(.original) .imageScale(.large) - Text("Contact", comment: "Button to contact in Settings") + Text("Contact") } } } Section(header: Text("About")) { Link(destination: URL(string: "https://dennistech.io")!) { - Text("Website", comment: "Button to go to Dennis Tech website") + Text("Website") } Link(destination: URL(string: "https://dennistech.io/privacy-policy")!) { - Text("Privacy Policy", comment: "Button to go to app privacy policy") + Text("Privacy Policy") } Link(destination: URL(string: "https://dennistech.io/terms-of-use")!) { - Text("Terms of Use", comment: "Button to go to app terms of use") + Text("Terms of Use") } } } @@ -103,7 +107,7 @@ } } .listStyle(InsetGroupedListStyle()) - .navigationTitle(Text("Settings", comment: "Navigation title")) + .navigationTitle("Settings") .sheet(isPresented: $showingSubscriptionPaywall, onDismiss: checkEntitlement) { SubscriptionPaywall(showingSubscriptionPaywall: $showingSubscriptionPaywall) } @@ -112,6 +116,20 @@ } } + /* + If searched currency string is empty: + * Show all currencies + else: + * Show filtered list of currencies containing searched currency string + */ + var searchResults: [String] { + if searchCurrency.isEmpty { + return currencyPairs.sorted() + } else { + return currencyPairs.filter { $0.contains(searchCurrency.uppercased()) } + } + } + // Save default currency to core data private func setCoreData() { @@ -140,10 +158,8 @@ Purchases.shared.purchaserInfo { (purchaserInfo, error) in if purchaserInfo?.entitlements["all"]?.isActive == true { entitlementIsActive = true - print("Entitlement is active") } else { entitlementIsActive = false - print("Entitlement is NOT active") } if let error = error as NSError? {