From 9d76d3293f7d720548f25e419da23aa6d32401e9 Mon Sep 17 00:00:00 2001 From: Julio Hermosa Date: Tue, 19 May 2020 17:44:00 -0400 Subject: [PATCH] Se ordena y documenta el código --- ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate | Bin 178910 -> 0 bytes ayudapy/Base.lproj/Main.storyboard | 4 ++-- ayudapy/CoreData/CoreDataManager.swift | 10 ++++++++++ ayudapy/Info.plist | 6 ++---- ayudapy/Static/Format.swift | 12 ++++++------ ayudapy/ViewControllers/MapViewController.swift | 58 +++++++++++++++++++++------------------------------------- ayudapy/ViewControllers/PendingsViewController.swift | 15 +++++++++------ ayudapy/ViewControllers/RequestViewController.swift | 52 ++++++++++++++++++++++++---------------------------- 8 files changed, 74 insertions(+), 83 deletions(-) diff --git a/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate b/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate index c64eecd..3fb0288 100644 Binary files a/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate and b/ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ayudapy/Base.lproj/Main.storyboard b/ayudapy/Base.lproj/Main.storyboard index 6388552..9e555c2 100644 --- a/ayudapy/Base.lproj/Main.storyboard +++ b/ayudapy/Base.lproj/Main.storyboard @@ -10,7 +10,7 @@ - + @@ -41,7 +41,7 @@ - + diff --git a/ayudapy/CoreData/CoreDataManager.swift b/ayudapy/CoreData/CoreDataManager.swift index 5e389e9..2bd3e8c 100644 --- a/ayudapy/CoreData/CoreDataManager.swift +++ b/ayudapy/CoreData/CoreDataManager.swift @@ -69,6 +69,16 @@ class CoreDataManager { } return [] } + func checkData(id: Int, entityList: [Entity])->Bool{ + let array = entityList + var bool = false + for i in 0.. Void){ // let context = container.viewContext diff --git a/ayudapy/Info.plist b/ayudapy/Info.plist index 15387e6..bc6eccd 100644 --- a/ayudapy/Info.plist +++ b/ayudapy/Info.plist @@ -20,6 +20,8 @@ 1 LSRequiresIPhoneOS + NSLocationWhenInUseUsageDescription + UIApplicationSceneManifest UIApplicationSupportsMultipleScenes @@ -50,11 +52,7 @@ UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - NSLocationWhenInUseUsageDescription - UISupportedInterfaceOrientations~ipad UIInterfaceOrientationPortrait diff --git a/ayudapy/Static/Format.swift b/ayudapy/Static/Format.swift index f96c475..845ce03 100644 --- a/ayudapy/Static/Format.swift +++ b/ayudapy/Static/Format.swift @@ -129,12 +129,12 @@ extension String{ } return month } - func convertURL()->String{ - var newURL = self - let subStr:Substring = "_th" - - return newURL - } +// func convertURL()->String{ +// var newURL = self +// let subStr:Substring = "_th" +// +// return newURL +// } } diff --git a/ayudapy/ViewControllers/MapViewController.swift b/ayudapy/ViewControllers/MapViewController.swift index e1b2706..24089dc 100644 --- a/ayudapy/ViewControllers/MapViewController.swift +++ b/ayudapy/ViewControllers/MapViewController.swift @@ -54,7 +54,7 @@ class MapViewController: UIViewController { infoLabel.font = UIFont.systemFont(ofSize: 8) infoLabel.textColor = format.footerTextColor infoButton.setImage(UIImage(named: "infoButton"), for: .normal) - infoButton.addTarget(self, action: #selector(goToInfo), for: .touchUpInside) + infoButton.addTarget(self, action: #selector(goToInfoVC), for: .touchUpInside) footerView.addSubview(infoLabel) footerView.addSubview(infoButton) @@ -83,7 +83,7 @@ class MapViewController: UIViewController { pendingLabel.font = UIFont.systemFont(ofSize: 8) pendingLabel.textAlignment = .center pendingButton.setImage(UIImage(named: "pendientesButton"), for: .normal) - pendingButton.addTarget(self, action: #selector(goToPendientes), for: .touchUpInside) + pendingButton.addTarget(self, action: #selector(goToPendingsVC), for: .touchUpInside) footerView.addSubview(pendingLabel) @@ -114,7 +114,7 @@ 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)) - if self.isFavorite(id: self.id) { + if self.manager.checkData(id: self.id, entityList: self.favorites){ markerButton.setImage(UIImage(named: "pinFavGMAPS"), for: .normal) } else { @@ -148,28 +148,10 @@ class MapViewController: UIViewController { mapView.isHidden = true } - //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) { - bool = true - } - else { - bool = false - } - } - } - else{ - 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" + favorites = manager.fetchFavorites() 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)) @@ -184,7 +166,7 @@ class MapViewController: UIViewController { } //Selectors - @objc func goToInfo(){ + @objc func goToInfoVC(){ let infoVC = self.storyboard?.instantiateViewController(withIdentifier: "infoVC") as! InfoViewController show(infoVC, sender: nil) } @@ -193,28 +175,30 @@ class MapViewController: UIViewController { UIApplication.shared.open(url as URL) } } - @objc func goToPendientes(){ - let pendientesVC = self.storyboard?.instantiateViewController(withIdentifier: "pendientesVC") as! PendingsViewController - show(pendientesVC, sender: nil) + @objc func goToPendingsVC(){ + let pendingsVC = self.storyboard?.instantiateViewController(withIdentifier: "pendingsVC") as! PendingsViewController + pendingsVC.currentLatitude = (currentLocation?.coordinate.latitude)! + pendingsVC.currentLongitude = (currentLocation?.coordinate.longitude)! + show(pendingsVC, 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 + @objc func goToRequestVC(pk: Int){ + let requestsVC = self.storyboard?.instantiateViewController(withIdentifier: "requestsVC")as! RequestViewController + requestsVC.id = id + requestsVC.currentLatitude = (currentLocation?.coordinate.latitude)! + requestsVC.currentLongitude = (currentLocation?.coordinate.longitude)! + if manager.checkData(id: id, entityList: favorites){ + requestsVC.isFavorite = true print("El pedido\(id) es favorito") } - pedidosVC.helpRequest() - //show(pedidosVC, sender: nil) + requestsVC.helpRequest() isModalInPresentation = true - present(pedidosVC, animated: true, completion: nil) + present(requestsVC, animated: true, completion: nil) } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) favorites = manager.fetchFavorites() + print("Estos son los favoritos \(favorites)") helpRequest() } @@ -271,7 +255,7 @@ extension MapViewController: CLLocationManagerDelegate, GMSMapViewDelegate { func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool { id = Int(marker.title!)! - goToRequestViewController(pk: id) + goToRequestVC(pk: id) return true } func mapView(_ mapView: GMSMapView, willMove gesture: Bool) { diff --git a/ayudapy/ViewControllers/PendingsViewController.swift b/ayudapy/ViewControllers/PendingsViewController.swift index fc3cb36..660fe57 100644 --- a/ayudapy/ViewControllers/PendingsViewController.swift +++ b/ayudapy/ViewControllers/PendingsViewController.swift @@ -13,20 +13,23 @@ class PendingsViewController: UIViewController { let manager = CoreDataManager() var favorites = [Entity]() let format = Format.init() + var currentLatitude = Double() + var currentLongitude = Double() @IBOutlet weak var tableView: UITableView! func goToRequestViewController(pk: Int){ - let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController - pedidosVC.id = pk - + let requestsVC = self.storyboard?.instantiateViewController(withIdentifier: "requestsVC")as! RequestViewController + requestsVC.id = pk + requestsVC.currentLatitude = currentLatitude + requestsVC.currentLongitude = currentLongitude if isFavorite(id: pk){ - pedidosVC.isFavorite = true + requestsVC.isFavorite = true } print("ID del pedido: \(pk)") - pedidosVC.helpRequest() + requestsVC.helpRequest() //show(pedidosVC, sender: nil) - present(pedidosVC, animated: true, completion: nil) + present(requestsVC, animated: true, completion: nil) } func isFavorite(id: Int)->Bool{ var bool = Bool() diff --git a/ayudapy/ViewControllers/RequestViewController.swift b/ayudapy/ViewControllers/RequestViewController.swift index 0160297..73c4fa9 100644 --- a/ayudapy/ViewControllers/RequestViewController.swift +++ b/ayudapy/ViewControllers/RequestViewController.swift @@ -36,12 +36,12 @@ class RequestViewController: UIViewController { let checkImage = UIImage(named: "iconListoUnchecked") let checkLabel = UILabel() - + //solicitud api segun nro de pedido de ayuda "pk" func helpRequest(){ let url = "https://ayudapy.org/api/v1/helprequests/" HTTPClient.request(endpoint: url + "\(id)", onSuccess: { (response: Request?) in if let requestInformation = response{ - print("Estos son los datos\(requestInformation)") + print("Estos son los datos: \(requestInformation)") self.name = response!.name self.message = response!.message self.hRequestTitle = response!.title @@ -52,7 +52,6 @@ class RequestViewController: UIViewController { self.imageUrl = response!.picture self.longitude = response!.location.coordinates[0] self.latitude = response!.location.coordinates[1] - self.isFavorite = self.isFavoriteCheck() self.showRequestInformation() } else { @@ -62,7 +61,9 @@ class RequestViewController: UIViewController { }) } + //Muestra la información recibida en pantalla func showRequestInformation(){ + //fecha (se convierte el string de la fecha completa a otro con la unidad de tiempo seleccionada let day = date.getDatePart(dateUnit: .day) let month = (date.getDatePart(dateUnit: .month)).getMonthInSpanish() let year = date.getDatePart(dateUnit: .year) @@ -71,22 +72,28 @@ class RequestViewController: UIViewController { dateLabel.text = "Publicado el \(day) de \(month) de \(year) a las \(hour)" dateLabel.font = format.dateFontStyle dateLabel.textColor = format.dateTextColor + + //titulo del pedido let titleLbl = UILabel() titleLbl.text = "\(hRequestTitle)" titleLbl.font = format.titleFontStyle titleLbl.textColor = format.titleTextColor + //detalle del pedido let messageLabel = UILabel() messageLabel.text = "\(message)" messageLabel.font = format.bodyFontStyle messageLabel.numberOfLines = .max messageLabel.lineBreakMode = .byWordWrapping messageLabel.sizeToFit() + + //Para mostrar la imagen en caso de que el campo no sea nulo let imageView = UIImageView() if imageUrl != nil { imageView.layer.frame = CGRect(x: 0, y: 0, width: 100, height: 100) imageView.kf.indicatorType = .activity imageView.kf.setImage(with: URL(string: imageUrl!)) } + //Se agrupan las vistas en la cabecera let headerStackView = UIStackView(arrangedSubviews: [dateLabel, titleLbl, messageLabel]) headerStackView.axis = .vertical headerStackView.spacing = 5 @@ -128,17 +135,18 @@ class RequestViewController: UIViewController { contactInformationStackView.axis = .vertical contactInformationStackView.spacing = 5 - - //checkButton.frame.size = CGSize(width: 80, height: 80) + //Se muestra el botón y la etiqueta de marcar como listo checkLabel.text = "Marcar como listo" checkLabel.font = format.bodyFontStyle checkLabel.textAlignment = .center + checkButton.setImage(checkImage, for: .normal) let checkStackView = UIStackView(arrangedSubviews: [checkButton, checkLabel]) checkStackView.axis = .vertical checkStackView.distribution = .fillEqually checkStackView.spacing = 0 + //se muestra el botón y etiqueta para Agregar a pendientes isFavoriteButton.frame.size = CGSize(width: 80, height: 80) if isFavorite{ isFavoriteButton.setImage(UIImage(named: "iconPendientesChecked"), for: .normal) @@ -149,7 +157,6 @@ class RequestViewController: UIViewController { isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside) isFavoriteLabel.text = "Agregar a mis Pendientes" } - isFavoriteLabel.font = format.bodyFontStyle isFavoriteLabel.numberOfLines = 2 isFavoriteLabel.textAlignment = .center @@ -157,39 +164,22 @@ class RequestViewController: UIViewController { isFavoriteStackView.axis = .vertical isFavoriteStackView.distribution = .fillEqually isFavoriteStackView.spacing = 0 - - - checkButton.setImage(checkImage, for: .normal) - let footerStackView = UIStackView(arrangedSubviews: [isFavoriteStackView, checkStackView]) footerStackView.axis = .horizontal footerStackView.distribution = .fillEqually - footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true - //viewHeightAnchor += Int(isFavoriteStackView.frame.height) - //viewHeightAnchor += 30 + footerStackView.heightAnchor.constraint(equalToConstant: 80).isActive = true + //Se agregan las vistas en un stack view vertical para que se vean ordenadamente, adaptando a la pantalla del dispositivo 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.layer.frame = CGRect(x: 20, y: 20, width: view.frame.width - 20 , height: view.frame.height*0.9) view.addSubview(stackView) } - func isFavoriteCheck()->Bool{ - var bool = false - for i in 0 ..< favorites.count { - if favorites[i].id == Int64(id) { - bool = true - } - else { - bool = false - } - } - return bool - } - + func isReadyCheck()->Bool{ return false } @@ -200,6 +190,7 @@ class RequestViewController: UIViewController { self.isFavorite = false sender.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal) self.isFavoriteLabel.text = "Agregar a mis Pendientes" + reloadInputViews() }else { manager.saveFavorites(id: id, name: name, date: date, address: address, message: message, title: hRequestTitle, phoneNumber: phoneNumber, latitude: latitude, longitude: longitude) { [weak self] in @@ -209,10 +200,10 @@ class RequestViewController: UIViewController { self.isFavorite = true sender.setImage(UIImage(named: "iconPendientesChecked"), for: .normal) self.isFavoriteLabel.text = "Quitar de mis Pendientes" + reloadInputViews() } } @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) } @@ -251,6 +242,11 @@ class RequestViewController: UIViewController { self.present(alert, animated: true) } + + override func viewWillAppear(_ animated: Bool) { + favorites = manager.fetchFavorites() + isFavorite = manager.checkData(id: id, entityList: favorites) + } override func viewDidLoad() { } -- libgit2 0.26.0