Skip to content

Commit 45e94cc

Browse files
authored
Merge pull request #585 from NordicSemiconductor/bugfix/proxy
[App] Fixed behavior on Proxy screen
2 parents 2447816 + 0dbbbef commit 45e94cc

4 files changed

Lines changed: 175 additions & 98 deletions

File tree

Example/Source/View Controllers/Proxy/AddAddressViewController.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,33 @@ private extension AddAddressViewController {
195195
extension AddAddressViewController: ProxyFilterDelegate {
196196

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

203202
func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
204-
// TODO: dismiss here?
203+
// This method is also called when the Proxy Node gets disconnected.
204+
// In that case, the list size is equal to 0.
205+
if listSize > 0 {
206+
done {
207+
self.dismiss(animated: true)
208+
}
209+
}
210+
}
211+
212+
func proxyFilterLimitReached(type: ProxyFilerType, maxSize: UInt16) {
213+
done {
214+
self.presentAlert(
215+
title: "Maximum filter size reached",
216+
message: """
217+
The connected proxy node supports only \(maxSize) addresses on its Proxy Filter list.
218+
219+
Some addresses were not added.
220+
"""
221+
) { _ in
222+
self.dismiss(animated: true)
223+
}
224+
}
205225
}
206226

207227
}

Example/Source/View Controllers/Proxy/ProxySelectorViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class ProxySelectorViewController: UITableViewController {
4545

4646
// MARK: - Properties
4747

48-
weak var delegate: ProvisioningViewDelegate?
4948
var meshNetwork: MeshNetwork?
5049

5150
private var centralManager: CBCentralManager!
@@ -189,9 +188,20 @@ extension ProxySelectorViewController: GattBearerDelegate {
189188

190189
func bearerDidOpen(_ bearer: Bearer) {
191190
MeshNetworkManager.bearer.use(proxy: bearer as! GattBearer)
191+
MeshNetworkManager.instance.proxyFilter.proxyDidDisconnect()
192+
192193
DispatchQueue.main.async { [weak self] in
193194
self?.alert?.dismiss(animated: true) { [weak self] in
194-
self?.dismiss(animated: true)
195+
self?.dismiss(animated: true) {
196+
// Set up the Proxy Filter when the view controller is no
197+
// longer visible. This action may end up reaching the Proxy
198+
// Filter list limit, which will result in showing an alert
199+
// from the ProxyViewController. Having 2 child view controllers
200+
// won't work.
201+
if let provisioner = self?.meshNetwork?.localProvisioner {
202+
MeshNetworkManager.instance.proxyFilter.setup(for: provisioner)
203+
}
204+
}
195205
}
196206
self?.alert = nil
197207
}

Example/Source/View Controllers/Proxy/ProxyViewController.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,36 @@ extension ProxyViewController: ProxyFilterTypeDelegate {
222222
extension ProxyViewController: ProxyFilterDelegate {
223223

224224
func proxyFilterUpdated(type: ProxyFilerType, addresses: Set<Address>) {
225+
// As we want different behavior when the list was acknowledged
226+
// or the list limit was reached, to nothing here.
227+
}
228+
229+
func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
230+
// This method is also called when the Proxy Node gets disconnected.
231+
// In that case, the list size is equal to 0.
225232
done {
226233
self.tableView.reloadData()
227234
}
228235
}
229236

230-
func proxyFilterUpdateAcknowledged(type: ProxyFilerType, listSize: UInt16) {
231-
// TODO: dismiss here?
237+
func proxyFilterLimitReached(type: ProxyFilerType, maxSize: UInt16) {
238+
done {
239+
self.tableView.reloadData()
240+
let setRejectList = UIAlertAction(title: "Use Reject List", style: .destructive) { _ in
241+
let proxyFilter = MeshNetworkManager.instance.proxyFilter
242+
proxyFilter.setType(.rejectList)
243+
}
244+
self.presentAlert(
245+
title: "Maximum filter size reached",
246+
message: """
247+
The connected proxy node supports only \(maxSize) addresses on its Proxy Filter list.
248+
249+
Use Reject List or add addresses manually.
250+
""",
251+
option: setRejectList
252+
)
253+
}
232254
}
233-
234255
}
235256

236257
private extension ProxyViewController {

0 commit comments

Comments
 (0)