Skip to content
Permalink
Browse files

WatchKit main interface

  • Loading branch information...
josecastillo committed Aug 9, 2015
1 parent 7e4bc9a commit dc980d493fadfcf35951023bdf4c586c3470a0cf
@@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
E7123E2C1B77ED580070AC66 /* UIColor+TFAlertColors.m in Sources */ = {isa = PBXBuildFile; fileRef = E7E544E61B769B8A006E3021 /* UIColor+TFAlertColors.m */; };
E721DD601B77C76900AC04C1 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E721DD5E1B77C76900AC04C1 /* Interface.storyboard */; };
E721DD621B77C76900AC04C1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E721DD611B77C76900AC04C1 /* Assets.xcassets */; };
E721DD691B77C76900AC04C1 /* TrainFaceWatchKitApp Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = E721DD681B77C76900AC04C1 /* TrainFaceWatchKitApp Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
@@ -84,7 +85,6 @@
E721DD741B77C76900AC04C1 /* ComplicationController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ComplicationController.m; sourceTree = "<group>"; };
E721DD761B77C76900AC04C1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
E721DD781B77C76900AC04C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E73298901B77B3E0006E04A9 /* TrainFace.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = TrainFace.entitlements; sourceTree = "<group>"; };
E78F48A91B77C8A60023C8DB /* TFWTrainRow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TFWTrainRow.h; sourceTree = "<group>"; };
E78F48AA1B77C8A60023C8DB /* TFWTrainRow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TFWTrainRow.m; sourceTree = "<group>"; };
E7E544AF1B766740006E3021 /* TrainFace.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TrainFace.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -176,7 +176,6 @@
E7E544B11B766740006E3021 /* TrainFace */ = {
isa = PBXGroup;
children = (
E73298901B77B3E0006E04A9 /* TrainFace.entitlements */,
E7E544CC1B7667EE006E3021 /* Classes */,
E7E544BE1B766740006E3021 /* Main.storyboard */,
E7E544C11B766740006E3021 /* Assets.xcassets */,
@@ -315,16 +314,27 @@
E721DD5B1B77C76900AC04C1 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 5459V76WQG;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 0;
};
};
};
E721DD671B77C76900AC04C1 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 5459V76WQG;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 0;
};
};
};
E7E544AE1B766740006E3021 = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 5459V76WQG;
SystemCapabilities = {
com.apple.ApplicationGroups.iOS = {
enabled = 1;
enabled = 0;
};
};
};
@@ -385,6 +395,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E7123E2C1B77ED580070AC66 /* UIColor+TFAlertColors.m in Sources */,
E721DD751B77C76900AC04C1 /* ComplicationController.m in Sources */,
E721DD721B77C76900AC04C1 /* ExtensionDelegate.m in Sources */,
E721DD6F1B77C76900AC04C1 /* InterfaceController.m in Sources */,
@@ -597,23 +608,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = TrainFace/TrainFace.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TrainFace/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.panchromatic.transitapp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Debug;
};
E7E544CB1B766740006E3021 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = TrainFace/TrainFace.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = TrainFace/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = net.panchromatic.transitapp;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
};
name = Release;
};
@@ -7,8 +7,9 @@
//

#import <UIKit/UIKit.h>
#import <WatchConnectivity/WatchConnectivity.h>

@interface TFAppDelegate : UIResponder <UIApplicationDelegate>
@interface TFAppDelegate : UIResponder <UIApplicationDelegate, WCSessionDelegate>

@property (strong, nonatomic) UIWindow *window;

@@ -9,6 +9,7 @@
#import "TFAppDelegate.h"
#import "TFDetailViewController.h"
#import "UIImage+TFSubwayLine.h"
#import "TFLiveDataSource.h"

#import "Constants.h"

@@ -19,24 +20,16 @@ @interface TFAppDelegate ()
@implementation TFAppDelegate

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions {
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.net.panchromatic.trainface"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:kUserDefaultsKeyLines]) {
NSArray *lines = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"A", @"C", @"E", @"B", @"D", @"F", @"M", @"G", @"J", @"Z", @"L", @"N", @"Q", @"R"];
[defaults setObject:lines forKey:kUserDefaultsKeyLines];
[defaults synchronize];
}

