Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Variable to BehaviorRelay. #23

Merged
merged 1 commit into from
Sep 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions BeaconDetection/Detection/DetectionViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class DetectionViewModel: NSObject {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
return cell
})

private let rangingButtonIconVar: Variable<UIImage> = Variable(#imageLiteral(resourceName: "RangingButtonIconStart"))
private let rangingButtonIconVar: BehaviorRelay<UIImage> = BehaviorRelay(value: #imageLiteral(resourceName: "RangingButtonIconStart"))

private let statusVar = BehaviorRelay(value: "")
private let inputProximityUUIDVar = BehaviorRelay(value: "")
Expand Down Expand Up @@ -86,7 +86,7 @@ class DetectionViewModel: NSObject {
}

func updateProximityUUID(uuidText: String) {

inputProximityUUIDVar.accept(uuidText)

guard UUID(uuidString: uuidText) != nil else { return }
Expand Down Expand Up @@ -128,16 +128,16 @@ class DetectionViewModel: NSObject {
}

guard let beaconRegion = beaconRegion,
authorizationStatusCheck() else { return }
rangingButtonIconVar.value = #imageLiteral(resourceName: "RangingButtonIconPause")
authorizationStatusCheck() else { return }
rangingButtonIconVar.accept(#imageLiteral(resourceName: "RangingButtonIconPause"))
isRanging = true
guard let manager = manager else { return }
manager.startRangingBeacons(in: beaconRegion)
}

private func stopRanging() {
guard let beaconRegion = beaconRegion else { return }
rangingButtonIconVar.value = #imageLiteral(resourceName: "RangingButtonIconStart")
rangingButtonIconVar.accept(#imageLiteral(resourceName: "RangingButtonIconStart"))
isRanging = false
guard let manager = manager else { return }
manager.stopRangingBeacons(in: beaconRegion)
Expand All @@ -147,7 +147,7 @@ class DetectionViewModel: NSObject {

dataSource.configureCell = { [unowned self] _, tv, _, item in
let cell = tv.dequeueReusableCell(withIdentifier: "DetectionInfoTableViewCell") as? DetectionInfoTableViewCell
?? DetectionInfoTableViewCell(style: .default, reuseIdentifier: "DetectionInfoTableViewCell")
?? DetectionInfoTableViewCell(style: .default, reuseIdentifier: "DetectionInfoTableViewCell")

cell.uuidLabel.text = item.beacon.proximityUUID.uuidString
cell.majorLabel.text = item.beacon.major.stringValue
Expand All @@ -170,11 +170,11 @@ class DetectionViewModel: NSObject {
manager = CLLocationManager()
beaconRegion = toUseBeaconRegion()
guard let manager = manager,
authorizationStatusCheck(),
let beaconRegion = beaconRegion else { return }
authorizationStatusCheck(),
let beaconRegion = beaconRegion else { return }
manager.delegate = self
manager.startMonitoring(for: beaconRegion)
rangingButtonIconVar.value = #imageLiteral(resourceName: "RangingButtonIconPause")
rangingButtonIconVar.accept(#imageLiteral(resourceName: "RangingButtonIconPause"))
}

private func toUseBeaconRegion() -> CLBeaconRegion! {
Expand Down Expand Up @@ -224,13 +224,13 @@ class DetectionViewModel: NSObject {
fatalError("not supported status")
}
}

func isMonitoringCapable() -> Bool {
return CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self)
}

private func convertProximityStatusToText(proximity: CLProximity) -> String {

switch proximity {
case .unknown:
return "Unknown"
Expand Down