Commit 1f9a77bf by Mobile Roshka

Se agrega el boton de filtro

parent af0eae13
......@@ -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 = "<group>"; };
BB8DBE392473B1E7006891EF /* DistanceVendorsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DistanceVendorsCell.swift; sourceTree = "<group>"; };
BB8DBE3B2473BAFD006891EF /* FeatureWithDistance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeatureWithDistance.swift; sourceTree = "<group>"; };
BB8DBE3D2474B4FB006891EF /* FilterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterViewController.swift; sourceTree = "<group>"; };
BB8DBE3F2474B960006891EF /* FilterCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilterCell.swift; sourceTree = "<group>"; };
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 = "<group>"; };
BBDA25AC2463193100819183 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
......@@ -110,6 +114,7 @@
BB5A720A246CBC0600B51D4E /* CustomMarkerView.swift */,
BB5A727524734FB600B51D4E /* FavoriteCell.swift */,
BB8DBE392473B1E7006891EF /* DistanceVendorsCell.swift */,
BB8DBE3F2474B960006891EF /* FilterCell.swift */,
);
path = entities;
sourceTree = "<group>";
......@@ -133,6 +138,7 @@
BB5A72392471336A00B51D4E /* screenThreInfomationViewController.swift */,
BB5A727324734E7800B51D4E /* ScreenFiveFavoritesViewController.swift */,
BB8DBE3724738BC6006891EF /* FavToVendorViewController.swift */,
BB8DBE3D2474B4FB006891EF /* FilterViewController.swift */,
);
path = ViewControllers;
sourceTree = "<group>";
......@@ -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 */,
......
......@@ -159,7 +159,66 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="luY-mx-qsR" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2684" y="-486"/>
<point key="canvasLocation" x="2746" y="-518"/>
</scene>
<!--Filter View Controller-->
<scene sceneID="2Hw-iZ-rQt">
<objects>
<viewController id="t9S-AL-NWS" customClass="FilterViewController" customModule="ProductosPY" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="odZ-Ho-I5z">
<rect key="frame" x="0.0" y="0.0" width="414" height="842"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="lwr-bN-YFd">
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="FilterCell" rowHeight="98" id="gx9-df-Xcj" customClass="FilterCell" customModule="ProductosPY" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="98"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="gx9-df-Xcj" id="dY6-C1-enL">
<rect key="frame" x="0.0" y="0.0" width="414" height="98"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6sj-cq-QzX">
<rect key="frame" x="20" y="20" width="374" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="6sj-cq-QzX" firstAttribute="leading" secondItem="dY6-C1-enL" secondAttribute="leading" constant="20" id="36f-vM-QcT"/>
<constraint firstAttribute="trailing" secondItem="6sj-cq-QzX" secondAttribute="trailing" constant="20" id="HPV-VU-VXL"/>
<constraint firstItem="6sj-cq-QzX" firstAttribute="top" secondItem="dY6-C1-enL" secondAttribute="top" constant="20" id="z6o-Sp-lGf"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="nombreLabel" destination="6sj-cq-QzX" id="gWt-6v-7Er"/>
</connections>
</tableViewCell>
</prototypes>
</tableView>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="lwr-bN-YFd" firstAttribute="leading" secondItem="5F7-CZ-pyk" secondAttribute="leading" id="MZR-gL-36J"/>
<constraint firstItem="lwr-bN-YFd" firstAttribute="top" secondItem="5F7-CZ-pyk" secondAttribute="top" id="QzA-J9-xox"/>
<constraint firstItem="5F7-CZ-pyk" firstAttribute="bottom" secondItem="lwr-bN-YFd" secondAttribute="bottom" id="cje-7D-h1T"/>
<constraint firstItem="5F7-CZ-pyk" firstAttribute="trailing" secondItem="lwr-bN-YFd" secondAttribute="trailing" id="rhW-r6-JYG"/>
</constraints>
<viewLayoutGuide key="safeArea" id="5F7-CZ-pyk"/>
</view>
<navigationItem key="navigationItem" id="pBU-eg-BDv"/>
<connections>
<outlet property="tableView" destination="lwr-bN-YFd" id="QrT-W1-Jm0"/>
<segue destination="ajw-Ik-xeV" kind="unwind" identifier="filterUnSegue" unwindAction="unwindToViewControllerFilterWithSegue:" id="dRq-X2-mOl"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="T7M-7J-04l" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<exit id="ajw-Ik-xeV" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="1827.5362318840582" y="937.5"/>
</scene>
<!--Screen Two View Controller-->
<scene sceneID="GK5-Vt-tJ6">
......@@ -295,11 +354,21 @@
</tableViewCell>
</prototypes>
</tableView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yeq-6s-Oss">
<rect key="frame" x="20" y="700" width="190" height="36"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="20"/>
<state key="normal" title="Todos los productos"/>
<connections>
<action selector="filtroAction:" destination="FrI-c0-r9v" eventType="touchUpInside" id="yaT-HE-Unm"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="XYL-Ea-Svi" firstAttribute="leading" secondItem="8Sf-9f-8lH" secondAttribute="leading" constant="10" id="0PF-Po-YVZ"/>
<constraint firstAttribute="trailing" secondItem="XYL-Ea-Svi" secondAttribute="trailing" constant="10" id="6U6-1a-Wiw"/>
<constraint firstItem="yeq-6s-Oss" firstAttribute="leading" secondItem="8Sf-9f-8lH" secondAttribute="leading" constant="20" id="Pyv-4J-afS"/>
<constraint firstAttribute="bottom" secondItem="yeq-6s-Oss" secondAttribute="bottom" constant="20" id="S4e-o9-Yt9"/>
<constraint firstItem="XYL-Ea-Svi" firstAttribute="top" secondItem="8Sf-9f-8lH" secondAttribute="top" id="yPw-CX-45M"/>
</constraints>
</view>
......@@ -318,12 +387,14 @@
</view>
<navigationItem key="navigationItem" id="3UV-dS-6Uk"/>
<connections>
<outlet property="filtroButton" destination="yeq-6s-Oss" id="dxr-B3-m1M"/>
<outlet property="mapView" destination="8Sf-9f-8lH" id="8B0-on-OxU"/>
<outlet property="searchBarView" destination="U67-QB-Pgr" id="FyF-3w-tZq"/>
<outlet property="tableView" destination="XYL-Ea-Svi" id="Hmf-kU-Luy"/>
<segue destination="BBj-Xn-BVA" kind="show" identifier="screenForDetailSegue" id="25F-o3-VDt"/>
<segue destination="7mb-0g-tTA" kind="show" identifier="screenThreInfomationSegue" id="pQA-RA-5JX"/>
<segue destination="Svh-hj-EjK" kind="show" identifier="screenFiveFavoritesSigue" id="78l-4d-EHT"/>
<segue destination="t9S-AL-NWS" kind="show" identifier="filterSegue" id="2cG-lN-XPL"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="qdd-Xi-vbZ" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
......@@ -471,7 +542,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="gb2-B7-bQo" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2806" y="171"/>
<point key="canvasLocation" x="2745" y="181"/>
</scene>
<!--Screen Five Favorites View Controller-->
<scene sceneID="ErX-0O-5UD">
......@@ -623,7 +694,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="nzr-l3-IRo" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2682.608695652174" y="878.57142857142856"/>
<point key="canvasLocation" x="2788" y="938"/>
</scene>
<!--Fav To Vendor View Controller-->
<scene sceneID="0Wi-qD-IlO">
......@@ -769,7 +840,7 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="ocp-ut-2jD" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
<exit id="ktO-EJ-yQB" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="3816" y="879"/>
<point key="canvasLocation" x="3822" y="938"/>
</scene>
</scenes>
<resources>
......
//
// 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)
}
}
......@@ -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)
}
}
//
// 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!
}
......@@ -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)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment