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"
}
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()
}
}
......
......@@ -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:
......
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