Skip to content

Commit

Permalink
Add BluetoothProvider to CentralServicesViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Piechocki committed Oct 29, 2020
1 parent f6eadbf commit 4648777
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
12 changes: 12 additions & 0 deletions ExampleApp/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
8DB15AAC253D938700DECF92 /* PeripheralViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DB15AAB253D938700DECF92 /* PeripheralViewController.swift */; };
8DB15AAF253D93A800DECF92 /* PeripheralView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DB15AAE253D93A800DECF92 /* PeripheralView.swift */; };
8DF924BB254ADE2C0027627D /* BluetoothProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF924BA254ADE2C0027627D /* BluetoothProvider.swift */; };
8DF924C3254AE4F40027627D /* Error+Printable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DF924C2254AE4F40027627D /* Error+Printable.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -52,6 +53,7 @@
8DB15AAB253D938700DECF92 /* PeripheralViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeripheralViewController.swift; sourceTree = "<group>"; };
8DB15AAE253D93A800DECF92 /* PeripheralView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeripheralView.swift; sourceTree = "<group>"; };
8DF924BA254ADE2C0027627D /* BluetoothProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothProvider.swift; sourceTree = "<group>"; };
8DF924C2254AE4F40027627D /* Error+Printable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Error+Printable.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -181,6 +183,7 @@
8DA476A425399CFA00B79A0A /* ExampleApp */ = {
isa = PBXGroup;
children = (
8DF924C1254AE4E80027627D /* Utilities */,
8DF924B9254ADE0B0027627D /* BluetoothProvider */,
8D72C5832539C34400456D1A /* Screens */,
8D72C5822539C33500456D1A /* Supporting Files */,
Expand All @@ -198,6 +201,14 @@
path = BluetoothProvider;
sourceTree = "<group>";
};
8DF924C1254AE4E80027627D /* Utilities */ = {
isa = PBXGroup;
children = (
8DF924C2254AE4F40027627D /* Error+Printable.swift */,
);
path = Utilities;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -273,6 +284,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8DF924C3254AE4F40027627D /* Error+Printable.swift in Sources */,
8D896D552542FFE000FD5FE5 /* CentralView.swift in Sources */,
8D4839A2254AAC0900266106 /* CharacteristicsViewController.swift in Sources */,
8D76F7352546C4DA00FF4DDB /* CentralServiceCell.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CentralListViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

tableView.register(CentralListCell.self, forCellReuseIdentifier: CentralListCell.reuseId)
setupBindings()
}
Expand Down Expand Up @@ -50,7 +51,7 @@ class CentralListViewController: UITableViewController {

peripheral.peripheral.establishConnection()
.subscribe(
onNext: { [weak self] in self?.presentServicesController(with: $0) },
onNext: { [weak self] in self?.pushServicesController(with: $0) },
onError: { [weak self] in AlertPresenter.presentError(with: $0.localizedDescription, on: self?.navigationController) }
)
.disposed(by: disposeBag)
Expand All @@ -65,7 +66,6 @@ class CentralListViewController: UITableViewController {
}

private let bluetoothProvider: BluetoothProvider

private let disposeBag = DisposeBag()

@objc private func startSearch() {
Expand All @@ -82,8 +82,8 @@ class CentralListViewController: UITableViewController {
.disposed(by: disposeBag)
}

private func presentServicesController(with peripheral: Peripheral) {
let controller = CentralSericesViewController(peripheral: peripheral)
private func pushServicesController(with peripheral: Peripheral) {
let controller = CentralSericesViewController(peripheral: peripheral, bluetoothProvider: bluetoothProvider)
navigationController?.pushViewController(controller, animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import UIKit

class CentralSericesViewController: UITableViewController {

init(peripheral: Peripheral) {
init(peripheral: Peripheral, bluetoothProvider: BluetoothProvider) {
self.peripheral = peripheral
self.bluetoothProvider = bluetoothProvider
super.init(nibName: nil, bundle: nil)

navigationItem.title = "Peripheral's services"
Expand Down Expand Up @@ -61,6 +62,7 @@ class CentralSericesViewController: UITableViewController {
// MARK: - Private

private let peripheral: Peripheral
private let bluetoothProvider: BluetoothProvider
private let didAppearSubject = PublishSubject<Void>()
private let disposeBag = DisposeBag()

Expand Down Expand Up @@ -89,15 +91,3 @@ class CentralSericesViewController: UITableViewController {
}

}

extension Error {

var printable: String {
if let bleError = self as? BluetoothError {
return bleError.description
}

return localizedDescription
}

}
13 changes: 13 additions & 0 deletions ExampleApp/ExampleApp/Utilities/Error+Printable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import RxBluetoothKit

extension Error {

var printable: String {
if let bleError = self as? BluetoothError {
return bleError.description
}

return localizedDescription
}

}

0 comments on commit 4648777

Please sign in to comment.