-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathSettingsCommon.swift
83 lines (67 loc) · 3.31 KB
/
SettingsCommon.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import UIKit
import WordPressKit
import CocoaLumberjack
protocol SettingsController: ImmuTableController {}
// MARK: - Actions
extension SettingsController {
func insideNavigationController(_ generator: @escaping ImmuTableRowControllerGenerator) -> ImmuTableRowControllerGenerator {
return { row in
let controller = generator(row)
let navigation = UINavigationController(rootViewController: controller)
navigation.modalPresentationStyle = .formSheet
return navigation
}
}
func editText(_ changeType: @escaping AccountSettingsChangeWithString, hint: String? = nil, service: AccountSettingsService) -> (ImmuTableRow) -> SettingsTextViewController {
return { row in
let editableRow = row as! EditableTextRow
return self.controllerForEditableText(editableRow, changeType: changeType, hint: hint, service: service)
}
}
func editMultilineText(_ changeType: @escaping AccountSettingsChangeWithString, hint: String? = nil, service: AccountSettingsService) -> (ImmuTableRow) -> SettingsMultiTextViewController {
return { row in
let editableRow = row as! EditableTextRow
return self.controllerForEditableMultilineText(editableRow, changeType: changeType, hint: hint, service: service)
}
}
func editEmailAddress(_ changeType: @escaping AccountSettingsChangeWithString, hint: String? = nil, service: AccountSettingsService) -> (ImmuTableRow) -> SettingsTextViewController {
return { row in
let editableRow = row as! EditableTextRow
let settingsViewController = self.controllerForEditableText(editableRow, changeType: changeType, hint: hint, service: service)
settingsViewController.mode = .email
return settingsViewController
}
}
func controllerForEditableText(_ row: EditableTextRow,
changeType: @escaping AccountSettingsChangeWithString,
hint: String? = nil,
service: AccountSettingsService) -> SettingsTextViewController {
let title = row.title
let value = row.value
let controller = SettingsTextViewController(text: value, placeholder: "\(title)...", hint: hint)
controller.title = title
controller.onValueChanged = {
value in
let change = changeType(value)
service.saveChange(change)
DDLogDebug("\(title) changed: \(value)")
}
return controller
}
func controllerForEditableMultilineText(_ row: EditableTextRow,
changeType: @escaping AccountSettingsChangeWithString,
hint: String? = nil,
service: AccountSettingsService) -> SettingsMultiTextViewController {
let title = row.title
let value = row.value
let controller = SettingsMultiTextViewController(text: value, placeholder: "\(title)...", hint: hint, isPassword: false)
controller.title = title
controller.onValueChanged = {
value in
let change = changeType(value)
service.saveChange(change)
DDLogDebug("\(title) changed: \(value)")
}
return controller
}
}