Commit f2c90045 by Julio Hermosa

Se agregan las funciones para los botones de como llegar y para contactar con el…

Se agregan las funciones para los botones de como llegar y para contactar con el solicitante (llamadas o whatsapp)
parent 64307c70
......@@ -568,21 +568,21 @@ extension AnimatedImageView {
}
class SafeArray<Element> {
private var array: Array<Element> = []
private var favorites: Array<Element> = []
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<Element> {
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
......
......@@ -2,6 +2,12 @@
<Workspace
version = "1.0">
<FileRef
location = "group:ayudapy/IsCheckedList+CoreDataClass.swift">
</FileRef>
<FileRef
location = "group:ayudapy/IsCheckedList+CoreDataProperties.swift">
</FileRef>
<FileRef
location = "group:ayudapy/CoreData/Entity+CoreDataClass.swift">
</FileRef>
<FileRef
......
......@@ -2,7 +2,7 @@
// APIError.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.
//
......
......@@ -2,7 +2,7 @@
// APISessionManager.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.
//
......
......@@ -2,7 +2,7 @@
// HTTPClient.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.
//
......
......@@ -2,7 +2,7 @@
// helpRequest.swift
// ayudapy
//
// Created by Mobile Roshka on 5/7/20.
// Created by Julio Hermosa on 5/7/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
......
......@@ -2,7 +2,7 @@
// AppDelegate.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.
//
......
......@@ -2,7 +2,7 @@
// SceneDelegate.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.
//
......
......@@ -2,7 +2,7 @@
// CoreDataManager.swift
// ayudapy
//
// Created by Mobile Roshka on 5/12/20.
// Created by Julio Hermosa on 5/12/20.
// Copyright © 2020 Mobile Roshka. All rights reserved.
//
......@@ -25,7 +25,7 @@ class CoreDataManager {
}
}
func saveFavorites(id: Int, name: String, date: String, address: String, message: String, title: String, phoneNumber: String, completion: @escaping()-> 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..<array.count {
......@@ -54,11 +55,10 @@ class CoreDataManager {
}catch{
print("error al borrar \(error)")
}
}
}
}
func fetchFavorites()->[Entity]{
let fetchRequest: NSFetchRequest<Entity> = 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> = 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..<array.count {
// if array[i].id == Int64(id){
// context.delete(array[i])
// do{
// try context.save()
// print("\(id) borrado")
// }catch{
// print("error al borrar \(error)")
// }
// }
// }
// }
}
......@@ -4,12 +4,20 @@
<attribute name="address" optional="YES" attributeType="String"/>
<attribute name="date" attributeType="String"/>
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="latitude" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="longitude" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="message" optional="YES" attributeType="String"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="phoneNumber" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/>
</entity>
<entity name="IsCheckedList" representedClassName="IsCheckedList" syncable="YES" codeGenerationType="class">
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="latitude" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="longitude" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
</entity>
<elements>
<element name="Entity" positionX="-54" positionY="-9" width="128" height="148"/>
<element name="Entity" positionX="-54" positionY="-9" width="128" height="178"/>
<element name="IsCheckedList" positionX="-54" positionY="63" width="128" height="88"/>
</elements>
</model>
\ No newline at end of file
//
// IsCheckedList+CoreDataClass.swift
//
//
// Created by Julio Hermosa on 5/19/20.
//
//
import Foundation
import CoreData
@objc(IsCheckedList)
public class IsCheckedList: NSManagedObject {
}
//
// IsCheckedList+CoreDataProperties.swift
//
//
// Created by Julio Hermosa on 5/19/20.
//
//
import Foundation
import CoreData
extension IsCheckedList {
@nonobjc public class func fetchRequest() -> NSFetchRequest<IsCheckedList> {
return NSFetchRequest<IsCheckedList>(entityName: "IsCheckedList")
}
@NSManaged public var id: Int64
@NSManaged public var latitude: Double
@NSManaged public var longitude: Double
}
......@@ -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
}
}
......@@ -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.
//
......
......@@ -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"
bool = true
}
else {
print("no es favorito")
named = "pinGMAPS"
bool = false
}
}
}
else{
named = "pinGMAPS"
bool = false
}
return bool
}
return named
//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)
}
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()
}
}
......
......@@ -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.
//
......
......@@ -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:
......
......@@ -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)
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()
}
}
......
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