Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
contact-list-app
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
Luis Zarza
contact-list-app
Commits
57a3919a
Commit
57a3919a
authored
Mar 20, 2020
by
Luis Zarza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
call and send sms swipe actions added in contact profile screen
parent
75f30cac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
1 deletions
+69
-1
contact-list-app/ContactProfileVC.swift
+69
-1
No files found.
contact-list-app/ContactProfileVC.swift
View file @
57a3919a
...
...
@@ -23,7 +23,6 @@ class ContactProfileVC: UIViewController {
var
contactProfileData
:
ContactProfile
?
@IBOutlet
weak
var
nameLbl
:
UILabel
!
@IBOutlet
weak
var
profilePic
:
UIImageView
!
@IBOutlet
weak
var
contactPhoneNumbersTable
:
UITableView
!
override
func
viewDidLoad
()
{
...
...
@@ -78,6 +77,63 @@ class ContactProfileVC: UIViewController {
}
}
func
callAction
(
at
indexPath
:
IndexPath
)
->
UIContextualAction
{
//get phoneNumber from datasource
let
phoneNumber
=
contactProfileData
!.
phonNumbersList
[
indexPath
.
row
]
//format phone number, replace invalid characters
let
formatedNumber
=
formatPhoneNumber
(
phoneNumber
:
phoneNumber
)
let
action
=
UIContextualAction
(
style
:
.
normal
,
title
:
"Call"
,
handler
:
{
(
action
,
view
,
completion
)
in
//make a phone call
guard
let
phoneCallURL
=
URL
(
string
:
"tel://+
\(
formatedNumber
)
"
)
else
{
return
}
UIApplication
.
shared
.
open
(
phoneCallURL
)
//show alert
let
alert
=
UIAlertController
(
title
:
"Calling
\(
phoneNumber
)
"
,
message
:
nil
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"Finish"
,
style
:
.
default
,
handler
:
nil
))
self
.
present
(
alert
,
animated
:
true
)
//hide leading swipe actions
completion
(
true
)
})
//set icon and backgorund
action
.
image
=
UIImage
(
systemName
:
"phone.fill.arrow.up.right"
)
action
.
backgroundColor
=
.
green
return
action
}
func
messageAction
(
at
indexPath
:
IndexPath
)
->
UIContextualAction
{
let
contact
=
contactProfileData
!.
phonNumbersList
[
indexPath
.
row
]
let
action
=
UIContextualAction
(
style
:
.
normal
,
title
:
"Call"
,
handler
:
{
(
action
,
view
,
completion
)
in
//show alert
let
alert
=
UIAlertController
(
title
:
"Send a SMS To:
\(
contact
)
"
,
message
:
nil
,
preferredStyle
:
.
alert
)
alert
.
addAction
(
UIAlertAction
(
title
:
"Finish"
,
style
:
.
default
,
handler
:
nil
))
self
.
present
(
alert
,
animated
:
true
)
//hide leading swipe actions
completion
(
true
)
})
action
.
image
=
UIImage
(
systemName
:
"envelope.fill"
)
action
.
backgroundColor
=
.
orange
return
action
}
func
formatPhoneNumber
(
phoneNumber
:
String
)
->
String
{
var
formatedNumber
=
phoneNumber
.
replacingOccurrences
(
of
:
"("
,
with
:
""
)
formatedNumber
=
phoneNumber
.
replacingOccurrences
(
of
:
")"
,
with
:
""
)
formatedNumber
=
phoneNumber
.
replacingOccurrences
(
of
:
"+"
,
with
:
""
)
formatedNumber
=
phoneNumber
.
replacingOccurrences
(
of
:
" "
,
with
:
"-"
)
return
formatedNumber
}
}
extension
ContactProfileVC
:
UITableViewDelegate
,
UITableViewDataSource
{
...
...
@@ -115,4 +171,16 @@ extension ContactProfileVC: UITableViewDelegate, UITableViewDataSource{
}
}
func
tableView
(
_
tableView
:
UITableView
,
leadingSwipeActionsConfigurationForRowAt
indexPath
:
IndexPath
)
->
UISwipeActionsConfiguration
?
{
if
indexPath
.
section
==
0
{
let
call
=
callAction
(
at
:
indexPath
)
let
sendMessage
=
messageAction
(
at
:
indexPath
)
return
UISwipeActionsConfiguration
(
actions
:
[
call
,
sendMessage
])
}
return
nil
}
}
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