From f2c9004575183de8f908eb5339959f78f9e712f1 Mon Sep 17 00:00:00 2001 From: Julio Hermosa Date: Tue, 19 May 2020 16:11:36 -0400 Subject: [PATCH] Se agregan las funciones para los botones de como llegar y para contactar con el solicitante (llamadas o whatsapp) --- Pods/Kingfisher/Sources/Views/AnimatedImageView.swift | 16 ++++++++-------- ayudapy.xcworkspace/contents.xcworkspacedata | 6 ++++++ ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate | Bin 174725 -> 0 bytes ayudapy/Api/APIError.swift | 2 +- ayudapy/Api/APISessionManager.swift | 2 +- ayudapy/Api/HTTPClient.swift | 2 +- ayudapy/Api/HelpRequest.swift | 2 +- ayudapy/App/AppDelegate.swift | 2 +- ayudapy/App/SceneDelegate.swift | 2 +- ayudapy/CoreData/CoreDataManager.swift | 42 ++++++++++++++++++++++++++++++++++++------ ayudapy/CoreData/Favorites.xcdatamodeld/favoriteRequests.xcdatamodel/contents | 10 +++++++++- ayudapy/IsCheckedList+CoreDataClass.swift | 15 +++++++++++++++ ayudapy/IsCheckedList+CoreDataProperties.swift | 23 +++++++++++++++++++++++ ayudapy/Static/Format.swift | 9 ++++++++- ayudapy/ViewControllers/InfoViewController.swift | 2 +- ayudapy/ViewControllers/MapViewController.swift | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- ayudapy/ViewControllers/MyPendingsTableViewCell.swift | 2 +- ayudapy/ViewControllers/PendingsViewController.swift | 46 +++++++++++++++++++++++++++++++++------------- ayudapy/ViewControllers/RequestViewController.swift | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- 19 files changed, 282 insertions(+), 120 deletions(-) create mode 100644 ayudapy/IsCheckedList+CoreDataClass.swift create mode 100644 ayudapy/IsCheckedList+CoreDataProperties.swift diff --git a/Pods/Kingfisher/Sources/Views/AnimatedImageView.swift b/Pods/Kingfisher/Sources/Views/AnimatedImageView.swift index e32a1f5..e5a782d 100644 --- a/Pods/Kingfisher/Sources/Views/AnimatedImageView.swift +++ b/Pods/Kingfisher/Sources/Views/AnimatedImageView.swift @@ -568,21 +568,21 @@ extension AnimatedImageView { } class SafeArray { - private var array: Array = [] + private var favorites: Array = [] private let lock = NSLock() subscript(index: Int) -> Element? { get { lock.lock() defer { lock.unlock() } - return array.indices ~= index ? array[index] : nil + return favorites.indices ~= index ? favorites[index] : nil } set { lock.lock() defer { lock.unlock() } - if let newValue = newValue, array.indices ~= index { - array[index] = newValue + if let newValue = newValue, favorites.indices ~= index { + favorites[index] = newValue } } } @@ -590,25 +590,25 @@ class SafeArray { var count : Int { lock.lock() defer { lock.unlock() } - return array.count + return favorites.count } func reserveCapacity(_ count: Int) { lock.lock() defer { lock.unlock() } - array.reserveCapacity(count) + favorites.reserveCapacity(count) } func append(_ element: Element) { lock.lock() defer { lock.unlock() } - array += [element] + favorites += [element] } func removeAll() { lock.lock() defer { lock.unlock() } - array = [] + favorites = [] } } #endif diff --git a/ayudapy.xcworkspace/contents.xcworkspacedata b/ayudapy.xcworkspace/contents.xcworkspacedata index ca52a46..e60dcbc 100644 --- a/ayudapy.xcworkspace/contents.xcworkspacedata +++ b/ayudapy.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,12 @@ + + + + Void){ + func saveFavorites(id: Int, name: String, date: String, address: String, message: String, title: String, phoneNumber: String, latitude: Double, longitude: Double, completion: @escaping()-> Void){ let context = container.viewContext let favorite = Entity(context: context) favorite.id = Int64(id) @@ -37,12 +37,13 @@ class CoreDataManager { favorite.phoneNumber = phoneNumber do{ try context.save() - print("\(id) guardado") + print("\(id) guardado en mis pendientes") completion() }catch{ print("error al guardar \(error)") } } + func deleteFavorites(id: Int, array: [Entity]){ let context = container.viewContext for i in 0..[Entity]{ let fetchRequest: NSFetchRequest = Entity.fetchRequest() do { @@ -67,7 +67,37 @@ class CoreDataManager { }catch{ print("Error al obtener la información de favoritos - \(error)") } - return [] } + + // func saveInCheckedList(id: Int, latitude: Double, longitude: Double, completion: @escaping()-> Void){ + // let context = container.viewContext + // let isCheckedList = IsCheckedList(context: context) + // + // } + // func fetchCheckedList()->[IsCheckedList]{ + // let fetchRequest: NSFetchRequest = IsCheckedList.fetchRequest() + // do { + // let result = try container.viewContext.fetch(fetchRequest) + // return result + // }catch{ + // print("Error al obtener la información de favoritos - \(error)") + // } + // + // return [] + // } +// func deleteCheckObject(id: Int, array: [IsCheckedList]){ +// let context = container.viewContext +// for i in 0.. + + + + + + + - + + \ No newline at end of file diff --git a/ayudapy/IsCheckedList+CoreDataClass.swift b/ayudapy/IsCheckedList+CoreDataClass.swift new file mode 100644 index 0000000..0834381 --- /dev/null +++ b/ayudapy/IsCheckedList+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// IsCheckedList+CoreDataClass.swift +// +// +// Created by Julio Hermosa on 5/19/20. +// +// + +import Foundation +import CoreData + +@objc(IsCheckedList) +public class IsCheckedList: NSManagedObject { + +} diff --git a/ayudapy/IsCheckedList+CoreDataProperties.swift b/ayudapy/IsCheckedList+CoreDataProperties.swift new file mode 100644 index 0000000..477dc05 --- /dev/null +++ b/ayudapy/IsCheckedList+CoreDataProperties.swift @@ -0,0 +1,23 @@ +// +// IsCheckedList+CoreDataProperties.swift +// +// +// Created by Julio Hermosa on 5/19/20. +// +// + +import Foundation +import CoreData + + +extension IsCheckedList { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "IsCheckedList") + } + + @NSManaged public var id: Int64 + @NSManaged public var latitude: Double + @NSManaged public var longitude: Double + +} diff --git a/ayudapy/Static/Format.swift b/ayudapy/Static/Format.swift index 60ed7ed..f96c475 100644 --- a/ayudapy/Static/Format.swift +++ b/ayudapy/Static/Format.swift @@ -2,7 +2,7 @@ // Format.swift // ayudapy // -// Created by Mobile Roshka on 4/30/20. +// Created by Julio Hermosa on 4/30/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // @@ -129,5 +129,12 @@ extension String{ } return month } + func convertURL()->String{ + var newURL = self + let subStr:Substring = "_th" + + return newURL + } + } diff --git a/ayudapy/ViewControllers/InfoViewController.swift b/ayudapy/ViewControllers/InfoViewController.swift index d9ee732..d128592 100644 --- a/ayudapy/ViewControllers/InfoViewController.swift +++ b/ayudapy/ViewControllers/InfoViewController.swift @@ -2,7 +2,7 @@ // AyudaViewController.swift // ayudapy // -// Created by Mobile Roshka on 4/30/20. +// Created by Julio Hermosa on 4/30/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // diff --git a/ayudapy/ViewControllers/MapViewController.swift b/ayudapy/ViewControllers/MapViewController.swift index 0e88e6b..e1b2706 100644 --- a/ayudapy/ViewControllers/MapViewController.swift +++ b/ayudapy/ViewControllers/MapViewController.swift @@ -2,7 +2,7 @@ // MapViewController.swift // ayudapy // -// Created by Mobile Roshka on 4/29/20. +// Created by Julio Hermosa on 4/29/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // @@ -27,8 +27,6 @@ class MapViewController: UIViewController { let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609) //-57.5879897,-43.2723609 -> Posición de Roshka - - //logo cabecera ayudapy.org func addHeader(){ let headerView = UIView(frame: CGRect(x: 0, y: 40, width: view.frame.width, height: 50)) @@ -92,31 +90,6 @@ class MapViewController: UIViewController { mapView.addSubview(footerView) } - //Selectors - @objc func goToInfo(){ - let infoVC = self.storyboard?.instantiateViewController(withIdentifier: "infoVC") as! InfoViewController - show(infoVC, sender: nil) - } - @objc func openLink(){ - if let url = NSURL(string: "https://ayudapy.org/recibir"){ - UIApplication.shared.open(url as URL) - } - } - @objc func goToPendientes(){ - let pendientesVC = self.storyboard?.instantiateViewController(withIdentifier: "pendientesVC") as! PendingsViewController - show(pendientesVC, sender: nil) - } - @objc func goToRequestViewController(pk: Int){ - let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController - pedidosVC.id = id - print("ID del pedido: \(id)") - pedidosVC.helpRequest() - //show(pedidosVC, sender: nil) - isModalInPresentation = true - present(pedidosVC, animated: true, completion: nil) - - } - //Función para hallar el boundingbox actual func getBoundingBox(mapView: GMSMapView)->String{ @@ -141,10 +114,12 @@ class MapViewController: UIViewController { let position = CLLocationCoordinate2D(latitude: lat, longitude: long) let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) - markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside) - let pin = self.addPins(id: self.id) - print("Nombre\(pin)") - markerButton.setImage(UIImage(named: pin), for: .normal) + if self.isFavorite(id: self.id) { + markerButton.setImage(UIImage(named: "pinFavGMAPS"), for: .normal) + } + else { + markerButton.setImage(UIImage(named: "pinGMAPS"), for: .normal) + } markerView.addSubview(markerButton) let marker = GMSMarker(position: position) marker.map = self.mapView @@ -153,7 +128,7 @@ class MapViewController: UIViewController { } }) } - + //configuración de la geolocalización func locationManagerSettings(){ locationManager = CLLocationManager() locationManager.desiredAccuracy = kCLLocationAccuracyBest @@ -169,42 +144,85 @@ class MapViewController: UIViewController { mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.isMyLocationEnabled = true view.addSubview(mapView) - + showFavoritesOrCheckedIcons() mapView.isHidden = true } - //Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente - func addPins(id: Int)->String{ - //let array = manager.fetchFavorites() - var named = String() + //Verificamos si el marcador corresponde a un favorito + func isFavorite(id: Int)->Bool{ + var bool = Bool() if favorites.count > 0{ - for i in 0 ..< favorites.count{ - if favorites[i].id == Int64(id) { - print("es favorito") - named = "pinFavGMAPS" - } - else { - print("no es favorito") - named = "pinGMAPS" + for i in 0 ..< favorites.count{ + if favorites[i].id == Int64(id) { + bool = true + } + else { + bool = false + } } - } } else{ - named = "pinGMAPS" + bool = false } + return bool + } + + //Mostramos en el mapa los marcadores de los pedidos guardados en mis pendientes y/o marcados como listo + func showFavoritesOrCheckedIcons(){ + let named = "pinFavGMAPS" + for i in 0 ..< favorites.count{ + let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) + let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) + let position = CLLocationCoordinate2D(latitude: favorites[i].latitude, longitude: favorites[i].longitude) + markerButton.setImage(UIImage(named: named), for: .normal) + markerView.addSubview(markerButton) + let marker = GMSMarker(position: position) + marker.map = self.mapView + marker.iconView = markerView + marker.title = "\(favorites[i].id)" + } + } + + //Selectors + @objc func goToInfo(){ + let infoVC = self.storyboard?.instantiateViewController(withIdentifier: "infoVC") as! InfoViewController + show(infoVC, sender: nil) + } + @objc func openLink(){ + if let url = NSURL(string: "https://ayudapy.org/recibir"){ + UIApplication.shared.open(url as URL) + } + } + @objc func goToPendientes(){ + let pendientesVC = self.storyboard?.instantiateViewController(withIdentifier: "pendientesVC") as! PendingsViewController + show(pendientesVC, sender: nil) + } + @objc func goToRequestViewController(pk: Int){ + let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController + pedidosVC.id = id + pedidosVC.currentLatitude = (currentLocation?.coordinate.latitude)! + pedidosVC.currentLongitude = (currentLocation?.coordinate.longitude)! + if isFavorite(id: id){ + pedidosVC.isFavorite = true + print("El pedido\(id) es favorito") + } + pedidosVC.helpRequest() + //show(pedidosVC, sender: nil) + isModalInPresentation = true + present(pedidosVC, animated: true, completion: nil) - return named - } + } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) favorites = manager.fetchFavorites() + helpRequest() } - override func viewDidLoad() { super.viewDidLoad() locationManagerSettings() showMapView() + showFavoritesOrCheckedIcons() mapView.delegate = self addHeader() addFooter() @@ -218,6 +236,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate { let location: CLLocation = locations.last! let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,longitude: location.coordinate.longitude, zoom: zoomLevel) + self.currentLocation = location if mapView.isHidden { mapView.isHidden = false mapView.camera = camera @@ -257,6 +276,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate { } func mapView(_ mapView: GMSMapView, willMove gesture: Bool) { helpRequest() + showFavoritesOrCheckedIcons() } } diff --git a/ayudapy/ViewControllers/MyPendingsTableViewCell.swift b/ayudapy/ViewControllers/MyPendingsTableViewCell.swift index 507f7da..57c4d34 100644 --- a/ayudapy/ViewControllers/MyPendingsTableViewCell.swift +++ b/ayudapy/ViewControllers/MyPendingsTableViewCell.swift @@ -2,7 +2,7 @@ // MyPendingsTableViewCell.swift // ayudapy // -// Created by Mobile Roshka on 5/13/20. +// Created by Julio Hermosa on 5/13/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // diff --git a/ayudapy/ViewControllers/PendingsViewController.swift b/ayudapy/ViewControllers/PendingsViewController.swift index 2a274eb..fc3cb36 100644 --- a/ayudapy/ViewControllers/PendingsViewController.swift +++ b/ayudapy/ViewControllers/PendingsViewController.swift @@ -2,7 +2,7 @@ // PendientesViewController.swift // ayudapy // -// Created by Mobile Roshka on 5/1/20. +// Created by Julio Hermosa on 5/1/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // @@ -11,7 +11,7 @@ import CoreData class PendingsViewController: UIViewController { let manager = CoreDataManager() - var array = [Entity]() + var favorites = [Entity]() let format = Format.init() @IBOutlet weak var tableView: UITableView! @@ -19,18 +19,38 @@ class PendingsViewController: UIViewController { func goToRequestViewController(pk: Int){ let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController pedidosVC.id = pk + + if isFavorite(id: pk){ + pedidosVC.isFavorite = true + } print("ID del pedido: \(pk)") pedidosVC.helpRequest() //show(pedidosVC, sender: nil) present(pedidosVC, animated: true, completion: nil) } - + func isFavorite(id: Int)->Bool{ + var bool = Bool() + if favorites.count > 0{ + for i in 0 ..< favorites.count{ + if favorites[i].id == Int64(id) { + bool = true + } + else { + bool = false + } + } + } + else{ + bool = false + } + return bool + } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) - array = manager.fetchFavorites() + favorites = manager.fetchFavorites() } override func viewDidLoad() { @@ -46,22 +66,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyPendingsTableViewCell - let date = array[indexPath.row].date + let date = favorites[indexPath.row].date let month = date!.getDatePart(dateUnit: .month) let monthString = month.getMonthShortString() let day = date!.getDatePart(dateUnit: .day) var detailLabel:String = "" - cell.titleLabel.text = array[indexPath.row].title + cell.titleLabel.text = favorites[indexPath.row].title cell.titleLabel.textColor = format.subTitleTextColor cell.titleLabel.font = format.subTitleFontStyle - if let address = array[indexPath.row].address { + if let address = favorites[indexPath.row].address { detailLabel = address } - if let contactName = array[indexPath.row].name { + if let contactName = favorites[indexPath.row].name { detailLabel = detailLabel + "\n\(contactName)" } - if let contactNumber = array[indexPath.row].phoneNumber { + if let contactNumber = favorites[indexPath.row].phoneNumber { detailLabel = detailLabel + "\n\(contactNumber)" } cell.detailLabel.text = detailLabel @@ -69,7 +89,7 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ cell.dayLabel.text = day cell.monthLabel.text = monthString - let id = array[indexPath.row].id + let id = favorites[indexPath.row].id cell.id = Int(id) return cell @@ -89,14 +109,14 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ return headerLabel } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - goToRequestViewController(pk: Int(array[indexPath.row].id)) + goToRequestViewController(pk: Int(favorites[indexPath.row].id)) } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { switch editingStyle { case .delete: - manager.deleteFavorites(id: Int(array[indexPath.row].id), array: array) - array.remove(at: indexPath.row) + manager.deleteFavorites(id: Int(favorites[indexPath.row].id), array: favorites) + favorites.remove(at: indexPath.row) tableView.deleteRows(at: [indexPath], with: .fade) default: diff --git a/ayudapy/ViewControllers/RequestViewController.swift b/ayudapy/ViewControllers/RequestViewController.swift index d865665..0160297 100644 --- a/ayudapy/ViewControllers/RequestViewController.swift +++ b/ayudapy/ViewControllers/RequestViewController.swift @@ -2,7 +2,7 @@ // PedidosViewController.swift // ayudapy // -// Created by Mobile Roshka on 5/10/20. +// Created by Julio Hermosa on 5/10/20. // Copyright © 2020 Mobile Roshka. All rights reserved. // @@ -12,6 +12,8 @@ import CoreData class RequestViewController: UIViewController { var id = Int() + var currentLatitude = Double() + var currentLongitude = Double() var name = String() var date = String() var message = String() @@ -20,12 +22,13 @@ class RequestViewController: UIViewController { var address = String() var phoneNumber = String() var imageUrl: String? - var coordinates = [Double]() + var longitude = Double() + var latitude = Double() var format = Format.init() var isFavorite = Bool() var checked = Bool() - var favorites = [Int]() private let manager = CoreDataManager() + var favorites = [Entity]() let isFavoriteButton = UIButton() let isFavoriteLabel = UILabel() @@ -47,6 +50,8 @@ class RequestViewController: UIViewController { self.phoneNumber = response!.phone self.address = response!.address self.imageUrl = response!.picture + self.longitude = response!.location.coordinates[0] + self.latitude = response!.location.coordinates[1] self.isFavorite = self.isFavoriteCheck() self.showRequestInformation() } @@ -58,8 +63,6 @@ class RequestViewController: UIViewController { } func showRequestInformation(){ - var viewHeightAnchor = 0 - //let dateToString = "\(date)" let day = date.getDatePart(dateUnit: .day) let month = (date.getDatePart(dateUnit: .month)).getMonthInSpanish() let year = date.getDatePart(dateUnit: .year) @@ -88,7 +91,6 @@ class RequestViewController: UIViewController { headerStackView.axis = .vertical headerStackView.spacing = 5 headerStackView.distribution = .equalSpacing - viewHeightAnchor += Int(headerStackView.frame.height) //Dirección y como llegar let addressSubTittle = UILabel() @@ -103,11 +105,11 @@ class RequestViewController: UIViewController { howToGetButton.backgroundColor = format.subTitleTextColor howToGetButton.layer.cornerRadius = 10 howToGetButton.setTitle("Como llegar", for: .normal) + howToGetButton.addTarget(self, action: #selector(openGoogleMapsLink), for: .touchUpInside) howToGetButton.titleLabel?.font = format.subTitleFontStyle let addressStackView = UIStackView(arrangedSubviews: [addressSubTittle, addressLabel, howToGetButton]) addressStackView.axis = .vertical addressStackView.spacing = 5 - viewHeightAnchor += Int(addressStackView.frame.height) //Información del Contacto let contactLabel = UILabel() @@ -121,10 +123,10 @@ class RequestViewController: UIViewController { contactNumberButton.titleLabel?.font = format.subTitleFontStyle contactNumberButton.layer.cornerRadius = 10 contactNumberButton.setTitle("\(phoneNumber)", for: .normal) + contactNumberButton.addTarget(self, action: #selector(call), for: .touchUpInside) let contactInformationStackView = UIStackView(arrangedSubviews: [contactLabel, contactNameLabel, contactNumberButton]) contactInformationStackView.axis = .vertical contactInformationStackView.spacing = 5 - viewHeightAnchor += Int(contactInformationStackView.frame.height) //checkButton.frame.size = CGSize(width: 80, height: 80) @@ -137,12 +139,17 @@ class RequestViewController: UIViewController { checkStackView.distribution = .fillEqually checkStackView.spacing = 0 - //isFavoriteButton.setImage(heartImage, for: .normal) isFavoriteButton.frame.size = CGSize(width: 80, height: 80) - isFavoriteButton.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal) - isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside) + if isFavorite{ + isFavoriteButton.setImage(UIImage(named: "iconPendientesChecked"), for: .normal) + isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside) + isFavoriteLabel.text = "Quitar de mis Pendientes" + }else{ + isFavoriteButton.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal) + isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside) + isFavoriteLabel.text = "Agregar a mis Pendientes" + } - isFavoriteLabel.text = "Agregar a mis pendientes" isFavoriteLabel.font = format.bodyFontStyle isFavoriteLabel.numberOfLines = 2 isFavoriteLabel.textAlignment = .center @@ -159,29 +166,21 @@ class RequestViewController: UIViewController { footerStackView.axis = .horizontal footerStackView.distribution = .fillEqually footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true - viewHeightAnchor += Int(isFavoriteStackView.frame.height) - viewHeightAnchor += 30 + //viewHeightAnchor += Int(isFavoriteStackView.frame.height) + //viewHeightAnchor += 30 let stackView = UIStackView(arrangedSubviews: [headerStackView, addressStackView, contactInformationStackView, footerStackView]) stackView.axis = .vertical stackView.distribution = .equalSpacing stackView.spacing = 10 stackView.layer.frame = CGRect(x: 20, y: 20, width: view.frame.width * 0.9, height: view.frame.height*0.9) - //stackView.heightAnchor.constraint(equalToConstant: CGFloat(viewHeightAnchor)).isActive = true - //stackView.widthAnchor.constraint(equalToConstant: view.frame.width * 0.9).isActive = true - //let scrollView = UIScrollView() - //scrollView.heightAnchor.constraint(equalToConstant: view.frame.height).isActive = true - //scrollView.widthAnchor.constraint(equalToConstant: view.frame.width).isActive = true - //scrollView.addSubview(stackView) - - //view.addSubview(scrollView) + view.addSubview(stackView) } func isFavoriteCheck()->Bool{ - let favoritos = manager.fetchFavorites() var bool = false - for i in 0 ..< favoritos.count { - if favoritos[i].id == Int64(id) { + for i in 0 ..< favorites.count { + if favorites[i].id == Int64(id) { bool = true } else { @@ -196,19 +195,14 @@ class RequestViewController: UIViewController { } @objc func addOrRemoveFavorite(sender: UIButton){ - - let favorites = manager.fetchFavorites() if isFavorite { - print("estaba guardado") manager.deleteFavorites(id: id, array: favorites) self.isFavorite = false sender.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal) self.isFavoriteLabel.text = "Agregar a mis Pendientes" }else { - print("se tiene que guardar") - - manager.saveFavorites(id: id, name: name, date: date, address: address, message: message, title: hRequestTitle, phoneNumber: phoneNumber) { [weak self] in + manager.saveFavorites(id: id, name: name, date: date, address: address, message: message, title: hRequestTitle, phoneNumber: phoneNumber, latitude: latitude, longitude: longitude) { [weak self] in print("\(self as Any) guardado!") self?.isFavorite = true } @@ -217,9 +211,48 @@ class RequestViewController: UIViewController { self.isFavoriteLabel.text = "Quitar de mis Pendientes" } } + @objc func openGoogleMapsLink(){ + //https://www.google.com/maps/dir/-25.2860598,-57.6162619/-25.287641,-57.611509/ + if let url = NSURL(string: "https://www.google.com/maps/dir/\(currentLatitude),\(currentLongitude )/\(latitude),\(longitude)"){ + UIApplication.shared.open(url as URL) + } + } + @objc func call() { + showAlert() + } + func showAlert(){ + let alert = UIAlertController(title: "Deseas contactar al \(phoneNumber)", message: "Elija una opción para continuar!", preferredStyle: .alert) + + alert.addAction(UIAlertAction(title: "Llamar", style: .default, handler: {action in + let cleanPhoneNumber = self.phoneNumber.components(separatedBy: CharacterSet.decimalDigits.inverted).joined(separator: "") + let urlString:String = "tel:\(cleanPhoneNumber)" + if let phoneCallURL = URL(string: urlString) { + UIApplication.shared.canOpenURL(phoneCallURL) + if (UIApplication.shared.canOpenURL(phoneCallURL)) { + UIApplication.shared.open(phoneCallURL, options: [:], completionHandler: nil) + } + } + })) + alert.addAction(UIAlertAction(title: "WhatsApp", style: .default, handler: {sendWspMsg in + let msg = "Hola! te escribo porque vi tu pedido de ayuda " + let urlWhats = "whatsapp://send?phone=\(self.phoneNumber)&text=\(msg)" + + if let urlString = urlWhats.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed) { + if let whatsappURL = NSURL(string: urlString) { + if UIApplication.shared.canOpenURL(whatsappURL as URL) { + UIApplication.shared.open(whatsappURL as URL) + } else { + print("No se ha podido conectar con whatsapp") + } + } + } + })) + alert.addAction(UIAlertAction(title: "Cancelar", style: .cancel, handler: nil)) + + self.present(alert, animated: true) + } override func viewDidLoad() { - helpRequest() } } -- libgit2 0.26.0