Skip to content

Instantly share code, notes, and snippets.

@rodericj
Created November 26, 2014 17:52
Show Gist options
  • Save rodericj/c66b8a4217f4fe1c7368 to your computer and use it in GitHub Desktop.
Save rodericj/c66b8a4217f4fe1c7368 to your computer and use it in GitHub Desktop.
[[RACSignal combineLatest:@[device.batteryLife, device.onlineState] reduce:^(NSNumber *level, NSNumber *stateEnum)
{
MorseDeviceConnectedState state = (MorseDeviceConnectedState) [stateEnum integerValue];
NSMutableDictionary *ret = [[NSMutableDictionary alloc] initWithCapacity:2];
switch (state)
{
case MorseDeviceConnectedStateConnected:
{
if ([level floatValue] > 0)
ret[@"string"] = [NSString stringWithFormat:@"%0.f%%", [level floatValue] * 100];
else
{
ret[@"string"] = @"...";
}
ret[@"color"] = [UIColor whiteColor];
break;
}
case MorseDeviceConnectedStateNotConnected:
{
ret[@"string"] = NSLocalizedString(@"disconnected", nil);
ret[@"color"] = [AVHexColor colorWithHex:0xF26322];
break;
}
case MorseDeviceConnectedStateConnecting:
{
ret[@"string"] = NSLocalizedString(@"connecting", nil);
ret[@"color"] = [UIColor whiteColor];
break;
}
case MorseDeviceConnectedStateFubar:
{
ret[@"string"] = @"Oh crap. Please show this to Adrian.";
ret[@"color"] = [AVHexColor colorWithHex:0xF26322];
break;
}
default:
{
ret[@"string"] = @"";
break;
}
}
return ret;
}]
subscribeNext:^(NSDictionary * stuff)
{
dispatch_async(dispatch_get_main_queue(), ^
{
self.accessoryStatusLabel.text = stuff[@"string"];
self.accessoryStatusLabel.textColor = stuff[@"color"];
});
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment