Added handling segmentedControl
MODIFY
BT-Tracking/Interface/Data List/DataListVC.swift
BT-Tracking/Interface/Data List/DataListVC.swift
@@ -36,6 +36,7 @@ final class DataListVC: UIViewController, UITableViewDelegate {
}
setupTableView()
+ viewModel.selectedSegmentIndex.accept(0)
}
// MARK: - TableView
@@ -72,7 +73,7 @@ final class DataListVC: UIViewController, UITableViewDelegate {
// MARK: - Actions
@IBAction private func segmentedControlValueChanged(_ sender: UISegmentedControl) {
- viewModel.onSegmentedControl.onNext(sender.selectedSegmentIndex)
+ viewModel.selectedSegmentIndex.accept(sender.selectedSegmentIndex)
}
@IBAction private func sendReportAction() {

MODIFY
BT-Tracking/Interface/Data List/DataListVM.swift
BT-Tracking/Interface/Data List/DataListVM.swift
@@ -15,8 +15,7 @@ import RealmSwift
class DataListVM {
// MARK: - Properties
-
- let onSegmentedControl = PublishSubject<Int>()
+ let selectedSegmentIndex = PublishRelay<Int>()
private let scans: Observable<[Scan]>
private let scanObjects: Results<ScanRealm>
@@ -31,18 +30,19 @@ class DataListVM {
.map { scanned in
return scanned.map { $0.toScan() }
}
-
- onSegmentedControl
- .subscribe(onNext: { [weak self] index in
- // TODO: Change data in tableView
- print("onSegmentedControl selected index: \(index)")
- }).disposed(by: bag)
}
// MARK: - Sections
var sections: Driver<[SectionModel]> {
- return scans
+ return Observable.combineLatest(scans, selectedSegmentIndex)
+ .map { unfilteredScans, selectedSegmentIndex -> [Scan] in
+ return unfilteredScans.filter { scan in
+ guard let medianRssi = scan.medianRssi else { return false }
+ let medianRssiPoint = AppSettings.medianRssiPoint
+ return selectedSegmentIndex == 0 ? (medianRssi < medianRssiPoint) : (medianRssi > medianRssiPoint)
+ }
+ }
.map { unsortedScans in
return unsortedScans.sorted(by: { scan0, scan1 in scan0.date > scan1.date })
}

MODIFY
BT-Tracking/Services/AppSettings.swift
BT-Tracking/Services/AppSettings.swift
@@ -11,6 +11,7 @@ import Foundation
struct AppSettings {
static let firebaseRegion = "europe-west1"
+ static let medianRssiPoint = 30
static var BUID: String? {
get {

Added handling segmentedControl