Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
VLC-iOS
Commits
8288f92c
Commit
8288f92c
authored
Aug 13, 2018
by
Soomin Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
VLCEditController: Create AlertTextField helper
parent
e4ccab12
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
23 deletions
+39
-23
Sources/VLCEditController.swift
Sources/VLCEditController.swift
+39
-23
No files found.
Sources/VLCEditController.swift
View file @
8288f92c
...
...
@@ -51,6 +51,39 @@ private extension VLCEditController {
cell
.
checkView
.
isEnabled
=
false
}
}
private
struct
TextFieldAlertInfo
{
var
alertTitle
:
String
var
placeHolder
:
String
}
private
func
presentTextFieldAlert
(
with
info
:
TextFieldAlertInfo
,
completionHandler
:
@escaping
(
String
)
->
Void
)
{
let
alertController
=
UIAlertController
(
title
:
info
.
alertTitle
,
message
:
""
,
preferredStyle
:
.
alert
)
alertController
.
addTextField
(
configurationHandler
:
{
textField
in
textField
.
placeholder
=
info
.
placeHolder
})
let
cancelButton
=
UIAlertAction
(
title
:
NSLocalizedString
(
"BUTTON_CANCEL"
,
comment
:
""
),
style
:
.
default
)
let
confirmAction
=
UIAlertAction
(
title
:
NSLocalizedString
(
"BUTTON_DONE"
,
comment
:
""
),
style
:
.
default
)
{
[
weak
alertController
]
_
in
guard
let
alertController
=
alertController
,
let
textField
=
alertController
.
textFields
?
.
first
else
{
return
}
completionHandler
(
textField
.
text
??
""
)
}
alertController
.
addAction
(
cancelButton
)
alertController
.
addAction
(
confirmAction
)
UIApplication
.
shared
.
keyWindow
?
.
rootViewController
?
.
present
(
alertController
,
animated
:
true
,
completion
:
nil
)
}
}
extension
VLCEditController
:
VLCEditControllerDataSource
{
...
...
@@ -104,31 +137,14 @@ extension VLCEditController: VLCEditToolbarDelegate {
for
indexPath
in
selectedCellIndexPaths
{
if
let
media
=
category
.
anyfiles
[
indexPath
.
row
]
as?
VLCMLMedia
{
// Not using VLCAlertViewController to have more customization in text fields
let
alertController
=
UIAlertController
(
title
:
String
(
format
:
NSLocalizedString
(
"RENAME_MEDIA_TO"
,
comment
:
""
),
media
.
title
),
message
:
""
,
preferredStyle
:
.
alert
)
alertController
.
addTextField
(
configurationHandler
:
{
textField
in
textField
.
placeholder
=
NSLocalizedString
(
"NEW_NAME"
,
comment
:
""
)
})
let
cancelButton
=
UIAlertAction
(
title
:
NSLocalizedString
(
"BUTTON_CANCEL"
,
comment
:
""
),
style
:
.
default
)
let
alertInfo
=
TextFieldAlertInfo
(
alertTitle
:
String
(
format
:
NSLocalizedString
(
"RENAME_MEDIA_TO"
,
comment
:
""
),
media
.
title
),
placeHolder
:
"NEW_NAME"
)
let
confirmAction
=
UIAlertAction
(
title
:
NSLocalizedString
(
"BUTTON_DONE"
,
comment
:
""
),
style
:
.
default
)
{
[
weak
alertController
,
weak
self
]
_
in
guard
let
alertController
=
alertController
,
let
textField
=
alertController
.
textFields
?
.
first
else
{
return
}
media
.
updateTitle
(
textField
.
text
)
presentTextFieldAlert
(
with
:
alertInfo
,
completionHandler
:
{
[
weak
self
]
text
->
Void
in
media
.
updateTitle
(
text
)
self
?
.
resetCell
(
at
:
indexPath
)
}
alertController
.
addAction
(
cancelButton
)
alertController
.
addAction
(
confirmAction
)
UIApplication
.
shared
.
keyWindow
?
.
rootViewController
?
.
present
(
alertController
,
animated
:
true
,
completion
:
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