Skip to content
Snippets Groups Projects
Commit b7680f15 authored by Alireza Toghyiani's avatar Alireza Toghyiani Committed by Kateryna Kostiuk
Browse files

Redesign Sip Configuration Form

Gitlab: #291

Change-Id: Ic87ceba2d52c3b2abdb02462d9f2602b60a60fd3
parent 50d9ebac
Branches
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@ internal enum L10n {
internal static let accountStatus = L10n.tr("Localizable", "account.accountStatus", fallback: "Account Status")
/// Advanced Features
internal static let advancedFeatures = L10n.tr("Localizable", "account.advancedFeatures", fallback: "Advanced Features")
/// Configure
internal static let configure = L10n.tr("Localizable", "account.configure", fallback: "Configure")
/// Configure a SIP Account
internal static let createSipAccount = L10n.tr("Localizable", "account.createSipAccount", fallback: "Configure a SIP Account")
/// Enable Account
......@@ -31,6 +33,8 @@ internal enum L10n {
internal static let proxyServer = L10n.tr("Localizable", "account.proxyServer", fallback: "Proxy")
/// Enter Address
internal static let serverLabel = L10n.tr("Localizable", "account.serverLabel", fallback: "Enter Address")
/// SIP Account
internal static let sipAccount = L10n.tr("Localizable", "account.sipAccount", fallback: "SIP Account")
/// SIP Server
internal static let sipServer = L10n.tr("Localizable", "account.sipServer", fallback: "SIP Server")
/// User Name
......
......@@ -25,49 +25,50 @@ import RxSwift
class CreateSipAccountViewController: UIViewController, StoryboardBased, ViewModelBased {
var viewModel: CreateSipAccountViewModel!
@IBOutlet weak var createAccountButton: DesignableButton!
@IBOutlet weak var passwordTextField: DesignableTextField!
@IBOutlet weak var userNameTextField: DesignableTextField!
@IBOutlet weak var serverTextField: DesignableTextField!
@IBOutlet weak var portTextField: DesignableTextField!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var cancelButton: DesignableButton!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var createAccountButton: DesignableButton!
@IBOutlet weak var containerViewBottomConstraint: NSLayoutConstraint!
@IBOutlet weak var userNameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var serverTextField: UITextField!
@IBOutlet weak var userNameLabel: UILabel!
@IBOutlet weak var passwordLabel: UILabel!
@IBOutlet weak var serverLabel: UILabel!
@IBOutlet weak var portLabel: UILabel!
@IBOutlet weak var backgroundView: UIView!
var keyboardDismissTapRecognizer: UITapGestureRecognizer!
var isKeyboardOpened: Bool = false
var disposeBag = DisposeBag()
weak var containerViewHeightConstraint: NSLayoutConstraint?
let formHeight: CGFloat = 258
override func viewDidLoad() {
self.applyL10n()
super.viewDidLoad()
setupUI()
self.buindViewToViewModel()
self.configureWalkrhroughNavigationBar()
self.userNameTextField.becomeFirstResponder()
self.configurePasswordField()
self.createAccountButton.applyGradient(with: [UIColor.jamiButtonLight, UIColor.jamiButtonDark], gradient: .horizontal)
createAccountButton.titleLabel?.ajustToTextSize()
// handle keyboard
self.adaptToKeyboardState(for: self.scrollView, with: self.disposeBag)
keyboardDismissTapRecognizer = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
NotificationCenter.default.rx
.notification(UIDevice.orientationDidChangeNotification)
adaptToSystemColor()
self.adaptToWelcomeFormKeyboardState(for: self.scrollView, with: self.disposeBag)
NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification)
.observe(on: MainScheduler.instance)
.subscribe(onNext: { [weak self] (_) in
guard UIDevice.current.portraitOrLandscape else { return }
self?.createAccountButton.updateGradientFrame()
self?.configureWalkrhroughNavigationBar()
self?.setupUI()
})
.disposed(by: self.disposeBag)
adaptToSystemColor()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillAppear(withNotification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillDisappear(withNotification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
setupUI()
}
override func viewWillDisappear(_ animated: Bool) {
......@@ -76,60 +77,97 @@ class CreateSipAccountViewController: UIViewController, StoryboardBased, ViewMod
}
func adaptToSystemColor() {
view.backgroundColor = UIColor.jamiBackgroundColor
backgroundView.backgroundColor = UIColor.jamiBackgroundColor
scrollView.backgroundColor = UIColor.jamiBackgroundColor
view.backgroundColor = .clear
userNameLabel.textColor = UIColor.jamiTextSecondary
passwordLabel.textColor = UIColor.jamiTextSecondary
serverLabel.textColor = UIColor.jamiTextSecondary
portLabel.textColor = UIColor.jamiTextSecondary
userNameTextField.backgroundColor = UIColor.jamiBackgroundColor
passwordTextField.backgroundColor = UIColor.jamiBackgroundColor
serverTextField.backgroundColor = UIColor.jamiBackgroundColor
portTextField.backgroundColor = UIColor.jamiBackgroundColor
userNameTextField.borderColor = UIColor.jamiTextBlue
passwordTextField.borderColor = UIColor.jamiTextBlue
serverTextField.borderColor = UIColor.jamiTextBlue
portTextField.borderColor = UIColor.jamiTextBlue
userNameTextField.tintColor = UIColor.jamiSecondary
passwordTextField.tintColor = UIColor.jamiSecondary
serverTextField.tintColor = UIColor.jamiSecondary
createAccountButton.tintColor = .jamiButtonDark
}
@objc
func dismissKeyboard() {
self.isKeyboardOpened = false
view.endEditing(true)
view.removeGestureRecognizer(keyboardDismissTapRecognizer)
func setContentInset(keyboardHeight: CGFloat = 0) {
self.containerViewBottomConstraint.constant = keyboardHeight
}
@objc
func keyboardWillAppear(withNotification: NSNotification) {
func keyboardWillAppear(withNotification notification: NSNotification) {
self.isKeyboardOpened = true
self.view.addGestureRecognizer(keyboardDismissTapRecognizer)
if let userInfo = notification.userInfo,
let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect,
ScreenHelper.welcomeFormPresentationStyle() != .fullScreen {
let keyboardHeight = keyboardFrame.size.height
self.setContentInset(keyboardHeight: keyboardHeight)
}
}
@objc
func keyboardWillDisappear(withNotification: NSNotification) {
self.setContentInset()
}
func setupUI() {
let welcomeFormPresentationStyle = ScreenHelper.welcomeFormPresentationStyle()
if welcomeFormPresentationStyle == .fullScreen {
contentView.removeCorners()
view.backgroundColor = .secondarySystemBackground
} else {
DispatchQueue.main.async { [weak self] in
self?.contentView.roundTopCorners(radius: 12)
}
view.backgroundColor = .clear
}
DispatchQueue.main.async { [weak self] in
self?.setupConstraint()
self?.view.setNeedsLayout()
self?.view.layoutIfNeeded()
}
}
func setupConstraint() {
// Remove the existing top constraint (if it exists)
containerViewHeightConstraint?.isActive = false
containerViewHeightConstraint = nil
// Create a new constraint with the desired relationship
let newConstraint: NSLayoutConstraint
if ScreenHelper.welcomeFormPresentationStyle() == .fullScreen || UIDevice.current.userInterfaceIdiom == .pad {
newConstraint = contentView.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.size.height)
} else {
newConstraint = contentView.heightAnchor.constraint(equalToConstant: formHeight)
}
// Activate the constraint
newConstraint.isActive = true
// Assign it to the property for later reference
containerViewHeightConstraint = newConstraint
}
func configurePasswordField() {
passwordTextField.isSecureTextEntry = true
let isSecureTextEntry = PublishSubject<Bool>()
let rightButton = UIButton(type: .custom)
rightButton.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
rightButton.setImage(UIImage(asset: Asset.icHideInput), for: .normal)
passwordTextField.rx.text.orEmpty.distinctUntilChanged()
.bind { text in
rightButton.isHidden = text.isEmpty
rightButton.isEnabled = !text.isEmpty
.bind { [weak rightButton] text in
rightButton?.isHidden = text.isEmpty
rightButton?.isEnabled = !text.isEmpty
}
.disposed(by: self.disposeBag)
passwordTextField.rightViewMode = .always
let rightView = UIView(frame: CGRect( x: 0, y: 0, width: 50, height: 30))
rightView.addSubview(rightButton)
passwordTextField.rightView = rightView
passwordTextField.leftViewMode = .always
let leftView = UIView(frame: CGRect( x: 0, y: 0, width: 50, height: 30))
rightButton.tintColor = UIColor.darkGray
passwordTextField.leftView = leftView
rightButton.rx.tap
.subscribe(onNext: { [weak self, isSecureTextEntry] _ in
.subscribe(onNext: { [weak self, weak isSecureTextEntry] _ in
guard let self = self else { return }
self.passwordTextField.isSecureTextEntry.toggle()
isSecureTextEntry
isSecureTextEntry?
.onNext(self.passwordTextField.isSecureTextEntry)
})
.disposed(by: self.disposeBag)
......@@ -155,9 +193,6 @@ class CreateSipAccountViewController: UIViewController, StoryboardBased, ViewMod
.disposed(by: self.disposeBag)
self.passwordTextField.rx.text.orEmpty.bind(to: self.viewModel.password).disposed(by: self.disposeBag)
self.serverTextField.rx.text.orEmpty.bind(to: self.viewModel.sipServer).disposed(by: self.disposeBag)
self.portTextField.rx.text.orEmpty
.bind(to: self.viewModel.port)
.disposed(by: self.disposeBag)
self.createAccountButton.rx.tap
.subscribe(onNext: { [weak self] in
guard let self = self else { return }
......@@ -166,19 +201,22 @@ class CreateSipAccountViewController: UIViewController, StoryboardBased, ViewMod
}
})
.disposed(by: self.disposeBag)
self.cancelButton.rx.tap
.subscribe(onNext: { [weak self] in
guard let self = self else { return }
self.dismiss(animated: true)
})
.disposed(by: self.disposeBag)
}
func applyL10n() {
self.createAccountButton
.setTitle(L10n.Account.createSipAccount, for: .normal)
self.navigationItem.title = L10n.Account.createSipAccount
self.createAccountButton.setTitle(L10n.Account.configure, for: .normal)
titleLabel.text = L10n.Account.sipAccount
self.userNameLabel.text = L10n.Global.enterUsername
self.passwordLabel.text = L10n.Global.enterPassword
self.serverLabel.text = L10n.Account.serverLabel
self.portLabel.text = L10n.Account.portLabel
self.passwordTextField.placeholder = L10n.Global.password
self.userNameTextField.placeholder = L10n.Account.sipUsername
self.serverTextField.placeholder = L10n.Account.sipServer
self.portTextField.placeholder = L10n.Account.port
}
}
......@@ -31,7 +31,6 @@ class CreateSipAccountViewModel: Stateable, ViewModel {
var userName = BehaviorRelay<String>(value: "")
var password = BehaviorRelay<String>(value: "")
var sipServer = BehaviorRelay<String>(value: "")
var port = BehaviorRelay<String>(value: "")
private let accountsService: AccountsService
required init(with injectionBag: InjectionBag) {
......@@ -41,8 +40,7 @@ class CreateSipAccountViewModel: Stateable, ViewModel {
func createSipaccount() {
let created = self.accountsService.addSipAccount(userName: userName.value,
password: password.value,
sipServer: sipServer.value,
port: port.value)
sipServer: sipServer.value)
if created {
DispatchQueue.main.async {
self.stateSubject.onNext(WalkthroughState.accountCreated)
......
......@@ -53,7 +53,6 @@ class LinkToAccountManagerViewController: UIViewController, StoryboardBased, Vie
configurePasswordField()
self.userNameTextField.becomeFirstResponder()
signInButton.titleLabel?.ajustToTextSize()
configureWalkrhroughNavigationBar()
self.adaptToWelcomeFormKeyboardState(for: self.scrollView, with: self.disposeBag)
NotificationCenter.default.rx.notification(UIDevice.orientationDidChangeNotification)
......
......@@ -101,7 +101,7 @@ class WalkthroughCoordinator: Coordinator, StateableResponsive {
self.present(viewController: createAccountViewController, withStyle: .formModal, withAnimation: true, withStateable: createAccountViewController.viewModel)
case .createSipAccount:
let sipAccountViewController = CreateSipAccountViewController.instantiate(with: self.injectionBag)
self.present(viewController: sipAccountViewController, withStyle: .show, withAnimation: true, withStateable: sipAccountViewController.viewModel)
self.present(viewController: sipAccountViewController, withStyle: .formModal, withAnimation: true, withStateable: sipAccountViewController.viewModel)
case .linkDevice:
let linkDeviceViewController = LinkDeviceViewController.instantiate(with: self.injectionBag)
self.present(viewController: linkDeviceViewController, withStyle: .formModal, withAnimation: true, withStateable: linkDeviceViewController.viewModel)
......
......@@ -296,6 +296,8 @@
"account.port" = "Port";
"account.proxyServer" = "Proxy";
"account.createSipAccount" = "Configure a SIP Account";
"account.sipAccount" = "SIP Account";
"account.configure" = "Configure";
"account.advancedFeatures" = "Advanced Features";
"account.serverLabel" = "Enter Address";
"account.portLabel" = "Enter Port Number";
......
......@@ -349,16 +349,12 @@ class AccountsService: AccountAdapterDelegate {
func addSipAccount(userName: String,
password: String,
sipServer: String,
port: String) -> Bool {
sipServer: String) -> Bool {
do {
var accountDetails = try self.getInitialAccountDetails(accountType: AccountType.sip.rawValue)
accountDetails.updateValue(userName, forKey: ConfigKey.accountUsername.rawValue)
accountDetails.updateValue(sipServer, forKey: ConfigKey.accountHostname.rawValue)
accountDetails.updateValue(password, forKey: ConfigKey.accountPassword.rawValue)
if !port.isEmpty {
accountDetails.updateValue(port, forKey: ConfigKey.localPort.rawValue)
}
guard let account = self.accountAdapter.addAccount(accountDetails) else { return false }
_ = try self.dbManager.createDatabaseForAccount(accountId: account, createFolder: true)
self.loadAccountsFromDaemon()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment