Commit 9d76d329 by Julio Hermosa

Se ordena y documenta el código

parent f2c90045
......@@ -10,7 +10,7 @@
<!--Request View Controller-->
<scene sceneID="MGi-Q6-5W5">
<objects>
<viewController storyboardIdentifier="pedidosVC" id="efO-tm-e7g" customClass="RequestViewController" customModule="ayudapy" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="requestsVC" id="efO-tm-e7g" customClass="RequestViewController" customModule="ayudapy" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="2Bp-lZ-T6S">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
......@@ -41,7 +41,7 @@
<!--Pendings View Controller-->
<scene sceneID="1wO-Og-nyO">
<objects>
<viewController storyboardIdentifier="pendientesVC" id="Ncc-gI-9dq" customClass="PendingsViewController" customModule="ayudapy" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="pendingsVC" id="Ncc-gI-9dq" customClass="PendingsViewController" customModule="ayudapy" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="s2s-eb-0xG">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
......
......@@ -69,6 +69,16 @@ class CoreDataManager {
}
return []
}
func checkData(id: Int, entityList: [Entity])->Bool{
let array = entityList
var bool = false
for i in 0..<array.count {
if array[i].id == Int64(id){
bool = true
}
}
return bool
}
// func saveInCheckedList(id: Int, latitude: Double, longitude: Double, completion: @escaping()-> Void){
// let context = container.viewContext
......
......@@ -20,6 +20,8 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
......@@ -50,11 +52,7 @@
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
......
......@@ -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
// }
}
......@@ -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) {
......
......@@ -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()
......
......@@ -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() {
}
......
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