Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ayudapy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julio Hermosa
ayudapy
Commits
9d76d329
Commit
9d76d329
authored
May 19, 2020
by
Julio Hermosa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se ordena y documenta el código
parent
f2c90045
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
74 additions
and
83 deletions
+74
-83
ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
ayudapy/Base.lproj/Main.storyboard
+2
-2
ayudapy/CoreData/CoreDataManager.swift
+10
-0
ayudapy/Info.plist
+2
-4
ayudapy/Static/Format.swift
+6
-6
ayudapy/ViewControllers/MapViewController.swift
+21
-37
ayudapy/ViewControllers/PendingsViewController.swift
+9
-6
ayudapy/ViewControllers/RequestViewController.swift
+24
-28
No files found.
ayudapy.xcworkspace/xcuserdata/roshka.xcuserdatad/UserInterfaceState.xcuserstate
View file @
9d76d329
No preview for this file type
ayudapy/Base.lproj/Main.storyboard
View file @
9d76d329
...
...
@@ -10,7 +10,7 @@
<!--Request View Controller-->
<scene
sceneID=
"MGi-Q6-5W5"
>
<objects>
<viewController
storyboardIdentifier=
"
pedido
sVC"
id=
"efO-tm-e7g"
customClass=
"RequestViewController"
customModule=
"ayudapy"
customModuleProvider=
"target"
sceneMemberID=
"viewController"
>
<viewController
storyboardIdentifier=
"
request
sVC"
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=
"pendi
ente
sVC"
id=
"Ncc-gI-9dq"
customClass=
"PendingsViewController"
customModule=
"ayudapy"
customModuleProvider=
"target"
sceneMemberID=
"viewController"
>
<viewController
storyboardIdentifier=
"pendi
ng
sVC"
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"
/>
...
...
ayudapy/CoreData/CoreDataManager.swift
View file @
9d76d329
...
...
@@ -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
...
...
ayudapy/Info.plist
View file @
9d76d329
...
...
@@ -20,6 +20,8 @@
<
string
>
1
<
/string
>
<
k
e
y
>
LSRequiresIPhoneOS
<
/k
e
y
>
<
tru
e
/
>
<
k
e
y
>
NSLocationWhenInUseUsageDescription
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
UIApplicationSceneManifest
<
/k
e
y
>
<
d
i
c
t
>
<
k
e
y
>
UIApplicationSupportsMultipleScenes
<
/k
e
y
>
...
...
@@ -50,11 +52,7 @@
<
k
e
y
>
UISupportedInterfaceOrientations
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeLeft
<
/string
>
<
string
>
UIInterfaceOrientationLandscapeRight
<
/string
>
<
/
a
rr
a
y
>
<
k
e
y
>
NSLocationWhenInUseUsageDescription
<
/k
e
y
>
<
string
><
/string
>
<
k
e
y
>
UISupportedInterfaceOrientations
~
ipad
<
/k
e
y
>
<
a
rr
a
y
>
<
string
>
UIInterfaceOrientationPortrait
<
/string
>
...
...
ayudapy/Static/Format.swift
View file @
9d76d329
...
...
@@ -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
//
}
}
ayudapy/ViewControllers/MapViewController.swift
View file @
9d76d329
...
...
@@ -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(
goToInfo
VC
)
,
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(
goToPendi
entes
)
,
for
:
.
touchUpInside
)
pendingButton
.
addTarget
(
self
,
action
:
#selector(
goToPendi
ngsVC
)
,
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
goToInfo
VC
(){
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
goToRequestV
iewController
(
pk
:
Int
){
let
pedidosVC
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"pedido
sVC"
)
as!
RequestViewController
pedido
sVC
.
id
=
id
pedido
sVC
.
currentLatitude
=
(
currentLocation
?
.
coordinate
.
latitude
)
!
pedido
sVC
.
currentLongitude
=
(
currentLocation
?
.
coordinate
.
longitude
)
!
if
isFavorite
(
id
:
id
){
pedido
sVC
.
isFavorite
=
true
@objc
func
goToRequestV
C
(
pk
:
Int
){
let
requestsVC
=
self
.
storyboard
?
.
instantiateViewController
(
withIdentifier
:
"request
sVC"
)
as!
RequestViewController
request
sVC
.
id
=
id
request
sVC
.
currentLatitude
=
(
currentLocation
?
.
coordinate
.
latitude
)
!
request
sVC
.
currentLongitude
=
(
currentLocation
?
.
coordinate
.
longitude
)
!
if
manager
.
checkData
(
id
:
id
,
entityList
:
favorites
){
request
sVC
.
isFavorite
=
true
print
(
"El pedido
\(
id
)
es favorito"
)
}
pedidosVC
.
helpRequest
()
//show(pedidosVC, sender: nil)
requestsVC
.
helpRequest
()
isModalInPresentation
=
true
present
(
pedido
sVC
,
animated
:
true
,
completion
:
nil
)
present
(
request
sVC
,
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
!
)
!
goToRequestV
iewController
(
pk
:
id
)
goToRequestV
C
(
pk
:
id
)
return
true
}
func
mapView
(
_
mapView
:
GMSMapView
,
willMove
gesture
:
Bool
)
{
...
...
ayudapy/ViewControllers/PendingsViewController.swift
View file @
9d76d329
...
...
@@ -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
){
pedido
sVC
.
isFavorite
=
true
request
sVC
.
isFavorite
=
true
}
print
(
"ID del pedido:
\(
pk
)
"
)
pedido
sVC
.
helpRequest
()
request
sVC
.
helpRequest
()
//show(pedidosVC, sender: nil)
present
(
pedido
sVC
,
animated
:
true
,
completion
:
nil
)
present
(
request
sVC
,
animated
:
true
,
completion
:
nil
)
}
func
isFavorite
(
id
:
Int
)
->
Bool
{
var
bool
=
Bool
()
...
...
ayudapy/ViewControllers/RequestViewController.swift
View file @
9d76d329
...
...
@@ -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
()
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment