Commit 775b38d6 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

account: add proxy

Add proxy server to Sip account

Change-Id: If0ab751f732e5bd6ba343705cf25cdbb7fc292d3
parent b4c7ca16
......@@ -25,6 +25,8 @@ internal enum L10n {
internal static let port = L10n.tr("Localizable", "account.port")
/// Enter Port Number
internal static let portLabel = L10n.tr("Localizable", "account.portLabel")
/// Proxy
internal static let proxyServer = L10n.tr("Localizable", "account.proxyServer")
/// Enter Address
internal static let serverLabel = L10n.tr("Localizable", "account.serverLabel")
/// Password
......
......@@ -361,6 +361,11 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
.configureSipCredentialsCell(cellType: .sipServer(value: value),
value: value)
return cell
case .proxyServer(let value):
let cell = self
.configureSipCredentialsCell(cellType: .proxyServer(value: value),
value: value)
return cell
case .port(let value):
let cell = self
.configureSipCredentialsCell(cellType: .port(value: value),
......@@ -441,6 +446,11 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
.bind(to: self.viewModel.port)
.disposed(by: cell.disposeBag)
cell.textLabel?.text = L10n.Account.port
case .proxyServer:
text.rx.text.orEmpty.distinctUntilChanged()
.bind(to: self.viewModel.proxyServer)
.disposed(by: cell.disposeBag)
cell.textLabel?.text = L10n.Account.proxyServer
case .sipServer:
text.rx.text.orEmpty.distinctUntilChanged()
.bind(to: self.viewModel.sipServer)
......@@ -493,12 +503,14 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
func calculateSipCredentialsMargin() {
let margin: CGFloat = 30
var usernameLength, passwordLength,
sipServerLength, portLength, statusLength: CGFloat
sipServerLength, portLength,
statusLength, proxyLength: CGFloat
let username = L10n.Account.sipUsername
let password = L10n.Account.sipPassword
let sipServer = L10n.Account.port
let port = L10n.Account.sipServer
let status = L10n.Account.accountStatus
let proxy = L10n.Account.proxyServer
let label = UITextView()
label.font = UIFont.systemFont(ofSize: 16, weight: .regular)
label.text = status
......@@ -516,7 +528,10 @@ class MeViewController: EditProfileViewController, StoryboardBased, ViewModelBas
label.text = port
label.sizeToFit()
portLength = label.frame.size.width
sipCredentialsMargin = max(max(max(max(usernameLength, passwordLength), sipServerLength), portLength), statusLength) + margin
label.text = proxy
label.sizeToFit()
proxyLength = label.frame.size.width
sipCredentialsMargin = max(max(max(max(max(usernameLength, passwordLength), sipServerLength), portLength), statusLength), proxyLength) + margin
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
......
......@@ -45,6 +45,7 @@ enum SettingsSection: SectionModelType {
case sipPassword(value: String)
case sipServer(value: String)
case port(value: String)
case proxyServer(value: String)
case accountState(state: Variable<String>)
case enableAccount
}
......@@ -209,6 +210,7 @@ class MeViewModel: ViewModel, Stateable {
var password = ""
var server = ""
var port = ""
var proxyServer = ""
if let account = self.accountService.currentAccount,
let details = account.details,
let credentials = account.credentialDetails.first {
......@@ -216,16 +218,27 @@ class MeViewModel: ViewModel, Stateable {
password = credentials.password
server = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountHostname))
port = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .localPort))
proxyServer = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountRouteSet))
self.sipUsername.value = username
self.sipPassword.value = password
self.sipServer.value = server
self.port.value = port
self.proxyServer.value = proxyServer
}
//isIP2IP
if server.isEmpty {
return .accountSettings( items: [.sectionHeader(title: ""),
.sipUserName(value: username),
.sipPassword(value: password),
.sipServer(value: server)])
}
return .accountSettings( items: [.sectionHeader(title: ""),
.sipUserName(value: username),
.sipPassword(value: password),
.sipServer(value: server),
.port(value: port)])
.port(value: port),
.proxyServer(value: proxyServer)])
}
}()
......@@ -527,6 +540,7 @@ class MeViewModel: ViewModel, Stateable {
let sipPassword = Variable<String>("")
let sipServer = Variable<String>("")
let port = Variable<String>("")
let proxyServer = Variable<String>("")
func updateSipSettings() {
guard let account = self.accountService.currentAccount, let details = account.details, let credentials = account.credentialDetails.first else {return}
......@@ -538,9 +552,12 @@ class MeViewModel: ViewModel, Stateable {
let server = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountHostname))
let port = details.get(withConfigKeyModel:
ConfigKeyModel.init(withKey: .localPort))
let proxy = details.get(withConfigKeyModel: ConfigKeyModel.init(withKey: .accountRouteSet))
if username == sipUsername.value
&& password == sipPassword.value
&& server == sipServer.value && port == self.port.value {
&& server == sipServer.value
&& port == self.port.value
&& proxy == self.proxyServer.value {
return
}
if username != sipUsername.value || password != sipPassword.value {
......@@ -552,10 +569,12 @@ class MeViewModel: ViewModel, Stateable {
}
if server != sipServer.value ||
port != self.port.value ||
username != sipUsername.value {
username != sipUsername.value ||
proxy != self.proxyServer.value {
details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountHostname), withValue: sipServer.value)
details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.localPort), withValue: self.port.value)
details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountUsername), withValue: self.sipUsername.value)
details.set(withConfigKeyModel: ConfigKeyModel(withKey: ConfigKey.accountRouteSet), withValue: self.proxyServer.value)
account.details = details
self.accountService.setAccountDetails(forAccountId: account.id, withDetails: details)
}
......
......@@ -173,6 +173,7 @@
"account.sipPassword" = "Password";
"account.sipServer" = "SIP Server";
"account.port" = "Port";
"account.proxyServer" = "Proxy";
"account.createSipAccount" = "Create Sip Account";
"account.usernameLabel" = "Enter Username";
"account.passwordLabel" = "Enter Password";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment