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 { ...@@ -568,21 +568,21 @@ extension AnimatedImageView {
} }
class SafeArray<Element> { class SafeArray<Element> {
private var array: Array<Element> = [] private var favorites: Array<Element> = []
private let lock = NSLock() private let lock = NSLock()
subscript(index: Int) -> Element? { subscript(index: Int) -> Element? {
get { get {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
return array.indices ~= index ? array[index] : nil return favorites.indices ~= index ? favorites[index] : nil
} }
set { set {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
if let newValue = newValue, array.indices ~= index { if let newValue = newValue, favorites.indices ~= index {
array[index] = newValue favorites[index] = newValue
} }
} }
} }
...@@ -590,25 +590,25 @@ class SafeArray<Element> { ...@@ -590,25 +590,25 @@ class SafeArray<Element> {
var count : Int { var count : Int {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
return array.count return favorites.count
} }
func reserveCapacity(_ count: Int) { func reserveCapacity(_ count: Int) {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
array.reserveCapacity(count) favorites.reserveCapacity(count)
} }
func append(_ element: Element) { func append(_ element: Element) {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
array += [element] favorites += [element]
} }
func removeAll() { func removeAll() {
lock.lock() lock.lock()
defer { lock.unlock() } defer { lock.unlock() }
array = [] favorites = []
} }
} }
#endif #endif
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "group:ayudapy/IsCheckedList+CoreDataClass.swift">
</FileRef>
<FileRef
location = "group:ayudapy/IsCheckedList+CoreDataProperties.swift">
</FileRef>
<FileRef
location = "group:ayudapy/CoreData/Entity+CoreDataClass.swift"> location = "group:ayudapy/CoreData/Entity+CoreDataClass.swift">
</FileRef> </FileRef>
<FileRef <FileRef
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// APIError.swift // APIError.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/1/20. // Created by Julio Hermosa on 5/1/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// APISessionManager.swift // APISessionManager.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/1/20. // Created by Julio Hermosa on 5/1/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// HTTPClient.swift // HTTPClient.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/1/20. // Created by Julio Hermosa on 5/1/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// helpRequest.swift // helpRequest.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/7/20. // Created by Julio Hermosa on 5/7/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// AppDelegate.swift // AppDelegate.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 4/29/20. // Created by Julio Hermosa on 4/29/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// SceneDelegate.swift // SceneDelegate.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 4/29/20. // Created by Julio Hermosa on 4/29/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// CoreDataManager.swift // CoreDataManager.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/12/20. // Created by Julio Hermosa on 5/12/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
...@@ -25,7 +25,7 @@ class CoreDataManager { ...@@ -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 context = container.viewContext
let favorite = Entity(context: context) let favorite = Entity(context: context)
favorite.id = Int64(id) favorite.id = Int64(id)
...@@ -37,12 +37,13 @@ class CoreDataManager { ...@@ -37,12 +37,13 @@ class CoreDataManager {
favorite.phoneNumber = phoneNumber favorite.phoneNumber = phoneNumber
do{ do{
try context.save() try context.save()
print("\(id) guardado") print("\(id) guardado en mis pendientes")
completion() completion()
}catch{ }catch{
print("error al guardar \(error)") print("error al guardar \(error)")
} }
} }
func deleteFavorites(id: Int, array: [Entity]){ func deleteFavorites(id: Int, array: [Entity]){
let context = container.viewContext let context = container.viewContext
for i in 0..<array.count { for i in 0..<array.count {
...@@ -54,11 +55,10 @@ class CoreDataManager { ...@@ -54,11 +55,10 @@ class CoreDataManager {
}catch{ }catch{
print("error al borrar \(error)") print("error al borrar \(error)")
} }
} }
} }
} }
func fetchFavorites()->[Entity]{ func fetchFavorites()->[Entity]{
let fetchRequest: NSFetchRequest<Entity> = Entity.fetchRequest() let fetchRequest: NSFetchRequest<Entity> = Entity.fetchRequest()
do { do {
...@@ -67,7 +67,37 @@ class CoreDataManager { ...@@ -67,7 +67,37 @@ class CoreDataManager {
}catch{ }catch{
print("Error al obtener la información de favoritos - \(error)") print("Error al obtener la información de favoritos - \(error)")
} }
return [] 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 @@ ...@@ -4,12 +4,20 @@
<attribute name="address" optional="YES" attributeType="String"/> <attribute name="address" optional="YES" attributeType="String"/>
<attribute name="date" attributeType="String"/> <attribute name="date" attributeType="String"/>
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/> <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="message" optional="YES" attributeType="String"/>
<attribute name="name" optional="YES" attributeType="String"/> <attribute name="name" optional="YES" attributeType="String"/>
<attribute name="phoneNumber" optional="YES" attributeType="String"/> <attribute name="phoneNumber" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/> <attribute name="title" optional="YES" attributeType="String"/>
</entity> </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> <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> </elements>
</model> </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 @@ ...@@ -2,7 +2,7 @@
// Format.swift // Format.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 4/30/20. // Created by Julio Hermosa on 4/30/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
...@@ -129,5 +129,12 @@ extension String{ ...@@ -129,5 +129,12 @@ extension String{
} }
return month return month
} }
func convertURL()->String{
var newURL = self
let subStr:Substring = "_th"
return newURL
}
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// AyudaViewController.swift // AyudaViewController.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 4/30/20. // Created by Julio Hermosa on 4/30/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// MapViewController.swift // MapViewController.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 4/29/20. // Created by Julio Hermosa on 4/29/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
...@@ -27,8 +27,6 @@ class MapViewController: UIViewController { ...@@ -27,8 +27,6 @@ class MapViewController: UIViewController {
let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609) let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609)
//-57.5879897,-43.2723609 -> Posición de Roshka //-57.5879897,-43.2723609 -> Posición de Roshka
//logo cabecera ayudapy.org //logo cabecera ayudapy.org
func addHeader(){ func addHeader(){
let headerView = UIView(frame: CGRect(x: 0, y: 40, width: view.frame.width, height: 50)) let headerView = UIView(frame: CGRect(x: 0, y: 40, width: view.frame.width, height: 50))
...@@ -92,31 +90,6 @@ class MapViewController: UIViewController { ...@@ -92,31 +90,6 @@ class MapViewController: UIViewController {
mapView.addSubview(footerView) 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 //Función para hallar el boundingbox actual
func getBoundingBox(mapView: GMSMapView)->String{ func getBoundingBox(mapView: GMSMapView)->String{
...@@ -141,10 +114,12 @@ class MapViewController: UIViewController { ...@@ -141,10 +114,12 @@ class MapViewController: UIViewController {
let position = CLLocationCoordinate2D(latitude: lat, longitude: long) let position = CLLocationCoordinate2D(latitude: lat, longitude: long)
let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 35)) 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 markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 30, height: 35))
markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside) if self.isFavorite(id: self.id) {
let pin = self.addPins(id: self.id) markerButton.setImage(UIImage(named: "pinFavGMAPS"), for: .normal)
print("Nombre\(pin)") }
markerButton.setImage(UIImage(named: pin), for: .normal) else {
markerButton.setImage(UIImage(named: "pinGMAPS"), for: .normal)
}
markerView.addSubview(markerButton) markerView.addSubview(markerButton)
let marker = GMSMarker(position: position) let marker = GMSMarker(position: position)
marker.map = self.mapView marker.map = self.mapView
...@@ -153,7 +128,7 @@ class MapViewController: UIViewController { ...@@ -153,7 +128,7 @@ class MapViewController: UIViewController {
} }
}) })
} }
//configuración de la geolocalización
func locationManagerSettings(){ func locationManagerSettings(){
locationManager = CLLocationManager() locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.desiredAccuracy = kCLLocationAccuracyBest
...@@ -169,42 +144,85 @@ class MapViewController: UIViewController { ...@@ -169,42 +144,85 @@ class MapViewController: UIViewController {
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
mapView.isMyLocationEnabled = true mapView.isMyLocationEnabled = true
view.addSubview(mapView) view.addSubview(mapView)
showFavoritesOrCheckedIcons()
mapView.isHidden = true mapView.isHidden = true
} }
//Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente //Verificamos si el marcador corresponde a un favorito
func addPins(id: Int)->String{ func isFavorite(id: Int)->Bool{
//let array = manager.fetchFavorites() var bool = Bool()
var named = String()
if favorites.count > 0{ if favorites.count > 0{
for i in 0 ..< favorites.count{ for i in 0 ..< favorites.count{
if favorites[i].id == Int64(id) { if favorites[i].id == Int64(id) {
print("es favorito") bool = true
named = "pinFavGMAPS"
} }
else { else {
print("no es favorito") bool = false
named = "pinGMAPS"
} }
} }
} }
else{ 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) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true) super.viewWillAppear(true)
favorites = manager.fetchFavorites() favorites = manager.fetchFavorites()
helpRequest()
} }
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
locationManagerSettings() locationManagerSettings()
showMapView() showMapView()
showFavoritesOrCheckedIcons()
mapView.delegate = self mapView.delegate = self
addHeader() addHeader()
addFooter() addFooter()
...@@ -218,6 +236,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate { ...@@ -218,6 +236,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate {
let location: CLLocation = locations.last! let location: CLLocation = locations.last!
let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,longitude: location.coordinate.longitude, zoom: zoomLevel) let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude,longitude: location.coordinate.longitude, zoom: zoomLevel)
self.currentLocation = location
if mapView.isHidden { if mapView.isHidden {
mapView.isHidden = false mapView.isHidden = false
mapView.camera = camera mapView.camera = camera
...@@ -257,6 +276,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate { ...@@ -257,6 +276,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate {
} }
func mapView(_ mapView: GMSMapView, willMove gesture: Bool) { func mapView(_ mapView: GMSMapView, willMove gesture: Bool) {
helpRequest() helpRequest()
showFavoritesOrCheckedIcons()
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// MyPendingsTableViewCell.swift // MyPendingsTableViewCell.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/13/20. // Created by Julio Hermosa on 5/13/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// PendientesViewController.swift // PendientesViewController.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/1/20. // Created by Julio Hermosa on 5/1/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
...@@ -11,7 +11,7 @@ import CoreData ...@@ -11,7 +11,7 @@ import CoreData
class PendingsViewController: UIViewController { class PendingsViewController: UIViewController {
let manager = CoreDataManager() let manager = CoreDataManager()
var array = [Entity]() var favorites = [Entity]()
let format = Format.init() let format = Format.init()
@IBOutlet weak var tableView: UITableView! @IBOutlet weak var tableView: UITableView!
...@@ -19,18 +19,38 @@ class PendingsViewController: UIViewController { ...@@ -19,18 +19,38 @@ class PendingsViewController: UIViewController {
func goToRequestViewController(pk: Int){ func goToRequestViewController(pk: Int){
let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController
pedidosVC.id = pk pedidosVC.id = pk
if isFavorite(id: pk){
pedidosVC.isFavorite = true
}
print("ID del pedido: \(pk)") print("ID del pedido: \(pk)")
pedidosVC.helpRequest() pedidosVC.helpRequest()
//show(pedidosVC, sender: nil) //show(pedidosVC, sender: nil)
present(pedidosVC, animated: true, completion: 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) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
array = manager.fetchFavorites() favorites = manager.fetchFavorites()
} }
override func viewDidLoad() { override func viewDidLoad() {
...@@ -46,22 +66,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -46,22 +66,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MyPendingsTableViewCell 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 month = date!.getDatePart(dateUnit: .month)
let monthString = month.getMonthShortString() let monthString = month.getMonthShortString()
let day = date!.getDatePart(dateUnit: .day) let day = date!.getDatePart(dateUnit: .day)
var detailLabel:String = "" var detailLabel:String = ""
cell.titleLabel.text = array[indexPath.row].title cell.titleLabel.text = favorites[indexPath.row].title
cell.titleLabel.textColor = format.subTitleTextColor cell.titleLabel.textColor = format.subTitleTextColor
cell.titleLabel.font = format.subTitleFontStyle cell.titleLabel.font = format.subTitleFontStyle
if let address = array[indexPath.row].address { if let address = favorites[indexPath.row].address {
detailLabel = address detailLabel = address
} }
if let contactName = array[indexPath.row].name { if let contactName = favorites[indexPath.row].name {
detailLabel = detailLabel + "\n\(contactName)" detailLabel = detailLabel + "\n\(contactName)"
} }
if let contactNumber = array[indexPath.row].phoneNumber { if let contactNumber = favorites[indexPath.row].phoneNumber {
detailLabel = detailLabel + "\n\(contactNumber)" detailLabel = detailLabel + "\n\(contactNumber)"
} }
cell.detailLabel.text = detailLabel cell.detailLabel.text = detailLabel
...@@ -69,7 +89,7 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -69,7 +89,7 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
cell.dayLabel.text = day cell.dayLabel.text = day
cell.monthLabel.text = monthString cell.monthLabel.text = monthString
let id = array[indexPath.row].id let id = favorites[indexPath.row].id
cell.id = Int(id) cell.id = Int(id)
return cell return cell
...@@ -89,14 +109,14 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -89,14 +109,14 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
return headerLabel return headerLabel
} }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 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) { func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
switch editingStyle { switch editingStyle {
case .delete: case .delete:
manager.deleteFavorites(id: Int(array[indexPath.row].id), array: array) manager.deleteFavorites(id: Int(favorites[indexPath.row].id), array: favorites)
array.remove(at: indexPath.row) favorites.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .fade) tableView.deleteRows(at: [indexPath], with: .fade)
default: default:
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// PedidosViewController.swift // PedidosViewController.swift
// ayudapy // ayudapy
// //
// Created by Mobile Roshka on 5/10/20. // Created by Julio Hermosa on 5/10/20.
// Copyright © 2020 Mobile Roshka. All rights reserved. // Copyright © 2020 Mobile Roshka. All rights reserved.
// //
...@@ -12,6 +12,8 @@ import CoreData ...@@ -12,6 +12,8 @@ import CoreData
class RequestViewController: UIViewController { class RequestViewController: UIViewController {
var id = Int() var id = Int()
var currentLatitude = Double()
var currentLongitude = Double()
var name = String() var name = String()
var date = String() var date = String()
var message = String() var message = String()
...@@ -20,12 +22,13 @@ class RequestViewController: UIViewController { ...@@ -20,12 +22,13 @@ class RequestViewController: UIViewController {
var address = String() var address = String()
var phoneNumber = String() var phoneNumber = String()
var imageUrl: String? var imageUrl: String?
var coordinates = [Double]() var longitude = Double()
var latitude = Double()
var format = Format.init() var format = Format.init()
var isFavorite = Bool() var isFavorite = Bool()
var checked = Bool() var checked = Bool()
var favorites = [Int]()
private let manager = CoreDataManager() private let manager = CoreDataManager()
var favorites = [Entity]()
let isFavoriteButton = UIButton() let isFavoriteButton = UIButton()
let isFavoriteLabel = UILabel() let isFavoriteLabel = UILabel()
...@@ -47,6 +50,8 @@ class RequestViewController: UIViewController { ...@@ -47,6 +50,8 @@ class RequestViewController: UIViewController {
self.phoneNumber = response!.phone self.phoneNumber = response!.phone
self.address = response!.address self.address = response!.address
self.imageUrl = response!.picture self.imageUrl = response!.picture
self.longitude = response!.location.coordinates[0]
self.latitude = response!.location.coordinates[1]
self.isFavorite = self.isFavoriteCheck() self.isFavorite = self.isFavoriteCheck()
self.showRequestInformation() self.showRequestInformation()
} }
...@@ -58,8 +63,6 @@ class RequestViewController: UIViewController { ...@@ -58,8 +63,6 @@ class RequestViewController: UIViewController {
} }
func showRequestInformation(){ func showRequestInformation(){
var viewHeightAnchor = 0
//let dateToString = "\(date)"
let day = date.getDatePart(dateUnit: .day) let day = date.getDatePart(dateUnit: .day)
let month = (date.getDatePart(dateUnit: .month)).getMonthInSpanish() let month = (date.getDatePart(dateUnit: .month)).getMonthInSpanish()
let year = date.getDatePart(dateUnit: .year) let year = date.getDatePart(dateUnit: .year)
...@@ -88,7 +91,6 @@ class RequestViewController: UIViewController { ...@@ -88,7 +91,6 @@ class RequestViewController: UIViewController {
headerStackView.axis = .vertical headerStackView.axis = .vertical
headerStackView.spacing = 5 headerStackView.spacing = 5
headerStackView.distribution = .equalSpacing headerStackView.distribution = .equalSpacing
viewHeightAnchor += Int(headerStackView.frame.height)
//Dirección y como llegar //Dirección y como llegar
let addressSubTittle = UILabel() let addressSubTittle = UILabel()
...@@ -103,11 +105,11 @@ class RequestViewController: UIViewController { ...@@ -103,11 +105,11 @@ class RequestViewController: UIViewController {
howToGetButton.backgroundColor = format.subTitleTextColor howToGetButton.backgroundColor = format.subTitleTextColor
howToGetButton.layer.cornerRadius = 10 howToGetButton.layer.cornerRadius = 10
howToGetButton.setTitle("Como llegar", for: .normal) howToGetButton.setTitle("Como llegar", for: .normal)
howToGetButton.addTarget(self, action: #selector(openGoogleMapsLink), for: .touchUpInside)
howToGetButton.titleLabel?.font = format.subTitleFontStyle howToGetButton.titleLabel?.font = format.subTitleFontStyle
let addressStackView = UIStackView(arrangedSubviews: [addressSubTittle, addressLabel, howToGetButton]) let addressStackView = UIStackView(arrangedSubviews: [addressSubTittle, addressLabel, howToGetButton])
addressStackView.axis = .vertical addressStackView.axis = .vertical
addressStackView.spacing = 5 addressStackView.spacing = 5
viewHeightAnchor += Int(addressStackView.frame.height)
//Información del Contacto //Información del Contacto
let contactLabel = UILabel() let contactLabel = UILabel()
...@@ -121,10 +123,10 @@ class RequestViewController: UIViewController { ...@@ -121,10 +123,10 @@ class RequestViewController: UIViewController {
contactNumberButton.titleLabel?.font = format.subTitleFontStyle contactNumberButton.titleLabel?.font = format.subTitleFontStyle
contactNumberButton.layer.cornerRadius = 10 contactNumberButton.layer.cornerRadius = 10
contactNumberButton.setTitle("\(phoneNumber)", for: .normal) contactNumberButton.setTitle("\(phoneNumber)", for: .normal)
contactNumberButton.addTarget(self, action: #selector(call), for: .touchUpInside)
let contactInformationStackView = UIStackView(arrangedSubviews: [contactLabel, contactNameLabel, contactNumberButton]) let contactInformationStackView = UIStackView(arrangedSubviews: [contactLabel, contactNameLabel, contactNumberButton])
contactInformationStackView.axis = .vertical contactInformationStackView.axis = .vertical
contactInformationStackView.spacing = 5 contactInformationStackView.spacing = 5
viewHeightAnchor += Int(contactInformationStackView.frame.height)
//checkButton.frame.size = CGSize(width: 80, height: 80) //checkButton.frame.size = CGSize(width: 80, height: 80)
...@@ -137,12 +139,17 @@ class RequestViewController: UIViewController { ...@@ -137,12 +139,17 @@ class RequestViewController: UIViewController {
checkStackView.distribution = .fillEqually checkStackView.distribution = .fillEqually
checkStackView.spacing = 0 checkStackView.spacing = 0
//isFavoriteButton.setImage(heartImage, for: .normal)
isFavoriteButton.frame.size = CGSize(width: 80, height: 80) 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.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal)
isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside) 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.font = format.bodyFontStyle
isFavoriteLabel.numberOfLines = 2 isFavoriteLabel.numberOfLines = 2
isFavoriteLabel.textAlignment = .center isFavoriteLabel.textAlignment = .center
...@@ -159,29 +166,21 @@ class RequestViewController: UIViewController { ...@@ -159,29 +166,21 @@ class RequestViewController: UIViewController {
footerStackView.axis = .horizontal footerStackView.axis = .horizontal
footerStackView.distribution = .fillEqually footerStackView.distribution = .fillEqually
footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true
viewHeightAnchor += Int(isFavoriteStackView.frame.height) //viewHeightAnchor += Int(isFavoriteStackView.frame.height)
viewHeightAnchor += 30 //viewHeightAnchor += 30
let stackView = UIStackView(arrangedSubviews: [headerStackView, addressStackView, contactInformationStackView, footerStackView]) let stackView = UIStackView(arrangedSubviews: [headerStackView, addressStackView, contactInformationStackView, footerStackView])
stackView.axis = .vertical stackView.axis = .vertical
stackView.distribution = .equalSpacing stackView.distribution = .equalSpacing
stackView.spacing = 10 stackView.spacing = 10
stackView.layer.frame = CGRect(x: 20, y: 20, width: view.frame.width * 0.9, height: view.frame.height*0.9) 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) view.addSubview(stackView)
} }
func isFavoriteCheck()->Bool{ func isFavoriteCheck()->Bool{
let favoritos = manager.fetchFavorites()
var bool = false var bool = false
for i in 0 ..< favoritos.count { for i in 0 ..< favorites.count {
if favoritos[i].id == Int64(id) { if favorites[i].id == Int64(id) {
bool = true bool = true
} }
else { else {
...@@ -196,19 +195,14 @@ class RequestViewController: UIViewController { ...@@ -196,19 +195,14 @@ class RequestViewController: UIViewController {
} }
@objc func addOrRemoveFavorite(sender: UIButton){ @objc func addOrRemoveFavorite(sender: UIButton){
let favorites = manager.fetchFavorites()
if isFavorite { if isFavorite {
print("estaba guardado")
manager.deleteFavorites(id: id, array: favorites) manager.deleteFavorites(id: id, array: favorites)
self.isFavorite = false self.isFavorite = false
sender.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal) sender.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal)
self.isFavoriteLabel.text = "Agregar a mis Pendientes" self.isFavoriteLabel.text = "Agregar a mis Pendientes"
}else }else
{ {
print("se tiene que guardar") manager.saveFavorites(id: id, name: name, date: date, address: address, message: message, title: hRequestTitle, phoneNumber: phoneNumber, latitude: latitude, longitude: longitude) { [weak self] in
manager.saveFavorites(id: id, name: name, date: date, address: address, message: message, title: hRequestTitle, phoneNumber: phoneNumber) { [weak self] in
print("\(self as Any) guardado!") print("\(self as Any) guardado!")
self?.isFavorite = true self?.isFavorite = true
} }
...@@ -217,9 +211,48 @@ class RequestViewController: UIViewController { ...@@ -217,9 +211,48 @@ class RequestViewController: UIViewController {
self.isFavoriteLabel.text = "Quitar de mis Pendientes" 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() { 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