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