diff --git a/Ring/Ring/Features/Me/Me/MeViewController.swift b/Ring/Ring/Features/Me/Me/MeViewController.swift index 9bcfeb7d9e184c816a3eaee6b715a2b132a0fc70..315d1f82d53af8603ad5e4b1e33a7ebe6028a193 100644 --- a/Ring/Ring/Features/Me/Me/MeViewController.swift +++ b/Ring/Ring/Features/Me/Me/MeViewController.swift @@ -512,6 +512,45 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas }) .disposed(by: cell.disposeBag) return cell + case .proxy: + let cell = DisposableCell(style: .value1, reuseIdentifier: self.sipAccountCredentialsCell) + cell.backgroundColor = UIColor.jamiBackgroundColor + cell.selectionStyle = .none + let text = UITextField() + text.autocorrectionType = .no + text.font = UIFont.preferredFont(forTextStyle: .callout) + text.returnKeyType = .done + text.text = self.viewModel.proxyAddress.value + text.sizeToFit() + text.rx.controlEvent(.editingDidEndOnExit) + .observe(on: MainScheduler.instance) + .subscribe(onNext: { [weak self] _ in + guard let text = text.text else { return } + self?.viewModel.changeProxy(proxyServer: text) + }) + .disposed(by: cell.disposeBag) + cell.textLabel?.text = "Proxy server" + cell.textLabel?.sizeToFit() + cell.sizeToFit() + cell.detailTextLabel?.font = UIFont.preferredFont(forTextStyle: .callout) + cell.detailTextLabel?.textColor = UIColor.clear + var frame = CGRect(x: self.sipCredentialsMargin, y: 0, + width: self.view.frame.width - self.sipCredentialsMargin, + height: cell.frame.height) + if self.view.frame.width - self.sipCredentialsMargin < text.frame.size.width { + let origin = CGPoint(x: 10, y: cell.textLabel!.frame.size.height + 25) + let size = text.frame.size + frame.origin = origin + frame.size = size + cell.detailTextLabel?.text = self.viewModel.proxyAddress.value + } else { + cell.detailTextLabel?.text = "" + } + cell.detailTextLabel?.sizeToFit() + text.frame = frame + cell.contentView.addSubview(text) + cell.sizeToFit() + return cell case .sipUserName(let value): let cell = self .configureSipCredentialsCell(cellType: .sipUserName(value: value), diff --git a/Ring/Ring/Features/Me/Me/MeViewModel.swift b/Ring/Ring/Features/Me/Me/MeViewModel.swift index d15e33b6dcda073f664397be25994429e5ff2598..fa4b14d34e671fc7f02274635f03fc18852c7636 100644 --- a/Ring/Ring/Features/Me/Me/MeViewModel.swift +++ b/Ring/Ring/Features/Me/Me/MeViewModel.swift @@ -51,6 +51,7 @@ enum SettingsSection: SectionModelType { case jamiUserName(label: String) case notifications case sipUserName(value: String) + case proxy case sipPassword(value: String) case sipServer(value: String) case port(value: String) @@ -261,9 +262,17 @@ class MeViewModel: ViewModel, Stateable { }() lazy var otherJamiSettings: Observable<SettingsSection> = { + var proxyServer = "" + if let account = self.accountService.currentAccount, + let details = account.details { + proxyServer = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: ConfigKey.proxyServer)) + self.proxyAddress.accept(proxyServer) + } let items: [SettingsSection.SectionRow] = [.peerDiscovery, .blockedList, - .accountState(state: self.accountStatus), + .proxy, + SettingsSection.SectionRow + .accountState(state: self.accountStatus), .enableAccount, .changePassword, .boothMode] @@ -504,7 +513,6 @@ class MeViewModel: ViewModel, Stateable { self.showActionState.accept(.hideLoading) return } - self.nameService .registerNameObservable(withAccount: accountId, password: password, @@ -825,6 +833,15 @@ class MeViewModel: ViewModel, Stateable { self.accountService.enableTurn(enable: enable, accountId: account.id) turnEnabled.accept(enable) } + let proxyAddress = BehaviorRelay<String>(value: "") + + func changeProxy(proxyServer: String) { + guard let accountId = self.accountService.currentAccount?.id else { + return + } + self.accountService.setProxyAddress(accountID: accountId, proxy: proxyServer) + self.proxyAddress.accept(proxyServer) + } func enableUpnp(enable: Bool) { guard self.upnpEnabled.value != enable,