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