Skip to content

Commit

Permalink
Fix issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnyyoung committed Oct 5, 2016
1 parent 7347879 commit eebc369
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions AppleReserver/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>1.1</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>4</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
1 change: 0 additions & 1 deletion AppleReserver/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@
</tableColumn>
</tableColumns>
<connections>
<action selector="storeTableViewAction:" target="XfG-lQ-9wD" id="N6u-gw-rMW"/>
<outlet property="dataSource" destination="XfG-lQ-9wD" id="tFY-lR-h9g"/>
<outlet property="delegate" destination="XfG-lQ-9wD" id="gvt-0i-gUe"/>
</connections>
Expand Down
34 changes: 25 additions & 9 deletions AppleReserver/Module/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ @interface HomeViewController () <NSTableViewDataSource, NSTableViewDelegate>
// TableViews
@property (weak) IBOutlet NSTableView *storeTableView;
@property (weak) IBOutlet NSTableView *availabilityTableView;

// Buttons
@property (weak) IBOutlet NSButton *onlyAvailabilityButton;
@property (weak) IBOutlet NSButton *notificationButton;
Expand All @@ -30,6 +31,7 @@ @interface HomeViewController () <NSTableViewDataSource, NSTableViewDelegate>

@property (nonatomic, strong) Store *selectedStore;
@property (nonatomic, strong) NSTimer *pollingTimer;
@property (nonatomic, copy) NSURL *reserveURL;

@end

Expand Down Expand Up @@ -117,19 +119,33 @@ - (void)checkAndMakeNotification {
}
}

#pragma mark - Event Response
#pragma mark - Notification Handler

- (IBAction)storeTableViewAction:(NSTableView *)sender {
self.selectedStore = self.storeArray[sender.selectedRow];
[self.selectedModelArray removeAllObjects];
[self reloadAvailability];
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
if ([notification.object isKindOfClass:[NSTableView class]]) {
NSTableView *tableVeiw = notification.object;
if (tableVeiw.selectedRow < 0) {
return;
}
if (notification.object == self.storeTableView) {
self.selectedStore = self.storeArray[tableVeiw.selectedRow];
[self.selectedModelArray removeAllObjects];
[self.availabilityTableView deselectAll:nil];
[self reloadAvailability];
} else if (notification.object == self.availabilityTableView) {
NSString *store = self.selectedStore.storeNumber;
NSString *model = self.availabilityDictionary.allKeys[tableVeiw.selectedRow];
self.reserveURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://reserve.cdn-apple.com/CN/zh_CN/reserve/iPhone/availability?channel=1&returnURL=&store=%@&partNumber=%@", store, model]];
}
}
}

#pragma mark - Event Response

- (IBAction)reverseAction:(NSTableView *)sender {
NSString *store = self.selectedStore.storeNumber;
NSString *model = self.availabilityDictionary.allKeys[sender.selectedRow];
NSURL *reverseURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://reserve.cdn-apple.com/CN/zh_CN/reserve/iPhone/availability?channel=1&returnURL=&store=%@&partNumber=%@", store, model]];
[[NSWorkspace sharedWorkspace] openURL:reverseURL];
if (sender.clickedRow > 0) {
[[NSWorkspace sharedWorkspace] openURL:self.reserveURL];
}
}

- (IBAction)onlyAvailabilityButtonAction:(NSButton *)sender {
Expand Down

0 comments on commit eebc369

Please sign in to comment.