123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- //
- // SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
- // SPDX-License-Identifier: GPL-3.0-or-later
- //
- import Foundation
- extension UserProfileTableViewController {
- @objc func editButtonPressed() {
- if activeTextField != nil {
- self.waitingForModification = true
- activeTextField?.resignFirstResponder()
- return
- }
- if !isEditable {
- isEditable = true
- self.showDoneButton()
- } else {
- isEditable = false
- self.showEditButton()
- }
- self.refreshProfileTableView()
- }
- func addNewAccount() {
- self.dismiss(animated: true) {
- NCUserInterfaceController.sharedInstance().presentLoginViewController()
- }
- }
- func showLogoutConfirmationDialog() {
- let alertTitle = multiAccountEnabled.boolValue ? NSLocalizedString("Remove account", comment: "") : NSLocalizedString("Log out", comment: "")
- let alertMessageAccountRemove = NSLocalizedString("Do you really want to remove this account?", comment: "")
- let alertMessageAccountLogout = NSLocalizedString("Do you really want to log out from this account?", comment: "")
- let alertMessage = multiAccountEnabled.boolValue ? alertMessageAccountRemove : alertMessageAccountLogout
- let actionTitle = multiAccountEnabled.boolValue ? NSLocalizedString("Remove", comment: "") : NSLocalizedString("Log out", comment: "")
- let confirmDialog = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
- let confirmAction = UIAlertAction(title: actionTitle, style: .destructive) { _ in
- self.logout()
- }
- confirmDialog.addAction(confirmAction)
- let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
- confirmDialog.addAction(cancelAction)
- self.present(confirmDialog, animated: true, completion: nil)
- }
- func logout() {
- let activeAccount = NCDatabaseManager.sharedInstance().activeAccount()
- NCSettingsController.sharedInstance().logoutAccount(withAccountId: activeAccount.accountId) { _ in
- NCUserInterfaceController.sharedInstance().presentConversationsList()
- NCConnectionController.sharedInstance().checkAppState()
- }
- }
- func presentSetPhoneNumberDialog() {
- let setPhoneNumberDialog = UIAlertController(title: NSLocalizedString("Phone number", comment: ""), message: nil, preferredStyle: .alert)
- let hasPhone = !account.phone.isEmpty
- setPhoneNumberDialog.addTextField { [self] textField in
- let regionCode = NSLocale.current.regionCode
- let countryCode = phoneUtil.getCountryCode(forRegion: regionCode)
- if let countryCode = countryCode {
- textField.text = "+\(countryCode)"
- }
- if hasPhone {
- textField.text = self.account.phone
- }
- let exampleNumber = try? self.phoneUtil.getExampleNumber(regionCode ?? "")
- if let exampleNumber = exampleNumber {
- textField.placeholder = try? self.phoneUtil.format(exampleNumber, numberFormat: NBEPhoneNumberFormat.INTERNATIONAL)
- textField.keyboardType = .phonePad
- textField.delegate = self
- textField.tag = self.kPhoneTextFieldTag
- }
- }
- setPhoneAction = UIAlertAction(title: NSLocalizedString("Set", comment: ""), style: .default, handler: { _ in
- let phoneNumber = setPhoneNumberDialog.textFields?[0].text
- if let phoneNumber = phoneNumber {
- self.setPhoneNumber(phoneNumber)
- }
- })
- setPhoneAction.isEnabled = false
- setPhoneNumberDialog.addAction(setPhoneAction)
- if hasPhone {
- let removeAction = UIAlertAction(title: NSLocalizedString("Remove", comment: ""), style: .destructive) { _ in
- self.setPhoneNumber("")
- }
- setPhoneNumberDialog.addAction(removeAction)
- }
- let cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment: ""), style: .cancel, handler: nil)
- setPhoneNumberDialog.addAction(cancelAction)
- self.present(setPhoneNumberDialog, animated: true, completion: nil)
- }
- func setPhoneNumber(_ phoneNumber: String) {
- self.setModifyingProfileUI()
- NCAPIController.sharedInstance().setUserProfileField(kUserProfilePhone, withValue: phoneNumber, for: account) { error, _ in
- if error != nil {
- self.showProfileModificationErrorForField(inTextField: self.kPhoneTextFieldTag, textField: nil)
- } else {
- self.refreshUserProfile()
- }
- self.removeModifyingProfileUI()
- }
- }
- }
|