// If we don't have line images generated for the Apple Watch, generate them now.
NSURL *containerUrl = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group.net.panchromatic.trainface"];
NSURL *testUrl = [[containerUrl URLByAppendingPathComponent:@"R"] URLByAppendingPathExtension:@"png"];
if (![[NSFileManager defaultManager] fileExistsAtPath:[testUrl path]]) {
for (NSString *lineName in [defaults objectForKey:kUserDefaultsKeyLines]) {
UIImage *lineImage = [UIImage imageForSubwayLine:lineName withSize:32];
NSData *pngData = UIImagePNGRepresentation(lineImage);
NSURL *outputUrl = [[containerUrl URLByAppendingPathComponent:lineName] URLByAppendingPathExtension:@"png"];
[pngData writeToURL:outputUrl atomically:NO];
}
}

WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];

return YES;
}
@@ -68,4 +61,27 @@ - (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

#pragma mark - WCSession Delegate

- (void)session:(WCSession *)session didReceiveMessage:(NSDictionary<NSString *, id> *)message replyHandler:(void(^)(NSDictionary<NSString *, id> *replyMessage))replyHandler {
NSString *command = message[@"command"];
if ([command isEqualToString:@"RequestLineImages"]) {
NSMutableDictionary *response = [NSMutableDictionary dictionary];
NSArray *lines = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"A", @"C", @"E", @"B", @"D", @"F", @"M", @"G", @"J", @"Z", @"L", @"N", @"Q", @"R"];
for (NSString *lineName in lines) {
UIImage *lineImage = [UIImage imageForSubwayLine:lineName withSize:32];
NSData *pngData = UIImagePNGRepresentation(lineImage);
NSString *filename = [NSString stringWithFormat:@"%@.png", lineName];
response[filename] = pngData;
}
replyHandler(@{@"images" : response});
} else if ([command isEqualToString:@"RequestServiceStatus"]) {
[[TFLiveDataSource defaultSource] refresh:^(NSError *error) {
// TODO: Error Handling. For now, pass along whatever we get back even if it's stale data.
replyHandler(@{@"status" : [[TFLiveDataSource defaultSource] status], @"lines" : [[NSUserDefaults standardUserDefaults] objectForKey:kUserDefaultsKeyLines]});
}];
}
}


@end
@@ -45,7 +45,7 @@ - (void)viewDidLoad {

- (void)viewWillAppear:(BOOL)animated {
self.clearsSelectionOnViewWillAppear = YES;
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.net.panchromatic.trainface"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
self.lines = [[defaults arrayForKey:kUserDefaultsKeyLines] mutableCopy];
[super viewWillAppear:animated];
}
@@ -104,7 +104,7 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sou
[self.lines removeObjectAtIndex:sourceIndexPath.row];
[self.lines insertObject:line atIndex:destinationIndexPath.row];

NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.net.panchromatic.trainface"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:self.lines forKey:kUserDefaultsKeyLines];
[defaults synchronize];
}
@@ -10,6 +10,7 @@
#define Constants_h

#define kUserDefaultsKeyLines (@"lines")
#define kUserDefaultsKeyServiceStatus (@"service_status")

#define kLiveDataSourceKeyTimestamp (@"timestamp")
#define kLiveDataSourceKeyLines (@"lines")

This file was deleted.

@@ -7,7 +7,8 @@
//

#import <WatchKit/WatchKit.h>
#import <WatchConnectivity/WatchConnectivity.h>

@interface ExtensionDelegate : NSObject <WKExtensionDelegate>

@interface ExtensionDelegate : NSObject <WKExtensionDelegate, WCSessionDelegate>
@property (nonatomic, strong) WCSession *session;
@end
@@ -8,14 +8,43 @@

#import "ExtensionDelegate.h"

#import "Constants.h"

@implementation ExtensionDelegate

- (void)applicationDidFinishLaunching {
// Perform any final initialization of your application.
WCSession *session = [WCSession defaultSession];
session.delegate = self;
[session activateSession];
self.session = session;

// If we don't have line images, fetch them from the host app now.
NSURL *containerUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] firstObject];
NSURL *testUrl = [[containerUrl URLByAppendingPathComponent:@"R"] URLByAppendingPathExtension:@"png"];
if (![[NSFileManager defaultManager] fileExistsAtPath:[testUrl path]]) {
[session sendMessage:@{@"command" : @"RequestLineImages"}
replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
NSDictionary *files = replyMessage[@"images"];
for (NSString *filename in files) {
NSData *imageData = files[filename];
NSURL *outputUrl = [containerUrl URLByAppendingPathComponent:filename];
[imageData writeToURL:outputUrl atomically:NO];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"TFWDataUpdate" object:self];
} errorHandler:nil];
}
}

