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 @@ ...@@ -2,10 +2,10 @@
<Workspace <Workspace
version = "1.0"> version = "1.0">
<FileRef <FileRef
location = "group:ayudapy/Entity+CoreDataClass.swift"> location = "group:ayudapy/CoreData/Entity+CoreDataClass.swift">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:ayudapy/Entity+CoreDataProperties.swift"> location = "group:ayudapy/CoreData/Entity+CoreDataProperties.swift">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:ayudapy.xcodeproj"> location = "group:ayudapy.xcodeproj">
......
...@@ -3,4 +3,25 @@ ...@@ -3,4 +3,25 @@
uuid = "39C5608C-6BDA-4DA8-94F3-02BAE7D82DBB" uuid = "39C5608C-6BDA-4DA8-94F3-02BAE7D82DBB"
type = "0" type = "0"
version = "2.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> </Bucket>
...@@ -56,98 +56,68 @@ ...@@ -56,98 +56,68 @@
<rect key="frame" x="0.0" y="0.0" width="500" height="110"/> <rect key="frame" x="0.0" y="0.0" width="500" height="110"/>
<autoresizingMask key="autoresizingMask"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bU8-yM-Yme"> <stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6Nx-7P-kFB">
<rect key="frame" x="0.0" y="8" width="499" height="116"/> <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"/>
<subviews> <subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="5uy-us-Ehr"> <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"/> <rect key="frame" x="0.0" y="0.0" width="70" height="88"/>
<subviews> <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"> <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"/> <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"/> <fontDescription key="fontDescription" type="system" weight="heavy" pointSize="35"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </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"> <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"/> <rect key="frame" x="0.0" y="42" width="70" height="46"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
<constraints>
<constraint firstAttribute="width" constant="70" id="WeG-F5-Sa1"/>
<constraint firstAttribute="height" constant="88" id="ZkU-Gs-4vz"/>
</constraints>
</stackView> </stackView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillProportionally" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="Arg-Pc-Vth"> <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"/> <rect key="frame" x="70" y="0.0" width="390" height="88"/>
<subviews> <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"> <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"/> <rect key="frame" x="0.0" y="0.0" width="33.5" height="45"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </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"> <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="59.5" width="50" height="56.5"/> <rect key="frame" x="0.0" y="45" width="50" height="43"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/> <fontDescription key="fontDescription" type="system" pointSize="16"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
</subviews> </subviews>
</stackView> </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>
</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"/>
</constraints>
</view>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstAttribute="bottom" secondItem="C7N-NJ-YuH" secondAttribute="bottom" id="90R-LQ-SCc"/> <constraint firstItem="5uy-us-Ehr" firstAttribute="top" secondItem="6Nx-7P-kFB" secondAttribute="top" id="TfY-P8-ksI"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="leading" secondItem="bU8-yM-Yme" secondAttribute="leading" id="Eab-SY-pQV"/> <constraint firstItem="5uy-us-Ehr" firstAttribute="leading" secondItem="6Nx-7P-kFB" secondAttribute="leading" id="VVJ-Q5-bRh"/>
<constraint firstItem="C7N-NJ-YuH" firstAttribute="top" secondItem="bU8-yM-Yme" secondAttribute="top" id="Mr3-vO-LvB"/> <constraint firstItem="Arg-Pc-Vth" firstAttribute="leading" secondItem="5uy-us-Ehr" secondAttribute="trailing" id="nX0-uu-DC8"/>
<constraint firstAttribute="trailing" secondItem="C7N-NJ-YuH" secondAttribute="trailing" id="Oxv-sN-EjK"/> <constraint firstAttribute="bottom" secondItem="5uy-us-Ehr" secondAttribute="bottom" id="yJZ-zv-3j7"/>
<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"/>
</constraints> </constraints>
<viewLayoutGuide key="contentLayoutGuide" id="26x-S3-ikO"/> </stackView>
<viewLayoutGuide key="frameLayoutGuide" id="50T-ZC-KZu"/>
</scrollView>
</subviews> </subviews>
<constraints> <constraints>
<constraint firstAttribute="leading" secondItem="bU8-yM-Yme" secondAttribute="trailing" id="ElR-zd-A6I"/> <constraint firstAttribute="bottomMargin" secondItem="6Nx-7P-kFB" secondAttribute="bottom" id="5HG-o6-ogM"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="leading" secondItem="aAc-DI-Gps" secondAttribute="leading" id="QQw-tp-GAm"/> <constraint firstItem="6Nx-7P-kFB" firstAttribute="leading" secondItem="aAc-DI-Gps" secondAttribute="leadingMargin" id="6No-Dk-Lmn"/>
<constraint firstItem="bU8-yM-Yme" firstAttribute="top" secondItem="aAc-DI-Gps" secondAttribute="top" id="TyR-QX-96O"/> <constraint firstItem="6Nx-7P-kFB" firstAttribute="top" secondItem="aAc-DI-Gps" secondAttribute="topMargin" id="Wb1-hi-8G8"/>
<constraint firstAttribute="bottom" secondItem="bU8-yM-Yme" secondAttribute="bottom" id="xGU-Zw-Qhz"/> <constraint firstAttribute="trailingMargin" secondItem="6Nx-7P-kFB" secondAttribute="trailing" id="u2z-q8-lXf"/>
</constraints> </constraints>
</tableViewCellContentView> </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> <connections>
<outlet property="dayLabel" destination="rt6-8B-njG" id="R9g-fH-iWH"/> <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="detailLabel" destination="J2F-4P-f1j" id="sDw-bP-ghK"/>
<outlet property="monthLabel" destination="A6k-4E-FiW" id="ffX-IQ-uuq"/> <outlet property="monthLabel" destination="A6k-4E-FiW" id="ffX-IQ-uuq"/>
<outlet property="titleLabel" destination="dIv-9y-AeI" id="jR9-VN-COa"/> <outlet property="titleLabel" destination="dIv-9y-AeI" id="jR9-VN-COa"/>
......
...@@ -25,15 +25,16 @@ class CoreDataManager { ...@@ -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 context = container.viewContext
let favorite = Entity(context: context) let favorite = Entity(context: context)
//let ifavorite = MyPendings(context: context)
favorite.id = Int64(id) favorite.id = Int64(id)
favorite.name = name favorite.name = name
favorite.date = date favorite.date = date
favorite.address = address favorite.address = address
favorite.message = message favorite.message = message
favorite.title = title
favorite.phoneNumber = phoneNumber
do{ do{
try context.save() try context.save()
print("\(id) guardado") print("\(id) guardado")
...@@ -47,6 +48,13 @@ class CoreDataManager { ...@@ -47,6 +48,13 @@ class CoreDataManager {
for i in 0..<array.count { for i in 0..<array.count {
if array[i].id == Int64(id){ 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 @@ ...@@ -2,7 +2,7 @@
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15400" systemVersion="19E266" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier=""> <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"> <entity name="Entity" representedClassName="Entity" syncable="YES" codeGenerationType="class">
<attribute name="address" optional="YES" attributeType="String"/> <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="id" attributeType="Integer 64" defaultValueString="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"/>
......
...@@ -23,13 +23,9 @@ class MapViewController: UIViewController { ...@@ -23,13 +23,9 @@ class MapViewController: UIViewController {
var bbox = String() var bbox = String()
var id = Int() var id = Int()
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
func addPins(){
}
//logo cabecera ayudapy.org //logo cabecera ayudapy.org
...@@ -112,9 +108,12 @@ class MapViewController: UIViewController { ...@@ -112,9 +108,12 @@ class MapViewController: UIViewController {
@objc func goToRequestViewController(pk: Int){ @objc func goToRequestViewController(pk: Int){
let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController let pedidosVC = self.storyboard?.instantiateViewController(withIdentifier: "pedidosVC")as! RequestViewController
pedidosVC.id = id pedidosVC.id = id
print(id) print("ID del pedido: \(id)")
pedidosVC.helpRequest() 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 //Función para hallar el boundingbox actual
...@@ -143,8 +142,8 @@ class MapViewController: UIViewController { ...@@ -143,8 +142,8 @@ class MapViewController: UIViewController {
let markerButton = UIButton(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) markerView.addSubview(markerButton)
markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside) markerButton.addTarget(self, action: #selector(self.goToInfo), for: .touchUpInside)
let markerImage = UIImage(named: "pinGMAPS") let pin = self.addPins(id: self.id)
markerButton.setImage(markerImage, for: .normal) markerButton.setImage(pin, for: .normal)
let marker = GMSMarker(position: position) let marker = GMSMarker(position: position)
marker.map = self.mapView marker.map = self.mapView
...@@ -173,6 +172,19 @@ class MapViewController: UIViewController { ...@@ -173,6 +172,19 @@ class MapViewController: UIViewController {
mapView.isHidden = true 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() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
locationManagerSettings() locationManagerSettings()
......
...@@ -13,16 +13,18 @@ class MyPendingsTableViewCell: UITableViewCell { ...@@ -13,16 +13,18 @@ class MyPendingsTableViewCell: UITableViewCell {
var id = Int() var id = Int()
let format = Format.init() let format = Format.init()
let manager = CoreDataManager() let manager = CoreDataManager()
var array = [Entity]()
@IBOutlet weak var dayLabel: UILabel! @IBOutlet weak var dayLabel: UILabel!
@IBOutlet weak var monthLabel: UILabel! @IBOutlet weak var monthLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var detailLabel: UILabel! @IBOutlet weak var detailLabel: UILabel!
@IBOutlet weak var deleteButton: UIButton! @IBOutlet weak var deleteButton: UIButton!
@IBAction func deleteRow(_ sender: Any) { // @IBAction func deleteRow(_ sender: Any) {
let array = manager.fetchFavorites() // array = manager.fetchFavorites()
print(id) // print(id)
manager.deleteFavorites(id: id, array: array) // manager.deleteFavorites(id: id, array: array)
} // }
......
...@@ -11,9 +11,10 @@ import CoreData ...@@ -11,9 +11,10 @@ import CoreData
struct MyPendings{ struct MyPendings{
var id: Int var id: Int
var title: String? var title: String?
var message: String? var message: String?
var date: String var date: String?
var address: String? var address: String?
var contactNumber: String? var contactNumber: String?
var contactName: String? var contactName: String?
...@@ -21,7 +22,9 @@ struct MyPendings{ ...@@ -21,7 +22,9 @@ struct MyPendings{
class PendingsViewController: UIViewController { class PendingsViewController: UIViewController {
let manager = CoreDataManager() let manager = CoreDataManager()
var array = [Entity]()
var myPendings = [MyPendings]() var myPendings = [MyPendings]()
let format = Format.init() let format = Format.init()
...@@ -29,11 +32,12 @@ class PendingsViewController: UIViewController { ...@@ -29,11 +32,12 @@ class PendingsViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
let array = manager.fetchFavorites() array = manager.fetchFavorites()
for i in 0..<manager.fetchFavorites().count { // 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)) // 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() { override func viewDidLoad() {
...@@ -51,22 +55,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -51,22 +55,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 = myPendings[indexPath.row].date let date = array[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 = myPendings[indexPath.row].title cell.titleLabel.text = array[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 = myPendings[indexPath.row].address { if let address = array[indexPath.row].address {
detailLabel = address detailLabel = address
} }
if let contactName = myPendings[indexPath.row].contactName { if let contactName = array[indexPath.row].name {
detailLabel = detailLabel + "\n\(contactName)" detailLabel = detailLabel + "\n\(contactName)"
} }
if let contactNumber = myPendings[indexPath.row].contactNumber { if let contactNumber = array[indexPath.row].phoneNumber {
detailLabel = detailLabel + "\n\(contactNumber)" detailLabel = detailLabel + "\n\(contactNumber)"
} }
cell.detailLabel.text = detailLabel cell.detailLabel.text = detailLabel
...@@ -74,8 +78,8 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -74,8 +78,8 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
cell.dayLabel.text = day cell.dayLabel.text = day
cell.monthLabel.text = monthString cell.monthLabel.text = monthString
let id = myPendings[indexPath.row].id let id = array[indexPath.row].id
cell.id = id cell.id = Int(id)
return cell return cell
} }
...@@ -87,12 +91,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{ ...@@ -87,12 +91,22 @@ extension PendingsViewController: UITableViewDelegate, UITableViewDataSource{
headerLabel.textAlignment = .center headerLabel.textAlignment = .center
let centerX = view.frame.width / 2 let centerX = view.frame.width / 2
headerLabel.center.x = centerX 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.center.y = headerLabel.frame.height/2
heartImage.image = UIImage(named: "iconPendientesChecked") heartImage.image = UIImage(named: "iconPendientesChecked")
headerLabel.addSubview(heartImage) headerLabel.addSubview(heartImage)
return headerLabel 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 @@ ...@@ -8,6 +8,7 @@
import UIKit import UIKit
import Kingfisher import Kingfisher
import CoreData
class RequestViewController: UIViewController { class RequestViewController: UIViewController {
var id = Int() var id = Int()
...@@ -26,12 +27,18 @@ class RequestViewController: UIViewController { ...@@ -26,12 +27,18 @@ class RequestViewController: UIViewController {
var favorites = [Int]() var favorites = [Int]()
private let manager = CoreDataManager() private let manager = CoreDataManager()
let isFavoriteButton = UIButton()
let isFavoriteLabel = UILabel()
let checkButton = UIButton()
let checkImage = UIImage(named: "iconListoUnchecked")
let checkLabel = UILabel()
func helpRequest(){ func helpRequest(){
let url = "https://ayudapy.org/api/v1/helprequests/" let url = "https://ayudapy.org/api/v1/helprequests/"
HTTPClient.request(endpoint: url + "\(id)", onSuccess: { (response: Request?) in HTTPClient.request(endpoint: url + "\(id)", onSuccess: { (response: Request?) in
if let requestInformation = response{ if let requestInformation = response{
print("asdf\(requestInformation)") print("Estos son los datos\(requestInformation)")
self.name = response!.name self.name = response!.name
self.message = response!.message self.message = response!.message
self.hRequestTitle = response!.title self.hRequestTitle = response!.title
...@@ -40,6 +47,7 @@ class RequestViewController: UIViewController { ...@@ -40,6 +47,7 @@ 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.isFavorite = self.isFavoriteCheck()
self.showRequestInformation() self.showRequestInformation()
} }
else { else {
...@@ -50,6 +58,8 @@ class RequestViewController: UIViewController { ...@@ -50,6 +58,8 @@ 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)
...@@ -74,7 +84,13 @@ class RequestViewController: UIViewController { ...@@ -74,7 +84,13 @@ class RequestViewController: UIViewController {
imageView.kf.indicatorType = .activity imageView.kf.indicatorType = .activity
imageView.kf.setImage(with: URL(string: imageUrl!)) 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() let addressSubTittle = UILabel()
addressSubTittle.text = "Dirección" addressSubTittle.text = "Dirección"
addressSubTittle.textColor = format.subTitleTextColor addressSubTittle.textColor = format.subTitleTextColor
...@@ -83,32 +99,49 @@ class RequestViewController: UIViewController { ...@@ -83,32 +99,49 @@ class RequestViewController: UIViewController {
addressLabel.text = "\(address)" addressLabel.text = "\(address)"
addressLabel.lineBreakMode = .byWordWrapping addressLabel.lineBreakMode = .byWordWrapping
addressLabel.numberOfLines = .max addressLabel.numberOfLines = .max
let howToGetButton = UIButton() let howToGetButton = UIButton()
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.titleLabel?.font = format.subTitleFontStyle 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() let contactLabel = UILabel()
contactLabel.text = "Contacto" contactLabel.text = "Contacto"
contactLabel.textColor = format.subTitleTextColor contactLabel.textColor = format.subTitleTextColor
contactLabel.font = format.subTitleFontStyle contactLabel.font = format.subTitleFontStyle
let contactNameLabel = UILabel() let contactNameLabel = UILabel()
contactNameLabel.text = "\(name)" contactNameLabel.text = "\(name)"
let contactButton = UIButton() let contactNumberButton = UIButton()
contactButton.backgroundColor = format.subTitleTextColor contactNumberButton.backgroundColor = format.subTitleTextColor
contactButton.titleLabel?.font = format.subTitleFontStyle contactNumberButton.titleLabel?.font = format.subTitleFontStyle
contactButton.layer.cornerRadius = 10 contactNumberButton.layer.cornerRadius = 10
contactButton.setTitle("\(phoneNumber)", for: .normal) 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 isFavoriteButton = UIButton() let checkStackView = UIStackView(arrangedSubviews: [checkButton, checkLabel])
let heartImage = UIImage(named: "iconPendientesUnchecked") checkStackView.axis = .vertical
isFavoriteButton.setImage(heartImage, for: .normal) checkStackView.distribution = .fillEqually
checkStackView.spacing = 0
//isFavoriteButton.setImage(heartImage, for: .normal)
isFavoriteButton.frame.size = CGSize(width: 80, height: 80) 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.text = "Agregar a mis pendientes"
isFavoriteLabel.font = format.bodyFontStyle isFavoriteLabel.font = format.bodyFontStyle
isFavoriteLabel.numberOfLines = 2 isFavoriteLabel.numberOfLines = 2
...@@ -118,54 +151,70 @@ class RequestViewController: UIViewController { ...@@ -118,54 +151,70 @@ class RequestViewController: UIViewController {
isFavoriteStackView.distribution = .fillEqually isFavoriteStackView.distribution = .fillEqually
isFavoriteStackView.spacing = 0 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() checkButton.setImage(checkImage, for: .normal)
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 footerStackView = UIStackView(arrangedSubviews: [isFavoriteStackView, checkStackView]) let footerStackView = UIStackView(arrangedSubviews: [isFavoriteStackView, checkStackView])
footerStackView.axis = .horizontal footerStackView.axis = .horizontal
footerStackView.distribution = .fillEqually footerStackView.distribution = .fillEqually
footerStackView.spacing = 50 footerStackView.heightAnchor.constraint(equalToConstant: 100).isActive = true
//let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)) viewHeightAnchor += Int(isFavoriteStackView.frame.height)
let footerSpacing = UIView() 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.axis = .vertical
stackView.distribution = .fillProportionally 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)
//view.addSubview(scrollView) //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) //scrollView.addSubview(stackView)
//view.addSubview(scrollView)
view.addSubview(stackView) view.addSubview(stackView)
//view.addSubview(titleLbl)
} }
func isFavoriteCheck()->Bool{ func isFavoriteCheck()->Bool{
let favoritos = manager.fetchFavorites()
return false 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{ func isReadyCheck()->Bool{
return false return false
} }
func convertDate(stringDate: String)->Date{
let dateFormatter = Date()
//dateFormatter.date(from: "stringDate")
return dateFormatter
}
@objc func addFavorite(){ @objc func addOrRemoveFavorite(sender: UIButton){
manager.saveFavorites(id: id, name: name, date: convertDate(stringDate: date), address: address, message: hRequestTitle) { [weak self] in
print(self as Any) 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 { ...@@ -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