EditSettingsController.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import UIKit
  2. class EditSettingsController: UITableViewController {
  3. private var displayNameBackup: String?
  4. private var statusCellBackup: String?
  5. private let section1 = 0
  6. private let section1Name = 0
  7. private let section1Status = 1
  8. private let section1RowCount = 2
  9. private let sectionCount = 1
  10. private lazy var displayNameCell: TextFieldCell = {
  11. let cell = TextFieldCell(description: String.localized("pref_your_name"), placeholder: String.localized("pref_your_name"))
  12. cell.setText(text: DcConfig.displayname ?? nil)
  13. return cell
  14. }()
  15. private lazy var statusCell: TextFieldCell = {
  16. let cell = TextFieldCell(description: String.localized("pref_default_status_label"), placeholder: String.localized("pref_default_status_label"))
  17. cell.setText(text: DcConfig.selfstatus ?? nil)
  18. return cell
  19. }()
  20. init() {
  21. super.init(style: .grouped)
  22. }
  23. required init?(coder aDecoder: NSCoder) {
  24. fatalError("init(coder:) has not been implemented")
  25. }
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28. title = String.localized("pref_profile_info_headline")
  29. }
  30. override func viewWillAppear(_ animated: Bool) {
  31. displayNameBackup = DcConfig.displayname
  32. statusCellBackup = DcConfig.selfstatus
  33. }
  34. override func viewWillDisappear(_ animated: Bool) {
  35. if displayNameBackup != displayNameCell.getText() || statusCellBackup != displayNameCell.getText() {
  36. DcConfig.selfstatus = statusCell.getText()
  37. DcConfig.displayname = displayNameCell.getText()
  38. dc_configure(mailboxPointer)
  39. }
  40. }
  41. // MARK: - Table view data source
  42. override func numberOfSections(in tableView: UITableView) -> Int {
  43. return sectionCount
  44. }
  45. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46. return section1RowCount
  47. }
  48. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  49. if indexPath.section == section1 && indexPath.row == section1Name {
  50. return displayNameCell
  51. }
  52. return statusCell
  53. }
  54. override func tableView(_: UITableView, titleForFooterInSection section: Int) -> String? {
  55. if section == section1 {
  56. return String.localized("pref_who_can_see_profile_explain")
  57. } else {
  58. return nil
  59. }
  60. }
  61. }