Skip to content

Commit

Permalink
Merge pull request #585 from NordicSemiconductor/bugfix/proxy
Browse files Browse the repository at this point in the history
[App] Fixed behavior on Proxy screen
  • Loading branch information
philips77 authored Nov 12, 2023
2 parents 2447816 + 0dbbbef commit 45e94cc
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,33 @@ private extension AddAddressViewController {
extension AddAddressViewController: ProxyFilterDelegate {

func proxyFilterUpdated(type: ProxyFilerType, addresses: Set<Address>) {
done {
self.dismiss(animated: true)
}
// As we want different behavior when the list was acknowledged
// or the list limit was reached, to nothing here.
}

func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
// TODO: dismiss here?
// This method is also called when the Proxy Node gets disconnected.
// In that case, the list size is equal to 0.
if listSize > 0 {
done {
self.dismiss(animated: true)
}
}
}

func proxyFilterLimitReached(type: ProxyFilerType, maxSize: UInt16) {
done {
self.presentAlert(
title: "Maximum filter size reached",
message: """
The connected proxy node supports only \(maxSize) addresses on its Proxy Filter list.
Some addresses were not added.
"""
) { _ in
self.dismiss(animated: true)
}
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class ProxySelectorViewController: UITableViewController {

// MARK: - Properties

weak var delegate: ProvisioningViewDelegate?
var meshNetwork: MeshNetwork?

private var centralManager: CBCentralManager!
Expand Down Expand Up @@ -189,9 +188,20 @@ extension ProxySelectorViewController: GattBearerDelegate {

func bearerDidOpen(_ bearer: Bearer) {
MeshNetworkManager.bearer.use(proxy: bearer as! GattBearer)
MeshNetworkManager.instance.proxyFilter.proxyDidDisconnect()

DispatchQueue.main.async { [weak self] in
self?.alert?.dismiss(animated: true) { [weak self] in
self?.dismiss(animated: true)
self?.dismiss(animated: true) {
// Set up the Proxy Filter when the view controller is no
// longer visible. This action may end up reaching the Proxy
// Filter list limit, which will result in showing an alert
// from the ProxyViewController. Having 2 child view controllers
// won't work.
if let provisioner = self?.meshNetwork?.localProvisioner {
MeshNetworkManager.instance.proxyFilter.setup(for: provisioner)
}
}
}
self?.alert = nil
}
Expand Down
27 changes: 24 additions & 3 deletions Example/Source/View Controllers/Proxy/ProxyViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,36 @@ extension ProxyViewController: ProxyFilterTypeDelegate {
extension ProxyViewController: ProxyFilterDelegate {

func proxyFilterUpdated(type: ProxyFilerType, addresses: Set<Address>) {
// As we want different behavior when the list was acknowledged
// or the list limit was reached, to nothing here.
}

func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
// This method is also called when the Proxy Node gets disconnected.
// In that case, the list size is equal to 0.
done {
self.tableView.reloadData()
}
}

func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
// TODO: dismiss here?
func proxyFilterLimitReached(type: ProxyFilerType, maxSize: UInt16) {
done {
self.tableView.reloadData()
let setRejectList = UIAlertAction(title: "Use Reject List", style: .destructive) { _ in
let proxyFilter = MeshNetworkManager.instance.proxyFilter
proxyFilter.setType(.rejectList)
}
self.presentAlert(
title: "Maximum filter size reached",
message: """
The connected proxy node supports only \(maxSize) addresses on its Proxy Filter list.
Use Reject List or add addresses manually.
""",
option: setRejectList
)
}
}

}

private extension ProxyViewController {
Expand Down
Loading

0 comments on commit 45e94cc

Please sign in to comment.