- (void)applicationDidBecomeActive {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[self.session sendMessage:@{@"command" : @"RequestServiceStatus"}
replyHandler:^(NSDictionary<NSString *,id> * _Nonnull replyMessage) {
NSDictionary *lines = replyMessage[@"lines"];
NSDictionary *serviceStatus = replyMessage[@"status"];
[[NSUserDefaults standardUserDefaults] setObject:lines forKey:kUserDefaultsKeyLines];
[[NSUserDefaults standardUserDefaults] setObject:serviceStatus forKey:kUserDefaultsKeyServiceStatus];
[[NSNotificationCenter defaultCenter] postNotificationName:@"TFWDataUpdate" object:self];
}
errorHandler:nil];
}

- (void)applicationWillResignActive {
@@ -8,6 +8,8 @@

#import "InterfaceController.h"
#import "TFWTrainRow.h"
#import "UIColor+TFAlertColors.h"

#import "Constants.h"

@interface InterfaceController()
@@ -17,25 +19,43 @@ @interface InterfaceController()

@implementation InterfaceController

- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];

NSArray *lines = @[@"F", @"M", @"L"];
- (void)refreshTable:(NSNotification *)notification {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *lines = [defaults arrayForKey:kUserDefaultsKeyLines];
NSURL *containerUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] firstObject];

[self.tableView setNumberOfRows:lines.count withRowType:kCellIdentifierDefault];
NSDictionary *systemStatus = [[NSUserDefaults standardUserDefaults] dictionaryForKey:kUserDefaultsKeyServiceStatus];
if (systemStatus) {
[self.tableView setNumberOfRows:lines.count withRowType:kCellIdentifierDefault];
} else {
[self.tableView setNumberOfRows:0 withRowType:kCellIdentifierDefault];
}

for (int i = 0 ; i < self.tableView.numberOfRows ; i++) {
NSString *line = lines[i];
NSDictionary *lineStatus = systemStatus[kLiveDataSourceKeyLines][line];
TFWTrainRow *row = [self.tableView rowControllerAtIndex:i];
row.textLabel.text = [NSString stringWithFormat:@"%@: SUSPENDED", lines[i]];
row.textLabel.text = lineStatus[kLiveDataSourceKeyStatus];
row.textLabel.textColor = [UIColor colorForAlertLevel:[lineStatus[kLiveDataSourceKeyAlertLevel] integerValue]];
NSURL *imageUrl = [[containerUrl URLByAppendingPathComponent:line] URLByAppendingPathExtension:@"png"];
[row.imageView setImageData:[NSData dataWithContentsOfURL:imageUrl]];
}
}

- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
}

- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[self refreshTable:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshTable:) name:@"TFWDataUpdate" object:nil];
[super willActivate];
}

- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"TFWDataUpdate" object:nil];
[super didDeactivate];
}

@@ -11,5 +11,6 @@

@interface TFWTrainRow : NSObject
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceLabel *textLabel;
@property (unsafe_unretained, nonatomic) IBOutlet WKInterfaceImage *imageView;

@end
@@ -15,10 +15,14 @@
<tableRow identifier="Cell" id="48G-Eb-S5k" customClass="TFWTrainRow">
<group key="rootItem" width="1" alignment="left" id="6Dp-FH-hha">
<items>
<label height="1" alignment="left" text="Label" id="dFA-vt-Kp2"/>
<imageView width="32" height="32" alignment="left" verticalAlignment="center" id="Awh-zb-CeA"/>
<label height="1" alignment="left" text="GOOD SERVICE" numberOfLines="2" id="dFA-vt-Kp2">
<fontDescription key="font" style="UICTFontTextStyleCaption2"/>
</label>
</items>
</group>
<connections>
<outlet property="imageView" destination="Awh-zb-CeA" id="L4g-4D-hl5"/>
<outlet property="textLabel" destination="dFA-vt-Kp2" id="xaf-Yu-ivl"/>
</connections>
</tableRow>

0 comments on commit dc980d4

Please sign in to comment.
You can’t perform that action at this time.