Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // EditProfileViewController.swift
- // Heply
- //
- // Created by IFCE on 02/06/17.
- // Copyright © 2017 ifce. All rights reserved.
- //
- import UIKit
- import GooglePlacePicker
- import FYComboBox
- class EditProfileViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate, FYComboBoxDelegate {
- @IBOutlet weak var photoProfile: UIImageRound!
- @IBOutlet weak var editStatusTextView: UITextViewPlaceholder!
- @IBOutlet weak var textFieldName: HoshiTextField!
- @IBOutlet weak var textFieldLastName: HoshiTextField!
- @IBOutlet weak var textFieldCity: HoshiTextField!
- @IBOutlet weak var textFieldBirth: HoshiTextField!
- @IBOutlet weak var textFieldGender: HoshiTextField!
- @IBOutlet weak var comboGender: HeplyCombo!
- @IBOutlet weak var labelGender: UILabel!
- @IBOutlet weak var upDown: UIImageView!
- @IBOutlet weak var imgCombo: UIImageView!
- var city: String?
- var datePicker = UIDatePicker()
- let gender = ["Masculino", "Feminino", "Não Definido"]
- let img = [#imageLiteral(resourceName: "male-25"), #imageLiteral(resourceName: "female-25"), #imageLiteral(resourceName: "transgender-25")]
- let pos = [#imageLiteral(resourceName: "up"), #imageLiteral(resourceName: "down")]
- @IBAction func editPhotoButton(_ sender: Any) {
- let photo = UIImagePickerController()
- photo.delegate = self
- photo.sourceType = UIImagePickerControllerSourceType.photoLibrary
- photo.allowsEditing = false
- self.present(photo, animated: true){}
- }
- @IBAction func DoneProfileButton(_ sender: Any) {
- //Conclusão da edição do perfil
- // let nameSepareted = Account.currentUser.name?.components(separatedBy: " ")
- // if (!(textFieldName.text == nameSepareted?[0] && textFieldLastName.text == nameSepareted?[0])){
- FirebaseConnection.updateProfile(userUID: Account.currentUser.userUID!, field: "name", value: textFieldName.text!) { (newUpdate) -> (Void) in
- if let update = newUpdate{
- print(update)
- }
- // self.navigationController?.popViewController(animated: true)
- //self.alertConfirmation()
- AlertViews.successAlert("Perfil atualizado com sucesso", "OK", self)
- }
- // Account.currentUser.name = textFieldName.text! + " " + textFieldLastName.text!
- // }
- // if (!(textFieldCity.text == Account.currentUser.city)){ //verificar se city ta vazia
- // FirebaseConnection.updateProfile(userUID: Account.currentUser.userUID!, field: "city", value: city!) { (newUpdate) -> (Void) in
- // if let update = newUpdate{
- // print(update)
- // }
- // }
- //
- // Account.currentUser.city = textFieldCity.text!
- // }
- // var dicUpdateUser = [String: String]()
- //
- // dicUpdateUser["age"] = textFieldBirth.text!
- // dicUpdateUser["gender"] = textFieldGender.text!
- // dicUpdateUser["phrase"] = editStatusTextView.text!
- // FirebaseConnection.updateUser(userUID: Account.currentUser.userUID!, dic: dicUpdateUser)
- // alertConfirmation()
- //
- // self.navigationController?.popViewController(animated: true)
- }
- func actionTextFieldCity(){
- let autocompleteController = GMSAutocompleteViewController()
- autocompleteController.delegate = self
- self.present(autocompleteController, animated: true, completion: nil)
- }
- //MARK: - Delegate combobox
- func comboBox(_ comboBox: FYComboBox!, titleForRow row: Int) -> String! {
- self.comboGender.img = img[row]
- return self.gender[row]
- }
- func comboBox(_ comboBox: FYComboBox!, didSelectRow row: Int) {
- if comboBox == self.comboGender {
- self.labelGender.text = self.gender[row]
- self.imgCombo.image = self.img[row]
- }
- comboBox.close(animated: true)
- }
- func comboBoxNumber(ofRows comboBox: FYComboBox!) -> Int {
- if comboBox == self.comboGender {
- return self.gender.count
- }
- return 0
- }
- func comboBox(_ comboBox: FYComboBox!, willOpenAnimated animated: Bool) {
- upDown.image = pos[0]
- }
- func comboBox(_ comboBox: FYComboBox!, willCloseAnimated animated: Bool) {
- upDown.image = pos[1]
- }
- // -MARK: Alert
- func alertInformation() {
- let alertController = UIAlertController(title: "Há campos obrigatórios em branco", message: "Favor, preencha todos os campos", preferredStyle: .alert)
- let cancelAction = UIAlertAction(title: "OK", style: .cancel) { (_) in }
- alertController.addAction(cancelAction)
- self.present(alertController, animated: true, completion: nil)
- }
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
- if let image = info[UIImagePickerControllerOriginalImage] as? UIImage{
- photoProfile.image = image
- }
- else{
- //Error message
- }
- self.dismiss(animated: true, completion: nil)
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- customVisual()
- self.tabBarController?.tabBar.isHidden = true
- textFieldName.becomeFirstResponder()
- photoProfile.loadImageUsingCacheWithUrlString(Account.currentUser.profileImage!)
- textFieldCity.addTarget(self, action: #selector(actionTextFieldCity), for: .touchDown)
- let name = Account.currentUser.name?.components(separatedBy: " ")
- textFieldName.text = name?[0]
- comboGender.delegate = self
- // textFieldLastName.text = name?[1]
- textFieldCity.text = Account.currentUser.city
- textFieldBirth.text = Account.currentUser.age
- textFieldGender.text = Account.currentUser.gender
- // let toolbar = UIToolbar()
- // toolbar.sizeToFit()
- // let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(donePressed))
- // doneButton.tintColor = #colorLiteral(red: 0.168627451, green: 0.2705882353, blue: 0.4392156863, alpha: 1)
- // toolbar.setItems([doneButton], animated: true)
- // toolbar.isUserInteractionEnabled = true
- // textFieldBirth.inputAccessoryView = toolbar
- // textFieldBirth.inputView = datePicker
- // editStatusTextView.delegate = self as? UITextViewDelegate
- // datePicker.datePickerMode = UIDatePickerMode.date
- // datePicker.backgroundColor = .white
- // datePicker.setValue(UIColor.gray, forKey: "textColor")
- // datePicker.addTarget(self, action: #selector(EditProfileViewController.createPickerDate(sender:)), for: UIControlEvents.valueChanged)
- }
- func customVisual(){
- textFieldName.editConfig(#imageLiteral(resourceName: "name2"), Opt.left)
- textFieldLastName.editConfig(#imageLiteral(resourceName: "name2"), Opt.left)
- textFieldCity.editConfig(#imageLiteral(resourceName: "city2"), Opt.left)
- textFieldBirth.editConfig(#imageLiteral(resourceName: "birth2"), Opt.left)
- textFieldGender.editConfig(#imageLiteral(resourceName: "gender2"), Opt.left)
- }
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
- donePressed()
- }
- //MARK: -DatePicker to birth textField
- func createPickerDate(sender: UIDatePicker){
- let formatter = DateFormatter()
- formatter.dateStyle = DateFormatter.Style.medium
- formatter.timeStyle = DateFormatter.Style.none
- formatter.dateFormat = "dd/MM/yyyy"
- textFieldBirth.text = formatter.string(from: sender.date)
- }
- func donePressed() {
- self.view.endEditing(true)
- }
- }
- extension EditProfileViewController: GMSAutocompleteViewControllerDelegate {
- // Handle the user's selection.
- func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
- city = place.name
- dismiss(animated: true, completion: nil)
- }
- func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
- // TODO: handle the error.
- print("Error: ", error.localizedDescription)
- }
- // User canceled the operation.
- func wasCancelled(_ viewController: GMSAutocompleteViewController) {
- dismiss(animated: true, completion: nil)
- }
- // Turn the network activity indicator on and off again.
- func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
- UIApplication.shared.isNetworkActivityIndicatorVisible = true
- }
- func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
- UIApplication.shared.isNetworkActivityIndicatorVisible = false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement