InfoDisplaySettingsViewController.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // InfoDisplaySettingsViewController.swift
  3. // LoopFollow
  4. //
  5. // Created by Jose Paredes on 7/16/20.
  6. // Copyright © 2020 Jon Fawcett. All rights reserved.
  7. //
  8. import UIKit
  9. import Eureka
  10. import EventKit
  11. import EventKitUI
  12. class InfoDisplaySettingsViewController: FormViewController {
  13. var appStateController: AppStateController?
  14. override func viewDidLoad() {
  15. print("Display Load")
  16. super.viewDidLoad()
  17. if UserDefaultsRepository.forceDarkMode.value {
  18. overrideUserInterfaceStyle = .dark
  19. }
  20. createForm()
  21. }
  22. private func createForm() {
  23. form
  24. +++ MultivaluedSection(multivaluedOptions: .Reorder, header: "Information Display Settings", footer: "Arrage/Enable Information Desired") {
  25. // TODO: add the other display values
  26. $0.tag = "InfoDisplay"
  27. for i in 0..<UserDefaultsRepository.infoNames.value.count {
  28. $0 <<< TextRow() { row in
  29. if(UserDefaultsRepository.infoVisible.value[UserDefaultsRepository.infoSort.value[i]]) {
  30. row.title = "\u{2713}\t\(UserDefaultsRepository.infoNames.value[UserDefaultsRepository.infoSort.value[i]])"
  31. } else {
  32. row.title = "\u{2001}\t\(UserDefaultsRepository.infoNames.value[UserDefaultsRepository.infoSort.value[i]])"
  33. }
  34. }.onCellSelection{(cell, row) in
  35. let i = row.indexPath!.row
  36. UserDefaultsRepository.infoVisible.value[UserDefaultsRepository.infoSort.value[i]] = !UserDefaultsRepository.infoVisible.value[UserDefaultsRepository.infoSort.value[i]]
  37. self.tableView.reloadData()
  38. //print("\(row.title)")
  39. //print("\(row.indexPath?.row)")
  40. }.cellSetup { (cell, row) in
  41. cell.textField.isUserInteractionEnabled = false
  42. }.cellUpdate{ (cell, row) in
  43. if(UserDefaultsRepository.infoVisible.value[UserDefaultsRepository.infoSort.value[i]]) {
  44. row.title = "\u{2713}\t\(UserDefaultsRepository.infoNames.value[UserDefaultsRepository.infoSort.value[i]])"
  45. } else {
  46. row.title = "\u{2001}\t\(UserDefaultsRepository.infoNames.value[UserDefaultsRepository.infoSort.value[i]])"
  47. }
  48. self.appStateController!.infoDataSettingsChanged = true
  49. }
  50. }
  51. }
  52. +++ ButtonRow() {
  53. $0.title = "DONE"
  54. }.onCellSelection { (row, arg) in
  55. self.dismiss(animated:true, completion: nil)
  56. }
  57. }
  58. override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
  59. //let view = tableView
  60. let sourceIndex = sourceIndexPath.row
  61. let destIndex = destinationIndexPath.row
  62. // new sort
  63. if(destIndex != sourceIndex ) {
  64. self.appStateController!.infoDataSettingsChanged = true
  65. let tmpVal = UserDefaultsRepository.infoSort.value[sourceIndex]
  66. UserDefaultsRepository.infoSort.value.remove(at:sourceIndex)
  67. UserDefaultsRepository.infoSort.value.insert(tmpVal, at:destIndex)
  68. }
  69. }
  70. }