|
@@ -7,53 +7,50 @@
|
|
//
|
|
//
|
|
|
|
|
|
import UIKit
|
|
import UIKit
|
|
-import JGProgressHUD
|
|
|
|
-
|
|
|
|
|
|
|
|
class AccountSetupController: UITableViewController {
|
|
class AccountSetupController: UITableViewController {
|
|
-
|
|
|
|
|
|
+
|
|
var backupProgressObserver: Any?
|
|
var backupProgressObserver: Any?
|
|
var configureProgressObserver: Any?
|
|
var configureProgressObserver: Any?
|
|
-
|
|
|
|
|
|
+
|
|
lazy var hudHandler: HudHandler = {
|
|
lazy var hudHandler: HudHandler = {
|
|
let hudHandler = HudHandler(parentView: self.tableView)
|
|
let hudHandler = HudHandler(parentView: self.tableView)
|
|
return hudHandler
|
|
return hudHandler
|
|
}()
|
|
}()
|
|
-
|
|
|
|
|
|
+
|
|
lazy var emailCell:InputTableViewCell = {
|
|
lazy var emailCell:InputTableViewCell = {
|
|
- let cell = InputTableViewCell()
|
|
|
|
|
|
+ let cell = InputTableViewCell()
|
|
cell.textLabel?.text = "Email"
|
|
cell.textLabel?.text = "Email"
|
|
cell.inputField.placeholder = "user@example.com"
|
|
cell.inputField.placeholder = "user@example.com"
|
|
return cell
|
|
return cell
|
|
}()
|
|
}()
|
|
-
|
|
|
|
|
|
+
|
|
lazy var passwordCell:PasswordInputCell = {
|
|
lazy var passwordCell:PasswordInputCell = {
|
|
let cell = PasswordInputCell()
|
|
let cell = PasswordInputCell()
|
|
cell.textLabel?.text = "Password"
|
|
cell.textLabel?.text = "Password"
|
|
cell.inputField.placeholder = "Required"
|
|
cell.inputField.placeholder = "Required"
|
|
return cell
|
|
return cell
|
|
}()
|
|
}()
|
|
-
|
|
|
|
- init() {
|
|
|
|
- super.init(style: .grouped)
|
|
|
|
- tableView.allowsSelection = false
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- required init?(coder aDecoder: NSCoder) {
|
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- override func viewDidLoad() {
|
|
|
|
- super.viewDidLoad()
|
|
|
|
- self.title = "Login to your server"
|
|
|
|
- self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(loginButtonPressed))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ init() {
|
|
|
|
+ super.init(style: .grouped)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ required init?(coder aDecoder: NSCoder) {
|
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ override func viewDidLoad() {
|
|
|
|
+ super.viewDidLoad()
|
|
|
|
+ self.title = "Login to your server"
|
|
|
|
+ self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Login", style: .done, target: self, action: #selector(loginButtonPressed))
|
|
|
|
+ }
|
|
|
|
+
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
super.viewDidAppear(animated)
|
|
addProgressHudEventListener()
|
|
addProgressHudEventListener()
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
override func viewDidDisappear(_ animated: Bool) {
|
|
let nc = NotificationCenter.default
|
|
let nc = NotificationCenter.default
|
|
if let backupProgressObserver = self.backupProgressObserver {
|
|
if let backupProgressObserver = self.backupProgressObserver {
|
|
@@ -66,13 +63,13 @@ class AccountSetupController: UITableViewController {
|
|
|
|
|
|
// MARK: - Table view data source
|
|
// MARK: - Table view data source
|
|
|
|
|
|
- override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
- // #warning Incomplete implementation, return the number of sections
|
|
|
|
- return 2
|
|
|
|
- }
|
|
|
|
|
|
+ override func numberOfSections(in tableView: UITableView) -> Int {
|
|
|
|
+ // #warning Incomplete implementation, return the number of sections
|
|
|
|
+ return 2
|
|
|
|
+ }
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
- // #warning Incomplete implementation, return the number of rows
|
|
|
|
|
|
+ // #warning Incomplete implementation, return the number of rows
|
|
if section == 0 {
|
|
if section == 0 {
|
|
return 2
|
|
return 2
|
|
} else {
|
|
} else {
|
|
@@ -84,24 +81,22 @@ class AccountSetupController: UITableViewController {
|
|
if section == 1 {
|
|
if section == 1 {
|
|
return "Advanced"
|
|
return "Advanced"
|
|
} else {
|
|
} else {
|
|
- return nil
|
|
|
|
|
|
+ return nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/*
|
|
/*
|
|
- override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
- if section == 0 {
|
|
|
|
- return nil
|
|
|
|
- } else {
|
|
|
|
- let label = UILabel()
|
|
|
|
- label.text = "Advanced"
|
|
|
|
- return label
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
|
|
+ override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
+ if section == 0 {
|
|
|
|
+ return nil
|
|
|
|
+ } else {
|
|
|
|
+ let label = UILabel()
|
|
|
|
+ label.text = "Advanced"
|
|
|
|
+ return label
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
|
|
if section == 0 {
|
|
if section == 0 {
|
|
return "There are no Delta Chat servers, your data stays on your device!"
|
|
return "There are no Delta Chat servers, your data stays on your device!"
|
|
@@ -118,20 +113,48 @@ class AccountSetupController: UITableViewController {
|
|
return passwordCell
|
|
return passwordCell
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
+ // handle tap on password
|
|
|
|
+ print(indexPath)
|
|
|
|
+ }
|
|
|
|
+
|
|
@objc func loginButtonPressed() {
|
|
@objc func loginButtonPressed() {
|
|
- guard let emailAdress = emailCell.getText() else {
|
|
|
|
|
|
+ guard let emailAddress = emailCell.getText() else {
|
|
return // handle case when either email or pw fields are empty
|
|
return // handle case when either email or pw fields are empty
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ let oAuthStared = showOAuthAlertIfNeeded(emailAddress: emailAddress)
|
|
|
|
+
|
|
|
|
+ if oAuthStared {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
let passWord = passwordCell.getText() ?? "" // empty passwords are ok -> for oauth there is no password needed
|
|
let passWord = passwordCell.getText() ?? "" // empty passwords are ok -> for oauth there is no password needed
|
|
-
|
|
|
|
- MRConfig.addr = emailAdress
|
|
|
|
|
|
+
|
|
|
|
+ MRConfig.addr = emailAddress
|
|
MRConfig.mailPw = passWord
|
|
MRConfig.mailPw = passWord
|
|
dc_configure(mailboxPointer)
|
|
dc_configure(mailboxPointer)
|
|
hudHandler.showBackupHud("Configuring account")
|
|
hudHandler.showBackupHud("Configuring account")
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ // returns true if needed
|
|
|
|
+ private func showOAuthAlertIfNeeded(emailAddress: String) -> Bool {
|
|
|
|
+ guard let oAuth2UrlPointer = dc_get_oauth2_url(mailboxPointer, emailAddress, "chat.delta:/auth") else {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ let oAuth2Url = String(cString: oAuth2UrlPointer)
|
|
|
|
+
|
|
|
|
+ // TODO: open webView with url
|
|
|
|
+ if let url = URL.init(string: oAuth2Url) {
|
|
|
|
+ UIApplication.shared.open(url)
|
|
|
|
+ return true
|
|
|
|
+ } else {
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private func addProgressHudEventListener() {
|
|
private func addProgressHudEventListener() {
|
|
let nc = NotificationCenter.default
|
|
let nc = NotificationCenter.default
|
|
backupProgressObserver = nc.addObserver(
|
|
backupProgressObserver = nc.addObserver(
|
|
@@ -147,6 +170,7 @@ class AccountSetupController: UITableViewController {
|
|
self.hudHandler.setHudDone(callback: nil)
|
|
self.hudHandler.setHudDone(callback: nil)
|
|
} else {
|
|
} else {
|
|
self.hudHandler.setHudProgress(ui["progress"] as! Int)
|
|
self.hudHandler.setHudProgress(ui["progress"] as! Int)
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -163,21 +187,19 @@ class AccountSetupController: UITableViewController {
|
|
self.hudHandler.setHudDone(callback: nil)
|
|
self.hudHandler.setHudDone(callback: nil)
|
|
} else {
|
|
} else {
|
|
self.hudHandler.setHudProgress(ui["progress"] as! Int)
|
|
self.hudHandler.setHudProgress(ui["progress"] as! Int)
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
class InputTableViewCell: UITableViewCell {
|
|
class InputTableViewCell: UITableViewCell {
|
|
-
|
|
|
|
lazy var inputField: UITextField = {
|
|
lazy var inputField: UITextField = {
|
|
let textField = UITextField()
|
|
let textField = UITextField()
|
|
return textField
|
|
return textField
|
|
}()
|
|
}()
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
init() {
|
|
init() {
|
|
super.init(style: .default, reuseIdentifier: nil)
|
|
super.init(style: .default, reuseIdentifier: nil)
|
|
setupView()
|
|
setupView()
|
|
@@ -186,128 +208,57 @@ class InputTableViewCell: UITableViewCell {
|
|
required init?(coder aDecoder: NSCoder) {
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private func setupView() {
|
|
private func setupView() {
|
|
contentView.addSubview(inputField)
|
|
contentView.addSubview(inputField)
|
|
inputField.translatesAutoresizingMaskIntoConstraints = false
|
|
inputField.translatesAutoresizingMaskIntoConstraints = false
|
|
-
|
|
|
|
inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
|
|
inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
|
|
inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
|
|
inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
|
|
inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
|
|
inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
|
|
inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
|
|
inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
|
|
inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
|
|
inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
|
|
}
|
|
}
|
|
-
|
|
|
|
public func getText() -> String? {
|
|
public func getText() -> String? {
|
|
- return inputField.text
|
|
|
|
|
|
+ return inputField.text
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
class PasswordInputCell: UITableViewCell {
|
|
class PasswordInputCell: UITableViewCell {
|
|
-
|
|
|
|
lazy var inputField: UITextField = {
|
|
lazy var inputField: UITextField = {
|
|
let textField = UITextField()
|
|
let textField = UITextField()
|
|
textField.isSecureTextEntry = true
|
|
textField.isSecureTextEntry = true
|
|
return textField
|
|
return textField
|
|
}()
|
|
}()
|
|
-
|
|
|
|
|
|
+
|
|
// TODO: to add Eye-icon -> uncomment -> add to inputField.rightView
|
|
// TODO: to add Eye-icon -> uncomment -> add to inputField.rightView
|
|
/*
|
|
/*
|
|
- lazy var makeVisibleIcon: UIImageView = {
|
|
|
|
- let view = UIImageView(image: )
|
|
|
|
- return view
|
|
|
|
- }()
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
|
|
+ lazy var makeVisibleIcon: UIImageView = {
|
|
|
|
+ let view = UIImageView(image: )
|
|
|
|
+ return view
|
|
|
|
+ }()
|
|
|
|
+ */
|
|
init() {
|
|
init() {
|
|
super.init(style: .default, reuseIdentifier: nil)
|
|
super.init(style: .default, reuseIdentifier: nil)
|
|
setupView()
|
|
setupView()
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
required init?(coder aDecoder: NSCoder) {
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
private func setupView() {
|
|
private func setupView() {
|
|
contentView.addSubview(inputField)
|
|
contentView.addSubview(inputField)
|
|
inputField.translatesAutoresizingMaskIntoConstraints = false
|
|
inputField.translatesAutoresizingMaskIntoConstraints = false
|
|
-
|
|
|
|
inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
|
|
inputField.centerYAnchor.constraint(equalTo: contentView.centerYAnchor, constant: 0).isActive = true
|
|
inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
|
|
inputField.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 5).isActive = true
|
|
inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
|
|
inputField.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -5).isActive = true
|
|
inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
|
|
inputField.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 100).isActive = true
|
|
inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
|
|
inputField.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 0).isActive = true
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public func getText() -> String? {
|
|
public func getText() -> String? {
|
|
- return inputField.text
|
|
|
|
|
|
+ return inputField.text
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-class HudHandler {
|
|
|
|
-
|
|
|
|
- var backupHud: JGProgressHUD?
|
|
|
|
- var view:UIView
|
|
|
|
-
|
|
|
|
- init(parentView: UIView) {
|
|
|
|
- self.view = parentView
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- func setHudProgress(_ progress: Int) {
|
|
|
|
- if let hud = self.backupHud {
|
|
|
|
- hud.progress = Float(progress) / 1000.0
|
|
|
|
- hud.detailTextLabel.text = "\(progress / 10)% Complete"
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func showBackupHud(_ text: String) {
|
|
|
|
- DispatchQueue.main.async {
|
|
|
|
- let hud = JGProgressHUD(style: .dark)
|
|
|
|
- hud.vibrancyEnabled = true
|
|
|
|
- hud.indicatorView = JGProgressHUDPieIndicatorView()
|
|
|
|
-
|
|
|
|
- hud.detailTextLabel.text = "0% Complete"
|
|
|
|
- hud.textLabel.text = text
|
|
|
|
- hud.show(in: self.view)
|
|
|
|
-
|
|
|
|
- self.backupHud = hud
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- func setHudError(_ message: String?) {
|
|
|
|
- if let hud = self.backupHud {
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
|
|
|
|
- UIView.animate(
|
|
|
|
- withDuration: 0.1, animations: {
|
|
|
|
- hud.textLabel.text = message ?? "Error"
|
|
|
|
- hud.detailTextLabel.text = nil
|
|
|
|
- hud.indicatorView = JGProgressHUDErrorIndicatorView()
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- hud.dismiss(afterDelay: 5.0)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- func setHudDone(callback: (()->())?) {
|
|
|
|
- if let hud = self.backupHud {
|
|
|
|
- DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
|
|
|
|
- UIView.animate(
|
|
|
|
- withDuration: 0.1, animations: {
|
|
|
|
- hud.textLabel.text = "Success"
|
|
|
|
- hud.detailTextLabel.text = nil
|
|
|
|
- hud.indicatorView = JGProgressHUDSuccessIndicatorView()
|
|
|
|
- }
|
|
|
|
- )
|
|
|
|
-
|
|
|
|
- callback?()
|
|
|
|
- hud.dismiss(afterDelay: 1.0)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|