Skip to content

Commit

Permalink
Selection and copy handling much improved, will keep the correct row …
Browse files Browse the repository at this point in the history
…for the beacon selected when the table view updates. Also now will use the right beacon for the copy when the table view columns are reorder.
  • Loading branch information
mlwelles committed May 11, 2016
1 parent b2496fe commit d7afaae
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 34 deletions.
7 changes: 6 additions & 1 deletion BeaconScanner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = HG;
LastUpgradeCheck = 0630;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Huge, Inc.";
TargetAttributes = {
675315A818EF27D30024E9CE = {
Expand Down Expand Up @@ -424,6 +424,7 @@
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
Expand Down Expand Up @@ -486,6 +487,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BeaconScanner/BeaconScanner-Prefix.pch";
INFOPLIST_FILE = "$(SRCROOT)/BeaconScanner/BeaconScanner-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.hugeinc.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -500,6 +502,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BeaconScanner/BeaconScanner-Prefix.pch";
INFOPLIST_FILE = "$(SRCROOT)/BeaconScanner/BeaconScanner-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.hugeinc.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -522,6 +525,7 @@
"$(inherited)",
);
INFOPLIST_FILE = "BeaconScannerTests/BeaconScannerTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.hugeinc.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = BeaconScannerTests;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand All @@ -541,6 +545,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "BeaconScanner/BeaconScanner-Prefix.pch";
INFOPLIST_FILE = "BeaconScannerTests/BeaconScannerTests-Info.plist";
PRODUCT_BUNDLE_IDENTIFIER = "com.hugeinc.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = BeaconScannerTests;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0510"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -23,10 +23,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -48,17 +48,21 @@
ReferencedContainer = "container:BeaconScanner.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6753158718EF27D30024E9CE"
Expand All @@ -71,12 +75,13 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6753158718EF27D30024E9CE"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,37 @@
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BeaconScanner/HGBeaconViewController.m"
timestampString = "484684227.591794"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "31"
endingLineNumber = "31"
landmarkName = "-init"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "BeaconScanner/HGBeaconViewController.m"
timestampString = "484685629.281533"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "189"
endingLineNumber = "189"
landmarkName = "-tableView:didClickTableColumn:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
3 changes: 2 additions & 1 deletion BeaconScanner/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="nF1-6k-907" customClass="HGBeaconViewController">
<connections>
<outlet property="arrayController" destination="bR3-4d-4Vy" id="V29-zm-okx"/>
<outlet property="bluetoothStatusTextField" destination="04Y-oF-bK2" id="GxW-b2-0bO"/>
<outlet property="scanToggleButton" destination="evM-58-jet" id="LeF-zS-nI6"/>
<outlet property="scannerStatusTextField" destination="UKN-Ca-y34" id="ZOq-RF-CPi"/>
<outlet property="tableView" destination="AH2-px-RsF" id="q1q-H7-yxx"/>
<outlet property="view" destination="EiT-Mj-1SZ" id="gWO-eF-WTs"/>
</connections>
</customObject>
<arrayController objectClassName="BCBeacon" editable="NO" id="bR3-4d-4Vy" userLabel="Beacon Array Controller">
<arrayController objectClassName="BCBeacon" editable="NO" automaticallyRearrangesObjects="YES" id="bR3-4d-4Vy" userLabel="Beacon Array Controller">
<declaredKeys>
<string>major</string>
<string>proximityUUID</string>
Expand Down
2 changes: 1 addition & 1 deletion BeaconScanner/BeaconScanner-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.hugeinc.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
6 changes: 6 additions & 0 deletions BeaconScanner/HGBeacon.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ -(BOOL)isEqualTo:(id)object {
return [super isEqualTo:object];
}

-(NSString *)description
{
return [NSString stringWithFormat:@"<%@: %p, UUID: %@, major: %@, minor: %@>",
[self class], self, [self.proximityUUID UUIDString], self.major, self.minor];
}


#pragma mark - NSCopying
-(id)copyWithZone:(NSZone *)zone {
Expand Down
1 change: 0 additions & 1 deletion BeaconScanner/HGBeaconScanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
break;

}
NSLog(@"CBluetooth central manager reported new state: %@", state);
if (state != HGGBluetoothStatePoweredOn) {
if (self.scanning) {
[self stopScanning];
Expand Down
1 change: 1 addition & 0 deletions BeaconScanner/HGBeaconViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
@property(nonatomic,weak) IBOutlet NSTextField *scannerStatusTextField;
@property(nonatomic,weak) IBOutlet NSTextField *bluetoothStatusTextField;
@property(nonatomic, weak) IBOutlet NSTableView *tableView;
@property(nonatomic, weak) IBOutlet NSArrayController *arrayController;
@end
66 changes: 44 additions & 22 deletions BeaconScanner/HGBeaconViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ @interface HGBeaconViewController()
@end
@implementation HGBeaconViewController

- (id)init
{
- (void) awakeFromNib {
[self.tableView setAllowsEmptySelection:YES];
[self.tableView setAllowsColumnSelection:NO];
}

- (id)init {
self = [super init];
if (self) {
self.beacons = [NSMutableArray array];
Expand All @@ -32,9 +36,8 @@ - (id)init
// Subscribe to beacons detected by the manager, modify beacon list that is bound to the table view array
[[beaconSignal deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(HGBeacon *beacon) {
@strongify(self)
NSUInteger existingBeaconIndex = [self.beacons indexOfObjectPassingTest:^BOOL(HGBeacon *otherBeacon, NSUInteger idx, BOOL *stop) {
return [beacon isEqualToBeacon:otherBeacon];
}];
BOOL shouldReselect = (self.tableView.selectedRow >= 0);
NSUInteger existingBeaconIndex = [self rowForBeacon:beacon];
if (existingBeaconIndex != NSNotFound) {
HGBeacon *existingBeacon = [self.beacons objectAtIndex:existingBeaconIndex];
[self removeObjectFromBeaconsAtIndex:existingBeaconIndex];
Expand All @@ -45,20 +48,19 @@ - (id)init
} else {
[self addBeaconsObject:beacon];
}

//If we had a row selected, re-selected it
NSUInteger selectedRow = [self rowForBeacon:self.lastSelectedBeacon];
if ( selectedRow != NSNotFound ) {
NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:selectedRow];
[self.tableView selectRowIndexes:indexSet byExtendingSelection:false];
if (shouldReselect) {
[self selectRowForBeacon:self.lastSelectedBeacon];
}

}];

// Setup a interval signal that will purge expired beacons (determined by a last update longer than HGBeaconTimeToLiveInterval) from the displayed list
self.housekeepingSignal = [RACSignal interval:1 onScheduler:[RACScheduler mainThreadScheduler]];
[self.housekeepingSignal subscribeNext:^(NSDate *now) {
@strongify(self);
if ([[HGBeaconScanner sharedBeaconScanner] scanning]) {
BOOL shouldReselect = (self.tableView.selectedRow >= 0);
BOOL didChange = NO;
NSArray *beaconsCopy = [NSArray arrayWithArray:self.beacons];
for (HGBeacon *candidateBeacon in beaconsCopy) {
NSTimeInterval age = [now timeIntervalSinceDate:candidateBeacon.lastUpdated];
Expand All @@ -67,12 +69,16 @@ - (id)init
for (HGBeacon *beacon in self.beacons) {
if ([beacon isEqualToBeacon:candidateBeacon]) {
[self removeObjectFromBeaconsAtIndex:index];
didChange = YES;
break;
}
index++;
}
}
}
if (didChange && shouldReselect) {
[self selectRowForBeacon:self.lastSelectedBeacon];
}
if ([self.scannerStatusTextField.stringValue isEqualToString:@"Scanning..."]) {
self.scannerStatusTextField.stringValue = @"Scanning....";
} else {
Expand Down Expand Up @@ -139,22 +145,28 @@ - (id)init
return self;
}


-(NSInteger)rowForBeacon:(HGBeacon *)beacon {
for (int row = 0; row < self.beacons.count; row++) {
HGBeacon *rowBeacon = self.beacons[0];
if ([beacon isEqualToBeacon:rowBeacon]) {
return row;
-(void)selectRowForBeacon:(HGBeacon *)beaconToSelect{
//If we had a row selected, re-select it
dispatch_async(dispatch_get_main_queue(), ^{
NSUInteger selectedRow = [self rowForBeacon:beaconToSelect];
if ( selectedRow != NSNotFound ) {
NSIndexSet *indexSet = [[NSIndexSet alloc] initWithIndex:selectedRow];
[self.tableView selectRowIndexes:indexSet byExtendingSelection:false];
}
}
return NSNotFound;
});

}
-(NSInteger)rowForBeacon:(HGBeacon *)beacon {
return [self.arrayController.arrangedObjects indexOfObjectPassingTest:^BOOL(HGBeacon *otherBeacon, NSUInteger idx, BOOL *stop) {
return [beacon isEqualToBeacon:otherBeacon];
}];

}
-(HGBeacon *)beaconForRow:(NSInteger) row {
HGBeacon *beacon = nil;
if ( row >= 0 &&
row < self.tableView.numberOfRows &&
row < self.beacons.count ) {
beacon = self.beacons[row];
row < [self.arrayController.arrangedObjects count]) {
beacon = (HGBeacon *)self.arrayController.arrangedObjects[row];
}
return beacon;
}
Expand All @@ -169,6 +181,16 @@ - (void)tableViewSelectionDidChange:(NSNotification *)notification {
}


- (void)tableView:(NSTableView *)tableView
didClickTableColumn:(NSTableColumn *)tableColumn {
if (self.tableView.selectedRow == -1) {
self.lastSelectedBeacon = nil;
} else {
[self selectRowForBeacon:self.lastSelectedBeacon];
}
}


#pragma mark - NSWindowController delegate
- (IBAction) copy:(id)sender
{
Expand Down
2 changes: 1 addition & 1 deletion BeaconScannerTests/BeaconScannerTests-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.hugeinc.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
Expand Down

0 comments on commit d7afaae

Please sign in to comment.