-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1 added Alert notification control point view controller
- Loading branch information
Showing
7 changed files
with
181 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
BluetoothExplorer/AlertNotificationControlPointCharacteristic.storyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
<device id="retina4_7" orientation="portrait"> | ||
<adaptation id="fullscreen"/> | ||
</device> | ||
<dependencies> | ||
<deployment identifier="iOS"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Alert Notification Control Point--> | ||
<scene sceneID="ckE-l7-ti3"> | ||
<objects> | ||
<tableViewController storyboardIdentifier="AlertNotificationControlPointCharacteristicViewController" title="Alert Notification Control Point" id="5Ij-Vs-xep" userLabel="Alert Notification Control Point" customClass="AlertNotificationControlPointCharacteristicViewController" customModule="BluetoothExplorer" customModuleProvider="target" sceneMemberID="viewController"> | ||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="A2r-Qd-mP7"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> | ||
<connections> | ||
<outlet property="dataSource" destination="5Ij-Vs-xep" id="YNI-WP-YSC"/> | ||
<outlet property="delegate" destination="5Ij-Vs-xep" id="CCM-nt-4da"/> | ||
</connections> | ||
</tableView> | ||
</tableViewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="D7o-68-1EX" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="182" y="78"/> | ||
</scene> | ||
</scenes> | ||
</document> |
126 changes: 126 additions & 0 deletions
126
...TT Characteristic Editors/AlertNotificationControlPointCharacteristicViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// | ||
// AlertNotificationControlPointCharacteristicViewController.swift | ||
// BluetoothExplorer | ||
// | ||
// Created by Carlos Duclos on 7/3/18. | ||
// Copyright © 2018 PureSwift. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import Bluetooth | ||
|
||
final class AlertNotificationControlPointCharacteristicViewController: UITableViewController, CharacteristicViewController, InstantiableViewController { | ||
|
||
typealias Command = GATTAlertNotificationControlPoint.Command | ||
|
||
// MARK: - Properties | ||
|
||
private let cellIdentifier = R.nib.inputTextViewCell.name | ||
|
||
private var fields = [Field]() | ||
|
||
var value = GATTAlertNotificationControlPoint(command: .enableNewIncomingAlertNotification, category: .simpleAlert) | ||
|
||
var valueDidChange: ((GATTAlertNotificationControlPoint) -> ())? | ||
|
||
// MARK: - Loading | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
fields = [.command("\(value.command.rawValue)"), | ||
.alertCategory("\(value.category.rawValue)")] | ||
|
||
tableView.register(R.nib.inputTextViewCell(), forCellReuseIdentifier: cellIdentifier) | ||
tableView.separatorStyle = .none | ||
} | ||
|
||
// MARK: - UITableViewController | ||
|
||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return fields.count | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
|
||
let field = fields[indexPath.row] | ||
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! InputTextViewCell | ||
cell.selectionStyle = .none | ||
|
||
configure(cell, field: field) | ||
|
||
return cell | ||
} | ||
|
||
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
|
||
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! InputTextViewCell | ||
cell.inputTextView.textField.becomeFirstResponder() | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
func configure(_ cell: InputTextViewCell, field: Field) { | ||
|
||
cell.inputTextView.value = field.bluetoothValue | ||
cell.inputTextView.posibleInputValues = field.posibleValues | ||
cell.inputTextView.isEnabled = valueDidChange != nil | ||
cell.inputTextView.fieldLabelText = field.title | ||
cell.inputTextView.placeholder = field.title | ||
} | ||
} | ||
|
||
extension AlertNotificationControlPointCharacteristicViewController { | ||
|
||
enum Field { | ||
|
||
case command(String) | ||
case alertCategory(String) | ||
|
||
var title: String { | ||
|
||
switch self { | ||
case .command: | ||
return "Command" | ||
|
||
case .alertCategory: | ||
return "Alert Category" | ||
} | ||
} | ||
|
||
var bluetoothValue: String { | ||
switch self { | ||
case .command(let value): | ||
return value | ||
|
||
case .alertCategory(let value): | ||
return value | ||
} | ||
} | ||
|
||
var posibleValues: [String] { | ||
switch self { | ||
case .command: | ||
return [Command.enableNewIncomingAlertNotification.rawValue.description, | ||
Command.enableUnreadCategoryStatusNotification.rawValue.description, | ||
Command.disableNewIncomingAlertNotification.rawValue.description, | ||
Command.disableUnreadCategoryStatusNotification.rawValue.description, | ||
Command.notifyNewIncomingAlertImmediately.rawValue.description, | ||
Command.notifyUnreadCategoryStatusImmediately.rawValue.description] | ||
|
||
case .alertCategory: | ||
return [GATTAlertCategory.simpleAlert.rawValue.description, | ||
GATTAlertCategory.email.rawValue.description, | ||
GATTAlertCategory.news.rawValue.description, | ||
GATTAlertCategory.call.rawValue.description, | ||
GATTAlertCategory.missedCall.rawValue.description, | ||
GATTAlertCategory.sms.rawValue.description, | ||
GATTAlertCategory.voiceMail.rawValue.description, | ||
GATTAlertCategory.schedule.rawValue.description, | ||
GATTAlertCategory.highPrioritizedAlert.rawValue.description, | ||
GATTAlertCategory.instantMessage.rawValue.description] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
// | ||
|
||
import Foundation | ||
|
||
import UIKit | ||
import Bluetooth | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters