Skip to content

Instantly share code, notes, and snippets.

@rodericj
Created November 26, 2014 18:27
Show Gist options
  • Save rodericj/c6ea8f56ca9d3c8d840e to your computer and use it in GitHub Desktop.
Save rodericj/c6ea8f56ca9d3c8d840e to your computer and use it in GitHub Desktop.
[[RACSignal combineLatest:@[[device.batteryLife deliverOn:[RACScheduler mainThreadScheduler]], [device.onlineState deliverOn:[RACScheduler mainThreadScheduler]]] reduce:^(NSNumber *level, NSNumber *stateEnum)
{
MorseDeviceConnectedState state = (MorseDeviceConnectedState) [stateEnum integerValue];
switch (state)
{
case MorseDeviceConnectedStateConnected:
{
NSString *string;
if ([level floatValue] > 0)
string = [NSString stringWithFormat:@"%0.f%%", [level floatValue] * 100];
else
{
string = @"...";
}
return [RACTuple tupleWithObjectsFromArray:@[string, [UIColor whiteColor]]];
}
case MorseDeviceConnectedStateNotConnected:
{
return [RACTuple tupleWithObjectsFromArray:@[NSLocalizedString(@"disconnected", nil), [AVHexColor colorWithHex:0xF26322]]];
}
case MorseDeviceConnectedStateConnecting:
{
return [RACTuple tupleWithObjectsFromArray:@[NSLocalizedString(@"connecting", nil), [UIColor whiteColor]]];
}
case MorseDeviceConnectedStateFubar:
{
return [RACTuple tupleWithObjectsFromArray:@[@"Oh crap. Please show this to Adrian.", [AVHexColor colorWithHex:0xF26322]]];
}
default:
{
return [RACTuple tupleWithObjectsFromArray:@[@"", [UIColor whiteColor]]];
}
}
}]
subscribeNext:^(RACTuple *stringAndColor)
{
self.accessoryStatusLabel.text = [stringAndColor first];
self.accessoryStatusLabel.textColor = [stringAndColor second];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment