Advertisement
Guest User

places

a guest
Jul 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. //
  2. // EditProfileViewController.swift
  3. // Heply
  4. //
  5. // Created by IFCE on 02/06/17.
  6. // Copyright © 2017 ifce. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import GooglePlacePicker
  11. import FYComboBox
  12.  
  13. class EditProfileViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, FYComboBoxDelegate {
  14. @IBOutlet weak var photoProfile: UIImageRound!
  15. @IBOutlet weak var editStatusTextView: UITextViewPlaceholder!
  16. @IBOutlet weak var textFieldName: HoshiTextField!
  17. @IBOutlet weak var textFieldLastName: HoshiTextField!
  18. @IBOutlet weak var textFieldCity: HoshiTextField!
  19. @IBOutlet weak var textFieldBirth: HoshiTextField!
  20. @IBOutlet weak var textFieldGender: HoshiTextField!
  21. @IBOutlet weak var comboGender: HeplyCombo!
  22. @IBOutlet weak var labelGender: UILabel!
  23. @IBOutlet weak var upDown: UIImageView!
  24. @IBOutlet weak var imgCombo: UIImageView!
  25.  
  26. var city: String?
  27. var datePicker = UIDatePicker()
  28. let gender = ["Masculino", "Feminino", "Não Definido"]
  29. let img = [#imageLiteral(resourceName: "male-25"), #imageLiteral(resourceName: "female-25"), #imageLiteral(resourceName: "transgender-25")]
  30. let pos = [#imageLiteral(resourceName: "up"), #imageLiteral(resourceName: "down")]
  31.  
  32. @IBAction func editPhotoButton(_ sender: Any) {
  33. let photo = UIImagePickerController()
  34. photo.delegate = self
  35. photo.sourceType = UIImagePickerControllerSourceType.photoLibrary
  36. photo.allowsEditing = false
  37. self.present(photo, animated: true){}
  38. }
  39.  
  40.  
  41. @IBAction func DoneProfileButton(_ sender: Any) {
  42. //Conclusão da edição do perfil
  43. // let nameSepareted = Account.currentUser.name?.components(separatedBy: " ")
  44. // if (!(textFieldName.text == nameSepareted?[0] && textFieldLastName.text == nameSepareted?[0])){
  45. FirebaseConnection.updateProfile(userUID: Account.currentUser.userUID!, field: "name", value: textFieldName.text!) { (newUpdate) -> (Void) in
  46. if let update = newUpdate{
  47. print(update)
  48. }
  49. // self.navigationController?.popViewController(animated: true)
  50.  
  51. //self.alertConfirmation()
  52. AlertViews.successAlert("Perfil atualizado com sucesso", "OK", self)
  53.  
  54. }
  55.  
  56. // Account.currentUser.name = textFieldName.text! + " " + textFieldLastName.text!
  57. // }
  58.  
  59. // if (!(textFieldCity.text == Account.currentUser.city)){ //verificar se city ta vazia
  60. // FirebaseConnection.updateProfile(userUID: Account.currentUser.userUID!, field: "city", value: city!) { (newUpdate) -> (Void) in
  61. // if let update = newUpdate{
  62. // print(update)
  63. // }
  64. // }
  65. //
  66. // Account.currentUser.city = textFieldCity.text!
  67. // }
  68.  
  69. // var dicUpdateUser = [String: String]()
  70. //
  71. // dicUpdateUser["age"] = textFieldBirth.text!
  72. // dicUpdateUser["gender"] = textFieldGender.text!
  73. // dicUpdateUser["phrase"] = editStatusTextView.text!
  74.  
  75. // FirebaseConnection.updateUser(userUID: Account.currentUser.userUID!, dic: dicUpdateUser)
  76.  
  77. // alertConfirmation()
  78. //
  79. // self.navigationController?.popViewController(animated: true)
  80. }
  81.  
  82. func actionTextFieldCity(){
  83. let autocompleteController = GMSAutocompleteViewController()
  84. autocompleteController.delegate = self
  85. self.present(autocompleteController, animated: true, completion: nil)
  86. }
  87.  
  88. //MARK: - Delegate combobox
  89.  
  90. func comboBox(_ comboBox: FYComboBox!, titleForRow row: Int) -> String! {
  91. self.comboGender.img = img[row]
  92. return self.gender[row]
  93. }
  94.  
  95. func comboBox(_ comboBox: FYComboBox!, didSelectRow row: Int) {
  96. if comboBox == self.comboGender {
  97. self.labelGender.text = self.gender[row]
  98. self.imgCombo.image = self.img[row]
  99. }
  100. comboBox.close(animated: true)
  101. }
  102.  
  103. func comboBoxNumber(ofRows comboBox: FYComboBox!) -> Int {
  104. if comboBox == self.comboGender {
  105. return self.gender.count
  106. }
  107. return 0
  108. }
  109.  
  110. func comboBox(_ comboBox: FYComboBox!, willOpenAnimated animated: Bool) {
  111. upDown.image = pos[0]
  112. }
  113.  
  114. func comboBox(_ comboBox: FYComboBox!, willCloseAnimated animated: Bool) {
  115. upDown.image = pos[1]
  116. }
  117.  
  118. // -MARK: Alert
  119.  
  120. func alertInformation() {
  121. let alertController = UIAlertController(title: "Há campos obrigatórios em branco", message: "Favor, preencha todos os campos", preferredStyle: .alert)
  122.  
  123. let cancelAction = UIAlertAction(title: "OK", style: .cancel) { (_) in }
  124. alertController.addAction(cancelAction)
  125.  
  126. self.present(alertController, animated: true, completion: nil)
  127. }
  128.  
  129.  
  130. func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
  131. if let image = info[UIImagePickerControllerOriginalImage] as? UIImage{
  132. photoProfile.image = image
  133. }
  134. else{
  135. //Error message
  136. }
  137.  
  138. self.dismiss(animated: true, completion: nil)
  139. }
  140.  
  141. override func viewDidLoad() {
  142. super.viewDidLoad()
  143. customVisual()
  144. self.tabBarController?.tabBar.isHidden = true
  145. textFieldName.becomeFirstResponder()
  146. photoProfile.loadImageUsingCacheWithUrlString(Account.currentUser.profileImage!)
  147. textFieldCity.addTarget(self, action: #selector(actionTextFieldCity), for: .touchDown)
  148. let name = Account.currentUser.name?.components(separatedBy: " ")
  149. textFieldName.text = name?[0]
  150. comboGender.delegate = self
  151. // textFieldLastName.text = name?[1]
  152. textFieldCity.text = Account.currentUser.city
  153. textFieldBirth.text = Account.currentUser.age
  154. textFieldGender.text = Account.currentUser.gender
  155.  
  156. // let toolbar = UIToolbar()
  157. // toolbar.sizeToFit()
  158. // let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(donePressed))
  159. // doneButton.tintColor = #colorLiteral(red: 0.168627451, green: 0.2705882353, blue: 0.4392156863, alpha: 1)
  160. // toolbar.setItems([doneButton], animated: true)
  161. // toolbar.isUserInteractionEnabled = true
  162. // textFieldBirth.inputAccessoryView = toolbar
  163. // textFieldBirth.inputView = datePicker
  164. // editStatusTextView.delegate = self as? UITextViewDelegate
  165. // datePicker.datePickerMode = UIDatePickerMode.date
  166. // datePicker.backgroundColor = .white
  167. // datePicker.setValue(UIColor.gray, forKey: "textColor")
  168. // datePicker.addTarget(self, action: #selector(EditProfileViewController.createPickerDate(sender:)), for: UIControlEvents.valueChanged)
  169.  
  170. }
  171.  
  172. func customVisual(){
  173. textFieldName.editConfig(#imageLiteral(resourceName: "name2"), Opt.left)
  174. textFieldLastName.editConfig(#imageLiteral(resourceName: "name2"), Opt.left)
  175. textFieldCity.editConfig(#imageLiteral(resourceName: "city2"), Opt.left)
  176. textFieldBirth.editConfig(#imageLiteral(resourceName: "birth2"), Opt.left)
  177. textFieldGender.editConfig(#imageLiteral(resourceName: "gender2"), Opt.left)
  178. }
  179.  
  180. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  181. donePressed()
  182. }
  183.  
  184. //MARK: -DatePicker to birth textField
  185. func createPickerDate(sender: UIDatePicker){
  186. let formatter = DateFormatter()
  187. formatter.dateStyle = DateFormatter.Style.medium
  188. formatter.timeStyle = DateFormatter.Style.none
  189. formatter.dateFormat = "dd/MM/yyyy"
  190. textFieldBirth.text = formatter.string(from: sender.date)
  191. }
  192.  
  193.  
  194. func donePressed() {
  195. self.view.endEditing(true)
  196. }
  197. }
  198.  
  199. extension EditProfileViewController: GMSAutocompleteViewControllerDelegate {
  200.  
  201. // Handle the user's selection.
  202. func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
  203. city = place.name
  204. dismiss(animated: true, completion: nil)
  205. }
  206.  
  207. func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
  208. // TODO: handle the error.
  209. print("Error: ", error.localizedDescription)
  210. }
  211.  
  212. // User canceled the operation.
  213. func wasCancelled(_ viewController: GMSAutocompleteViewController) {
  214. dismiss(animated: true, completion: nil)
  215. }
  216.  
  217. // Turn the network activity indicator on and off again.
  218. func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
  219. UIApplication.shared.isNetworkActivityIndicatorVisible = true
  220. }
  221.  
  222. func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
  223. UIApplication.shared.isNetworkActivityIndicatorVisible = false
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement