HCEditProfile.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // HCEditProfile.swift
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 17/04/19.
  6. // Copyright (c) 2019 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. class HCEditProfile: XLFormViewController {
  25. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  26. required init(coder aDecoder: NSCoder) {
  27. super.init(coder: aDecoder)
  28. }
  29. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  30. super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
  31. }
  32. func initializeForm() {
  33. let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
  34. form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
  35. var section : XLFormSectionDescriptor
  36. var row : XLFormRowDescriptor
  37. let tableAccount = NCManageDatabase.sharedInstance.getAccountActive()
  38. section = XLFormSectionDescriptor.formSection()
  39. form.addFormSection(section)
  40. row = XLFormRowDescriptor(tag: "userfullname", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_full_name_", comment: ""))
  41. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  42. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  43. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  44. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "user"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  45. row.value = tableAccount?.displayName
  46. section.addFormRow(row)
  47. row = XLFormRowDescriptor(tag: "useraddress", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_address_", comment: ""))
  48. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  49. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  50. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  51. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "address"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  52. row.value = tableAccount?.address
  53. section.addFormRow(row)
  54. row = XLFormRowDescriptor(tag: "usercity", rowType: XLFormRowDescriptorTypeText, title: NSLocalizedString("_user_city_", comment: ""))
  55. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  56. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  57. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  58. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "city"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  59. row.value = tableAccount?.city
  60. section.addFormRow(row)
  61. row = XLFormRowDescriptor(tag: "userzip", rowType: XLFormRowDescriptorTypeZipCode, title: NSLocalizedString("_user_zip_", comment: ""))
  62. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  63. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  64. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  65. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "cityzip"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  66. row.value = tableAccount?.zip
  67. section.addFormRow(row)
  68. row = XLFormRowDescriptor(tag: "usercountry", rowType: XLFormRowDescriptorTypeSelectorPickerView, title: NSLocalizedString("_user_country_", comment: ""))
  69. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  70. row.cellConfig["detailTextLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  71. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "country"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  72. var locales = [String]()
  73. for localeCode in NSLocale.isoCountryCodes {
  74. let countryName = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: localeCode) ?? ""
  75. if localeCode == tableAccount?.country {
  76. row.value = countryName
  77. }
  78. locales.append(countryName)
  79. }
  80. row.selectorOptions = locales.sorted()
  81. section.addFormRow(row)
  82. row = XLFormRowDescriptor(tag: "userphone", rowType: XLFormRowDescriptorTypePhone, title: NSLocalizedString("_user_phone_", comment: ""))
  83. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  84. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  85. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  86. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "phone"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  87. row.value = tableAccount?.phone
  88. section.addFormRow(row)
  89. row = XLFormRowDescriptor(tag: "useremail", rowType: XLFormRowDescriptorTypeEmail, title: NSLocalizedString("_user_email_", comment: ""))
  90. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  91. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  92. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  93. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "email"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  94. row.value = tableAccount?.email
  95. section.addFormRow(row)
  96. row = XLFormRowDescriptor(tag: "userweb", rowType: XLFormRowDescriptorTypeEmail, title: NSLocalizedString("_user_web_", comment: ""))
  97. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  98. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  99. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  100. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "web"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  101. row.value = tableAccount?.webpage
  102. section.addFormRow(row)
  103. row = XLFormRowDescriptor(tag: "usertwitter", rowType: XLFormRowDescriptorTypeTwitter, title: NSLocalizedString("_user_twitter_", comment: ""))
  104. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  105. row.cellConfig["textField.font"] = UIFont.systemFont(ofSize: 15.0)
  106. row.cellConfig["textField.textAlignment"] = NSTextAlignment.right.rawValue
  107. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "twitter"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  108. row.value = tableAccount?.twitter
  109. section.addFormRow(row)
  110. row = XLFormRowDescriptor(tag: "userbusinesstype", rowType: XLFormRowDescriptorTypeMultipleSelector, title: NSLocalizedString("_user_businesstype_", comment: ""))
  111. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  112. row.cellConfig["detailTextLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  113. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "businesstype"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  114. row.selectorOptions = ["ARCHITECT","BRICKLAYER","CARPENTER","ELECTRICIAN","INSTALLER","PAINTER","PLUMBER","ROOFER","STOVEBUILDER","STUCCOER","WINDOWBUILDER","OTHER"]
  115. row.value = tableAccount?.businessType.components(separatedBy: ",")
  116. section.addFormRow(row)
  117. row = XLFormRowDescriptor(tag: "userbusinesssize", rowType: XLFormRowDescriptorTypeSelectorPickerView, title: NSLocalizedString("_user_businesssize_", comment: ""))
  118. row.cellConfig["textLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  119. row.cellConfig["detailTextLabel.font"] = UIFont.systemFont(ofSize: 15.0)
  120. row.cellConfig["imageView.image"] = CCGraphics.changeThemingColorImage(UIImage.init(named: "users"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  121. row.selectorOptions = ["1-4","5-9","10-19","20-49","50-99","100-249","250-499","500-999","1000+"];
  122. switch tableAccount?.businessSize {
  123. case 1: row.value = "1-4"
  124. case 5: row.value = "5-9"
  125. case 10: row.value = "10-19"
  126. case 20: row.value = "20-49"
  127. case 50: row.value = "50-99"
  128. case 100: row.value = "100-249"
  129. case 250: row.value = "250-499"
  130. case 500: row.value = "500-999"
  131. case 1000: row.value = "1000+"
  132. default: break
  133. }
  134. section.addFormRow(row)
  135. self.form = form
  136. }
  137. override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
  138. super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
  139. }
  140. // MARK: - View Life Cycle
  141. override func viewDidLoad() {
  142. super.viewDidLoad()
  143. self.navigationItem.title = NSLocalizedString("_user_editprofile_", comment: "")
  144. self.navigationController?.navigationBar.isTranslucent = false
  145. self.navigationController?.navigationBar.barTintColor = NCBrandColor.sharedInstance.brand
  146. self.navigationController?.navigationBar.tintColor = NCBrandColor.sharedInstance.brandText
  147. self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: NCBrandColor.sharedInstance.brandText]
  148. self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
  149. initializeForm()
  150. }
  151. }