diff --git a/ProductosPY.xcodeproj/project.pbxproj b/ProductosPY.xcodeproj/project.pbxproj index fb890cd..de88c0f 100644 --- a/ProductosPY.xcodeproj/project.pbxproj +++ b/ProductosPY.xcodeproj/project.pbxproj @@ -26,6 +26,8 @@ BB8DBE3824738BC6006891EF /* FavToVendorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8DBE3724738BC6006891EF /* FavToVendorViewController.swift */; }; BB8DBE3A2473B1E7006891EF /* DistanceVendorsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8DBE392473B1E7006891EF /* DistanceVendorsCell.swift */; }; BB8DBE3C2473BAFD006891EF /* FeatureWithDistance.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8DBE3B2473BAFD006891EF /* FeatureWithDistance.swift */; }; + BB8DBE3E2474B4FB006891EF /* FilterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8DBE3D2474B4FB006891EF /* FilterViewController.swift */; }; + BB8DBE402474B960006891EF /* FilterCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8DBE3F2474B960006891EF /* FilterCell.swift */; }; BBDA25AB2463193100819183 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDA25AA2463193100819183 /* AppDelegate.swift */; }; BBDA25AD2463193100819183 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDA25AC2463193100819183 /* SceneDelegate.swift */; }; BBDA25AF2463193100819183 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BBDA25AE2463193100819183 /* ViewController.swift */; }; @@ -55,6 +57,8 @@ BB8DBE3724738BC6006891EF /* FavToVendorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavToVendorViewController.swift; sourceTree = ""; }; BB8DBE392473B1E7006891EF /* DistanceVendorsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DistanceVendorsCell.swift; sourceTree = ""; }; BB8DBE3B2473BAFD006891EF /* FeatureWithDistance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureWithDistance.swift; sourceTree = ""; }; + BB8DBE3D2474B4FB006891EF /* FilterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterViewController.swift; sourceTree = ""; }; + BB8DBE3F2474B960006891EF /* FilterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCell.swift; sourceTree = ""; }; BBDA25A72463193100819183 /* ProductosPY.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ProductosPY.app; sourceTree = BUILT_PRODUCTS_DIR; }; BBDA25AA2463193100819183 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; BBDA25AC2463193100819183 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -110,6 +114,7 @@ BB5A720A246CBC0600B51D4E /* CustomMarkerView.swift */, BB5A727524734FB600B51D4E /* FavoriteCell.swift */, BB8DBE392473B1E7006891EF /* DistanceVendorsCell.swift */, + BB8DBE3F2474B960006891EF /* FilterCell.swift */, ); path = entities; sourceTree = ""; @@ -133,6 +138,7 @@ BB5A72392471336A00B51D4E /* screenThreInfomationViewController.swift */, BB5A727324734E7800B51D4E /* ScreenFiveFavoritesViewController.swift */, BB8DBE3724738BC6006891EF /* FavToVendorViewController.swift */, + BB8DBE3D2474B4FB006891EF /* FilterViewController.swift */, ); path = ViewControllers; sourceTree = ""; @@ -327,6 +333,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + BB8DBE3E2474B4FB006891EF /* FilterViewController.swift in Sources */, BB5A71FB2465A5EC00B51D4E /* Constants.swift in Sources */, BB8DBE3824738BC6006891EF /* FavToVendorViewController.swift in Sources */, BBDA25AF2463193100819183 /* ViewController.swift in Sources */, @@ -339,6 +346,7 @@ BB5A7201246610BE00B51D4E /* HTTPClient.swift in Sources */, BB5A71FE2465C7D800B51D4E /* ScreenTwoViewController.swift in Sources */, BB8DBE3C2473BAFD006891EF /* FeatureWithDistance.swift in Sources */, + BB8DBE402474B960006891EF /* FilterCell.swift in Sources */, BB5A72032466114400B51D4E /* APIError.swift in Sources */, BBDA25AB2463193100819183 /* AppDelegate.swift in Sources */, BB5A723A2471336A00B51D4E /* screenThreInfomationViewController.swift in Sources */, diff --git a/ProductosPY/Base.lproj/Main.storyboard b/ProductosPY/Base.lproj/Main.storyboard index c495a13..f3ecd1d 100644 --- a/ProductosPY/Base.lproj/Main.storyboard +++ b/ProductosPY/Base.lproj/Main.storyboard @@ -159,7 +159,66 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -295,11 +354,21 @@ + + + @@ -318,12 +387,14 @@ + + @@ -471,7 +542,7 @@ - + @@ -623,7 +694,7 @@ - + @@ -769,7 +840,7 @@ - + diff --git a/ProductosPY/ViewControllers/FilterViewController.swift b/ProductosPY/ViewControllers/FilterViewController.swift new file mode 100644 index 0000000..f8d2eba --- /dev/null +++ b/ProductosPY/ViewControllers/FilterViewController.swift @@ -0,0 +1,59 @@ +// +// FilterViewController.swift +// ProductosPY +// +// Created by Mobile Roshka on 5/19/20. +// Copyright © 2020 Mobile Roshka. All rights reserved. +// + +import UIKit + +protocol CanRecive { + func passDataBack(data: String, nombre:String) +} + +class FilterViewController: UIViewController { + + @IBOutlet weak var tableView: UITableView! + var delegate:CanRecive? + + var arrayFiltro = ["todos", "agua" , "gel_alcohol", "alcohol_rectificado", "canasta_basica", "cocido_quemado", "comida", "costurera", "frutas", "guantes", "hipoclorito_sodio", "jabon_coco", "negocio", "papel", "ropa", "servicios", "tapabocas", "toalla", "verduras"] + var arrayFiltroName = ["Todos los productos", "Agua", "Alcohol en gel", "Alcohol rectificado", "Canasta básica", "Cocido quemado", "Comida dulce o salada", "Costurero/a", "Frutas", "Guantes", "Hipoclorito de sodio", "Jabón de coco", "Negocio (Ferretería, farmacia, despensa, etc)", "Papel", "Ropa, vestimenta", "Servicios", "Tapabocas", "Toalla", "Verduras"] + var producto = "" + override func viewDidLoad() { + super.viewDidLoad() + + tableView.dataSource = self + tableView.delegate = self + } + + +} + +extension FilterViewController: UITableViewDelegate, UITableViewDataSource { + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return arrayFiltro.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let myFilterCell = tableView.dequeueReusableCell(withIdentifier: "FilterCell", for: indexPath) as! FilterCell + myFilterCell.nombreLabel.text = arrayFiltroName[indexPath.row] + + return myFilterCell + } + + func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + return 80.0 + } + + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + producto = arrayFiltro[indexPath.row] + let nombre = arrayFiltroName[indexPath.row] + delegate?.passDataBack(data: producto, nombre: nombre) + dismiss(animated: true, completion: nil) + + } + + +} diff --git a/ProductosPY/ViewControllers/ScreenTwoViewController.swift b/ProductosPY/ViewControllers/ScreenTwoViewController.swift index 1b0ce07..26e3b21 100644 --- a/ProductosPY/ViewControllers/ScreenTwoViewController.swift +++ b/ProductosPY/ViewControllers/ScreenTwoViewController.swift @@ -18,16 +18,17 @@ class ScreenTwoViewController: UIViewController { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var mapView: GMSMapView! + @IBOutlet weak var filtroButton: UIButton! var locationManager: CLLocationManager! var currentLocation: CLLocation? var currentCoordinates:String = "" //var placesClient: GMSPlacesClient! - var zoomLevel: Float = 15.0 + var zoomLevel: Float = 10 var featureCollection = FeatureCollection(type: "Type", features: []) var featureWithDistance = [FeatureWithDistance]() - + var tipoProducto:String = "" override func viewWillAppear(_ animated: Bool) { locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest @@ -38,7 +39,8 @@ class ScreenTwoViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - + + filtroButton.setTitleColor(Constants.fontColorFilter, for: .normal) initMapView() tableView.delegate = self tableView.dataSource = self @@ -57,6 +59,7 @@ class ScreenTwoViewController: UIViewController { mapView.isMyLocationEnabled = true mapView.isHidden = true mapView.bringSubviewToFront(tableView) + mapView.bringSubviewToFront(filtroButton) //tableView.isHidden = false mapView.delegate = self } @@ -122,6 +125,11 @@ class ScreenTwoViewController: UIViewController { @IBAction func favoritesAction(_ sender: Any) { performSegue(withIdentifier: "screenFiveFavoritesSigue", sender: nil) } + + + @IBAction func filtroAction(_ sender: Any) { + performSegue(withIdentifier: "filterSegue", sender: nil) + } } // Delegates to handle events for the location manager. @@ -186,6 +194,9 @@ extension ScreenTwoViewController: GMSMapViewDelegate { } else if id == "screenFiveFavoritesSigue" { let screenFiveFavorites = segue.destination as! ScreenFiveFavoritesViewController screenFiveFavorites.currentCoordinates = currentCoordinates + } else if id == "filterSegue" { + let filterVC = segue.destination as! FilterViewController + filterVC.delegate = self } } } @@ -203,6 +214,7 @@ extension ScreenTwoViewController: GMSMapViewDelegate { } } +// Tabla del buscador extension ScreenTwoViewController: UITableViewDataSource, UITableViewDelegate { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return featureWithDistance.count @@ -244,6 +256,7 @@ extension ScreenTwoViewController: UITableViewDataSource, UITableViewDelegate { } } +// Buscador extension ScreenTwoViewController: UISearchBarDelegate { func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { if searchText.isEmpty == false { @@ -251,11 +264,15 @@ extension ScreenTwoViewController: UISearchBarDelegate { tableView.isHidden = false tableView.reloadData() } else { - //aparte + let textButton = filtroButton.titleLabel?.text searchBar.endEditing(true) searchBarView.endEditing(true) tableView.isHidden = true - getData() + if (textButton?.uppercased().contains("todos"))! { + addFeatureCollectionInTheMap() + } else { + addFeatureCollectionFilterInTheMap(tipo: tipoProducto, nombre: textButton!) + } tableView.reloadData() } } @@ -283,3 +300,62 @@ extension ScreenTwoViewController: UISearchBarDelegate { searchBarView.endEditing(true) } } + +// Filtro +extension ScreenTwoViewController: CanRecive { + func passDataBack(data: String, nombre:String) { + print(data) + self.filtroButton.setTitle(nombre, for: .normal) + self.tipoProducto = data + self.mapView.clear() + if data == "todos" { + addFeatureCollectionInTheMap() + } else { + addFeatureCollectionFilterInTheMap(tipo: data, nombre: nombre) + } + + } + + func addFeatureCollectionFilterInTheMap(tipo: String, nombre:String) { + mapView.clear() + featureWithDistance = [] + var position = CLLocationCoordinate2D() + var c = 0 + let icon = UIImage(named: "markerNormal") + for feature in featureCollection.features { + var productoType = [String]() + // Pequenho artificio para poder sacar una lista de producto que tiene el vendedor + for p in feature.properties.productos { + productoType.append(p.productType.rawValue) + } + let marker = GMSMarker() + if let latitude = feature.geometry.coordinates[1] { + position.latitude = latitude + } else { + position.latitude = 0.0 + } + if let longitude = feature.geometry.coordinates[0] { + position.longitude = longitude + } else { + position.latitude = 0.0 + } + if !position.longitude.isZero && !position.latitude.isZero { + // Aca se filtra los producto segun el tipo que vino del trableviewAnterior + if productoType.contains(tipo) { + print("Si tiene") + let finalLocation = CLLocation(latitude: position.latitude, longitude: position.longitude) + let distance = currentLocation?.distance(from: finalLocation) + let km = distance!/1000 + marker.position = position + marker.title = String(c) + marker.icon = icon + marker.map = mapView + featureWithDistance.append(FeatureWithDistance(feature: feature, distance: Double(round(100*(km))/100), id: String(c))) + } + } + c += 1 + + } + print(c) + } +} diff --git a/ProductosPY/entities/FilterCell.swift b/ProductosPY/entities/FilterCell.swift new file mode 100644 index 0000000..c72914f --- /dev/null +++ b/ProductosPY/entities/FilterCell.swift @@ -0,0 +1,14 @@ +// +// FilterCell.swift +// ProductosPY +// +// Created by Mobile Roshka on 5/19/20. +// Copyright © 2020 Mobile Roshka. All rights reserved. +// + +import Foundation +import UIKit +class FilterCell: UITableViewCell { + + @IBOutlet weak var nombreLabel: UILabel! +} diff --git a/ProductosPY/structs/Constants.swift b/ProductosPY/structs/Constants.swift index be5e510..1daaec9 100644 --- a/ProductosPY/structs/Constants.swift +++ b/ProductosPY/structs/Constants.swift @@ -16,4 +16,5 @@ struct Constants { static let pointPageColor = UIColor(red: 0.85, green: 0.85, blue: 0.85, alpha: 1.00) static let fontTitleColorVendor = UIColor(red: 0.00, green: 0.24, blue: 0.67, alpha: 1.00) static let fontSubTextColor = UIColor(red: 0.71, green: 0.71, blue: 0.71, alpha: 1.00) + static let fontColorFilter = UIColor(red: 0.08, green: 0.12, blue: 0.86, alpha: 1.00) }