Commit 574b8ff0 by Julio Hermosa

-Se corrigen errores de persistencia de datos en coredata (los cambios de iconos…

-Se corrigen errores de persistencia de datos en coredata (los cambios de iconos de los pines, botones, etc al actualizarse la base de datos)
-Se agrego la función de eliminar favoritos de mis pendientes scrolleando la celda o al pulsar el botón de quitar de favoritos
-Se implementa funciones para obtener día, mes y año de las fechas, manipulándolos como strings
-Se corrigen algunos detalles de diseño
parent 6524daa8
......@@ -2,10 +2,10 @@
<Workspace
version = "1.0">
<FileRef
location = "group:ayudapy/Entity+CoreDataClass.swift">
location = "group:ayudapy/CoreData/Entity+CoreDataClass.swift">
</FileRef>
<FileRef
location = "group:ayudapy/Entity+CoreDataProperties.swift">
location = "group:ayudapy/CoreData/Entity+CoreDataProperties.swift">
</FileRef>
<FileRef
location = "group:ayudapy.xcodeproj">
......
......@@ -3,4 +3,25 @@
uuid = "39C5608C-6BDA-4DA8-94F3-02BAE7D82DBB"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.AddressBreakpoint">
<BreakpointContent
uuid = "27D6CC79-B1DE-4915-B5F7-E25621245CF2"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "*0x103007dd5">
<Locations>
<Location
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
usesParentBreakpointCondition = "Yes"
offsetFromSymbolStart = "0">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
......@@ -56,98 +56,68 @@
<rect key="frame" x="0.0" y="0.0" width="500" height="110"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bU8-yM-Yme">
<rect key="frame" x="0.0" y="8" width="499" height="116"/>
<stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Nx-7P-kFB">
<rect key="frame" x="20" y="11" width="460" height="88"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="C7N-NJ-YuH">
<rect key="frame" x="0.0" y="0.0" width="499" height="116"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="5uy-us-Ehr">
<rect key="frame" x="0.0" y="0.0" width="70" height="88"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="5uy-us-Ehr">
<rect key="frame" x="32" y="17" width="49.5" height="62.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="25" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rt6-8B-njG">
<rect key="frame" x="0.0" y="0.0" width="49.5" height="42"/>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="35"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Month" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A6k-4E-FiW">
<rect key="frame" x="0.0" y="42" width="49.5" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="Arg-Pc-Vth">
<rect key="frame" x="91.5" y="0.0" width="407.5" height="116"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dIv-9y-AeI">
<rect key="frame" x="0.0" y="0.0" width="33.5" height="59.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Details" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="6" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="J2F-4P-f1j">
<rect key="frame" x="0.0" y="59.5" width="50" height="56.5"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VLe-bj-MvJ">
<rect key="frame" x="360" y="-6" width="103" height="108"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="1" green="0.24040085119999999" blue="0.2524891279" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<state key="normal" title="Delete">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<connections>
<action selector="deleteRow:" destination="D8e-6i-a9c" eventType="touchUpInside" id="eGP-bs-lFf"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="25" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rt6-8B-njG">
<rect key="frame" x="0.0" y="0.0" width="70" height="42"/>
<constraints>
<constraint firstAttribute="height" constant="42" id="Wfx-VK-I1j"/>
</constraints>
<fontDescription key="fontDescription" type="system" weight="heavy" pointSize="35"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Month" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="A6k-4E-FiW">
<rect key="frame" x="0.0" y="42" width="70" height="46"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<constraints>
<constraint firstItem="Arg-Pc-Vth" firstAttribute="leading" secondItem="5uy-us-Ehr" secondAttribute="trailing" constant="10" id="Dt9-oj-7qE"/>
<constraint firstAttribute="trailing" secondItem="Arg-Pc-Vth" secondAttribute="trailing" id="Mck-4x-NwY"/>
<constraint firstItem="Arg-Pc-Vth" firstAttribute="top" secondItem="C7N-NJ-YuH" secondAttribute="top" id="SMK-db-fln"/>
<constraint firstItem="5uy-us-Ehr" firstAttribute="leading" secondItem="C7N-NJ-YuH" secondAttribute="leading" constant="32" id="TQI-Bh-ycO"/>
<constraint firstAttribute="bottom" secondItem="5uy-us-Ehr" secondAttribute="bottom" constant="36.5" id="Zsu-RA-gIe"/>
<constraint firstItem="5uy-us-Ehr" firstAttribute="top" secondItem="C7N-NJ-YuH" secondAttribute="top" constant="17" id="pHg-od-S6v"/>
<constraint firstAttribute="bottom" secondItem="Arg-Pc-Vth" secondAttribute="bottom" id="wNj-fg-TIG"/>
<constraint firstAttribute="width" constant="70" id="WeG-F5-Sa1"/>
<constraint firstAttribute="height" constant="88" id="ZkU-Gs-4vz"/>
</constraints>
</view>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="Arg-Pc-Vth">
<rect key="frame" x="70" y="0.0" width="390" height="88"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dIv-9y-AeI">
<rect key="frame" x="0.0" y="0.0" width="33.5" height="45"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="TopLeft" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Details" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="6" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="J2F-4P-f1j">
<rect key="frame" x="0.0" y="45" width="50" height="43"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="C7N-NJ-YuH" secondAttribute="bottom" id="90R-LQ-SCc"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="leading" secondItem="bU8-yM-Yme" secondAttribute="leading" id="Eab-SY-pQV"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="top" secondItem="bU8-yM-Yme" secondAttribute="top" id="Mr3-vO-LvB"/>
<constraint firstAttribute="trailing" secondItem="C7N-NJ-YuH" secondAttribute="trailing" id="Oxv-sN-EjK"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="trailing" secondItem="50T-ZC-KZu" secondAttribute="trailing" id="VUP-Oz-xXO"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="bottom" secondItem="50T-ZC-KZu" secondAttribute="bottom" id="uIa-C8-d0Y"/>
<constraint firstItem="5uy-us-Ehr" firstAttribute="top" secondItem="6Nx-7P-kFB" secondAttribute="top" id="TfY-P8-ksI"/>
<constraint firstItem="5uy-us-Ehr" firstAttribute="leading" secondItem="6Nx-7P-kFB" secondAttribute="leading" id="VVJ-Q5-bRh"/>
<constraint firstItem="Arg-Pc-Vth" firstAttribute="leading" secondItem="5uy-us-Ehr" secondAttribute="trailing" id="nX0-uu-DC8"/>
<constraint firstAttribute="bottom" secondItem="5uy-us-Ehr" secondAttribute="bottom" id="yJZ-zv-3j7"/>
</constraints>
<viewLayoutGuide key="contentLayoutGuide" id="26x-S3-ikO"/>
<viewLayoutGuide key="frameLayoutGuide" id="50T-ZC-KZu"/>
</scrollView>
</stackView>
</subviews>
<constraints>
<constraint firstAttribute="leading" secondItem="bU8-yM-Yme" secondAttribute="trailing" id="ElR-zd-A6I"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="leading" secondItem="aAc-DI-Gps" secondAttribute="leading" id="QQw-tp-GAm"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="top" secondItem="aAc-DI-Gps" secondAttribute="top" id="TyR-QX-96O"/>
<constraint firstAttribute="bottom" secondItem="bU8-yM-Yme" secondAttribute="bottom" id="xGU-Zw-Qhz"/>
<constraint firstAttribute="bottomMargin" secondItem="6Nx-7P-kFB" secondAttribute="bottom" id="5HG-o6-ogM"/>
<constraint firstItem="6Nx-7P-kFB" firstAttribute="leading" secondItem="aAc-DI-Gps" secondAttribute="leadingMargin" id="6No-Dk-Lmn"/>
<constraint firstItem="6Nx-7P-kFB" firstAttribute="top" secondItem="aAc-DI-Gps" secondAttribute="topMargin" id="Wb1-hi-8G8"/>
<constraint firstAttribute="trailingMargin" secondItem="6Nx-7P-kFB" secondAttribute="trailing" id="u2z-q8-lXf"/>
</constraints>
</tableViewCellContentView>
<constraints>
<constraint firstAttribute="trailing" secondItem="bU8-yM-Yme" secondAttribute="trailing" constant="1" id="2TT-oW-Udo"/>
<constraint firstAttribute="bottom" secondItem="bU8-yM-Yme" secondAttribute="bottom" constant="-14" id="FM1-nh-Pii"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="top" secondItem="D8e-6i-a9c" secondAttribute="top" constant="8" id="h7S-b7-B9X"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="leading" secondItem="D8e-6i-a9c" secondAttribute="leading" id="qhI-My-wfT"/>
</constraints>
<connections>
<outlet property="dayLabel" destination="rt6-8B-njG" id="R9g-fH-iWH"/>
<outlet property="deleteButton" destination="VLe-bj-MvJ" id="Oxh-mM-u2B"/>
<outlet property="detailLabel" destination="J2F-4P-f1j" id="sDw-bP-ghK"/>
<outlet property="monthLabel" destination="A6k-4E-FiW" id="ffX-IQ-uuq"/>
<outlet property="titleLabel" destination="dIv-9y-AeI" id="jR9-VN-COa"/>
......
......@@ -25,15 +25,16 @@ class CoreDataManager {
}
}
func saveFavorites(id: Int, name: String, date: Date, address: String, message: String, completion: @escaping()-> Void){
func saveFavorites(id: Int, name: String, date: String, address: String, message: String, title: String, phoneNumber: String, completion: @escaping()-> Void){
let context = container.viewContext
let favorite = Entity(context: context)
//let ifavorite = MyPendings(context: context)
favorite.id = Int64(id)
favorite.name = name
favorite.date = date
favorite.address = address
favorite.message = message
favorite.title = title
favorite.phoneNumber = phoneNumber
do{
try context.save()
print("\(id) guardado")
......@@ -46,7 +47,14 @@ class CoreDataManager {
let context = container.viewContext
for i in 0..<array.count {
if array[i].id == Int64(id){
context.delete(array[i])
context.delete(array[i])
do{
try context.save()
print("\(id) borrado")
}catch{
print("error al borrar \(error)")
}
}
}
......
......@@ -2,7 +2,7 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15400" systemVersion="19E266" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Entity" representedClassName="Entity" syncable="YES" codeGenerationType="class">
<attribute name="address" optional="YES" attributeType="String"/>
<attribute name="date" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="date" attributeType="String"/>
<attribute name="id" attributeType="Integer 64" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="message" optional="YES" attributeType="String"/>
<attribute name="name" optional="YES" attributeType="String"/>
......
......@@ -23,14 +23,10 @@ class MapViewController: UIViewController {
var bbox = String()
var id = Int()
let defaultLocation = CLLocation(latitude: -57.5879897, longitude: -43.2723609)
//-57.5879897,-43.2723609 -> Posición de Roshka
func addPins(){
}
//logo cabecera ayudapy.org
func addHeader(){
......@@ -112,9 +108,12 @@ class MapViewController: UIViewController {
@objc func goToRequestViewController(pk: Int){
let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController
pedidosVC.id = id
print(id)
print("ID del pedido: \(id)")
pedidosVC.helpRequest()
show(pedidosVC, sender: nil)
//show(pedidosVC, sender: nil)
isModalInPresentation = true
present(pedidosVC, animated: true, completion: nil)
}
//Función para hallar el boundingbox actual
......@@ -142,9 +141,9 @@ class MapViewController: UIViewController {
let markerView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 30))
let markerButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 30))
markerView.addSubview(markerButton)
markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside)
let markerImage = UIImage(named: "pinGMAPS")
markerButton.setImage(markerImage, for: .normal)
markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside)
let pin = self.addPins(id: self.id)
markerButton.setImage(pin, for: .normal)
let marker = GMSMarker(position: position)
marker.map = self.mapView
......@@ -172,6 +171,19 @@ class MapViewController: UIViewController {
mapView.isHidden = true
}
//Verificamos si el marcador corresponde a un favorito y agregamos la imagen correspondiente
func addPins(id: Int)->UIImage{
let array = manager.fetchFavorites()
var pinImage = UIImage(named: "pinGMAPS")
for i in 0 ..< array.count{
if array[i].id == Int64(id) {
pinImage = UIImage(named: "pinFavGMAPS")
}
}
return pinImage!
}
override func viewDidLoad() {
super.viewDidLoad()
......
......@@ -13,16 +13,18 @@ class MyPendingsTableViewCell: UITableViewCell {
var id = Int()
let format = Format.init()
let manager = CoreDataManager()
var array = [Entity]()
@IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel!
@IBOutlet weak var deleteButton: UIButton!
@IBAction func deleteRow(_ sender: Any) {
let array = manager.fetchFavorites()
print(id)
manager.deleteFavorites(id: id, array: array)
}
// @IBAction func deleteRow(_ sender: Any) {
// array = manager.fetchFavorites()
// print(id)
// manager.deleteFavorites(id: id, array: array)
// }
......
......@@ -11,9 +11,10 @@ import CoreData
struct MyPendings{
var id: Int
var title: String?
var message: String?
var date: String
var date: String?
var address: String?
var contactNumber: String?
var contactName: String?
......@@ -21,7 +22,9 @@ struct MyPendings{
class PendingsViewController: UIViewController {
let manager = CoreDataManager()
var array = [Entity]()
var myPendings = [MyPendings]()
let format = Format.init()
......@@ -29,11 +32,12 @@ class PendingsViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let array = manager.fetchFavorites()
for i in 0..<manager.fetchFavorites().count {
myPendings.append(MyPendings(id: Int(array[i].id), title: array[i].title, message: array[i].message, date: "\(array[i].date!)", address: array[i].address, contactNumber: array[i].name, contactName: array[i].phoneNumber))
}
array = manager.fetchFavorites()
// for i in 0..<manager.fetchFavorites().count {
// myPendings.append(MyPendings(id: Int(array[i].id), title: array[i].title, message: array[i].message, date: array[i].date, address: array[i].address, contactNumber: array[i].name, contactName: array[i].phoneNumber))
// }
// print("Mis pendintes\(myPendings)")
}
override func viewDidLoad() {
......@@ -51,22 +55,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 = myPendings[indexPath.row].date
let month = date.getDatePart(dateUnit: .month)
let date = array[indexPath.row].date
let month = date!.getDatePart(dateUnit: .month)
let monthString = month.getMonthShortString()
let day = date.getDatePart(dateUnit: .day)
let day = date!.getDatePart(dateUnit: .day)
var detailLabel:String = ""
cell.titleLabel.text = myPendings[indexPath.row].title
cell.titleLabel.text = array[indexPath.row].title
cell.titleLabel.textColor = format.subTitleTextColor
cell.titleLabel.font = format.subTitleFontStyle
if let address = myPendings[indexPath.row].address {
if let address = array[indexPath.row].address {
detailLabel = address
}
if let contactName = myPendings[indexPath.row].contactName {
if let contactName = array[indexPath.row].name {
detailLabel = detailLabel + "\n\(contactName)"
}
if let contactNumber = myPendings[indexPath.row].contactNumber {
if let contactNumber = array[indexPath.row].phoneNumber {
detailLabel = detailLabel + "\n\(contactNumber)"
}
cell.detailLabel.text = detailLabel
......@@ -74,9 +78,9 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
cell.dayLabel.text = day
cell.monthLabel.text = monthString
let id = myPendings[indexPath.row].id
cell.id = id
let id = array[indexPath.row].id
cell.id = Int(id)
return cell
}
......@@ -87,12 +91,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
headerLabel.textAlignment = .center
let centerX = view.frame.width / 2
headerLabel.center.x = centerX
let heartImage = UIImageView(frame: CGRect(x: centerX + 60, y: 10, width: 22, height: 22))
let heartImage = UIImageView(frame: CGRect(x: centerX + 100, y: 10, width: 22, height: 22))
heartImage.center.y = headerLabel.frame.height/2
heartImage.image = UIImage(named: "iconPendientesChecked")
headerLabel.addSubview(heartImage)
return headerLabel
}
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)
tableView.deleteRows(at: [indexPath], with: .fade)
default:
print("no pasa nada")
}
}
}
......@@ -8,6 +8,7 @@
import UIKit
import Kingfisher
import CoreData
class RequestViewController: UIViewController {
var id = Int()
......@@ -26,12 +27,18 @@ class RequestViewController: UIViewController {
var favorites = [Int]()
private let manager = CoreDataManager()
let isFavoriteButton = UIButton()
let isFavoriteLabel = UILabel()
let checkButton = UIButton()
let checkImage = UIImage(named: "iconListoUnchecked")
let checkLabel = UILabel()
func helpRequest(){
let url = "https://ayudapy.org/api/v1/helprequests/"
HTTPClient.request(endpoint: url + "\(id)", onSuccess: { (response: Request?) in
if let requestInformation = response{
print("asdf\(requestInformation)")
print("Estos son los datos\(requestInformation)")
self.name = response!.name
self.message = response!.message
self.hRequestTitle = response!.title
......@@ -40,6 +47,7 @@ class RequestViewController: UIViewController {
self.phoneNumber = response!.phone
self.address = response!.address
self.imageUrl = response!.picture
self.isFavorite = self.isFavoriteCheck()
self.showRequestInformation()
}
else {
......@@ -50,6 +58,8 @@ 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)
......@@ -74,7 +84,13 @@ class RequestViewController: UIViewController {
imageView.kf.indicatorType = .activity
imageView.kf.setImage(with: URL(string: imageUrl!))
}
let headerStackView = UIStackView(arrangedSubviews: [dateLabel, titleLbl, messageLabel])
headerStackView.axis = .vertical
headerStackView.spacing = 5
headerStackView.distribution = .equalSpacing
viewHeightAnchor += Int(headerStackView.frame.height)
//Dirección y como llegar
let addressSubTittle = UILabel()
addressSubTittle.text = "Dirección"
addressSubTittle.textColor = format.subTitleTextColor
......@@ -83,32 +99,49 @@ class RequestViewController: UIViewController {
addressLabel.text = "\(address)"
addressLabel.lineBreakMode = .byWordWrapping
addressLabel.numberOfLines = .max
let howToGetButton = UIButton()
howToGetButton.backgroundColor = format.subTitleTextColor
howToGetButton.layer.cornerRadius = 10
howToGetButton.setTitle("Como llegar", for: .normal)
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()
contactLabel.text = "Contacto"
contactLabel.textColor = format.subTitleTextColor
contactLabel.font = format.subTitleFontStyle
let contactNameLabel = UILabel()
contactNameLabel.text = "\(name)"
let contactButton = UIButton()
contactButton.backgroundColor = format.subTitleTextColor
contactButton.titleLabel?.font = format.subTitleFontStyle
contactButton.layer.cornerRadius = 10
contactButton.setTitle("\(phoneNumber)", for: .normal)
let contactNumberButton = UIButton()
contactNumberButton.backgroundColor = format.subTitleTextColor
contactNumberButton.titleLabel?.font = format.subTitleFontStyle
contactNumberButton.layer.cornerRadius = 10
contactNumberButton.setTitle("\(phoneNumber)", for: .normal)
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)
checkLabel.text = "Marcar como listo"
checkLabel.font = format.bodyFontStyle
checkLabel.textAlignment = .center
let checkStackView = UIStackView(arrangedSubviews: [checkButton, checkLabel])
checkStackView.axis = .vertical
checkStackView.distribution = .fillEqually
checkStackView.spacing = 0
let isFavoriteButton = UIButton()
let heartImage = UIImage(named: "iconPendientesUnchecked")
isFavoriteButton.setImage(heartImage, for: .normal)
//isFavoriteButton.setImage(heartImage, for: .normal)
isFavoriteButton.frame.size = CGSize(width: 80, height: 80)
isFavoriteButton.addTarget(self, action: #selector(addFavorite), for: .touchUpInside)
isFavoriteButton.setImage(UIImage(named: "iconPendientesUnchecked"), for: .normal)
isFavoriteButton.addTarget(self, action: #selector(addOrRemoveFavorite(sender: )), for: .touchUpInside)
let isFavoriteLabel = UILabel()
isFavoriteLabel.text = "Agregar a mis pendientes"
isFavoriteLabel.font = format.bodyFontStyle
isFavoriteLabel.numberOfLines = 2
......@@ -118,54 +151,70 @@ class RequestViewController: UIViewController {
isFavoriteStackView.distribution = .fillEqually
isFavoriteStackView.spacing = 0
let checkButton = UIButton()
let checkImage = UIImage(named: "iconListoUnchecked")
checkButton.setImage(checkImage, for: .normal)
checkButton.frame.size = CGSize(width: 80, height: 80)
let checkLabel = UILabel()
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
let footerStackView = UIStackView(arrangedSubviews: [isFavoriteStackView, checkStackView])
footerStackView.axis = .horizontal
footerStackView.distribution = .fillEqually
footerStackView.spacing = 50
//let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height))
let footerSpacing = UIView()
footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true
viewHeightAnchor += Int(isFavoriteStackView.frame.height)
viewHeightAnchor += 30
let stackView = UIStackView(arrangedSubviews: [dateLabel, titleLbl, messageLabel, addressSubTittle, addressLabel,howToGetButton,contactLabel,contactNameLabel, contactButton, footerStackView, footerSpacing])
let stackView = UIStackView(arrangedSubviews: [headerStackView, addressStackView, contactInformationStackView, footerStackView])
stackView.axis = .vertical
stackView.distribution = .fillProportionally
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)
//view.addSubview(scrollView)
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(titleLbl)
}
func isFavoriteCheck()->Bool{
return false
let favoritos = manager.fetchFavorites()
var bool = false
for i in 0 ..< favoritos.count {
if favoritos[i].id == Int64(id) {
bool = true
}
else {
bool = false
}
}
return bool
}
func isReadyCheck()->Bool{
return false
}
func convertDate(stringDate: String)->Date{
let dateFormatter = Date()
//dateFormatter.date(from: "stringDate")
return dateFormatter
}
@objc func addFavorite(){
manager.saveFavorites(id: id, name: name, date: convertDate(stringDate: date), address: address, message: hRequestTitle) { [weak self] in
print(self as Any)
@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
print("\(self as Any) guardado!")
self?.isFavorite = true
}
self.isFavorite = true
sender.setImage(UIImage(named: "iconPendientesChecked"), for: .normal)
self.isFavoriteLabel.text = "Quitar de mis Pendientes"
}
}
......@@ -174,3 +223,5 @@ class RequestViewController: UIViewController {
}
}
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