Skip to content
Browse files

Add basic state changes for wifi networks.

  • Loading branch information...
1 parent d6bce94 commit f9ec5395836aac94c6669076b95b3ee8aacde6c1 @jverkoey committed Jun 6, 2012
View
6 Settings.xcodeproj/project.pbxproj
@@ -147,6 +147,7 @@
6677CFB11580440900FAB17D /* YouTube.png in Resources */ = {isa = PBXBuildFile; fileRef = 6677CF481580440900FAB17D /* YouTube.png */; };
6677CFB21580440900FAB17D /* YouTube@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6677CF491580440900FAB17D /* YouTube@2x.png */; };
6677CFB51580492C00FAB17D /* WifiViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6677CFB41580492C00FAB17D /* WifiViewController.m */; };
+ 6677CFB815804B9F00FAB17D /* GlobalState.m in Sources */ = {isa = PBXBuildFile; fileRef = 6677CFB715804B9F00FAB17D /* GlobalState.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -332,6 +333,8 @@
6677CF491580440900FAB17D /* YouTube@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "YouTube@2x.png"; path = "resources/YouTube@2x.png"; sourceTree = "<group>"; };
6677CFB31580492C00FAB17D /* WifiViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WifiViewController.h; sourceTree = "<group>"; };
6677CFB41580492C00FAB17D /* WifiViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WifiViewController.m; sourceTree = "<group>"; };
+ 6677CFB615804B9E00FAB17D /* GlobalState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GlobalState.h; sourceTree = "<group>"; };
+ 6677CFB715804B9F00FAB17D /* GlobalState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GlobalState.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -485,6 +488,8 @@
6677CEDE158043A800FAB17D /* RootController.m */,
6677CFB31580492C00FAB17D /* WifiViewController.h */,
6677CFB41580492C00FAB17D /* WifiViewController.m */,
+ 6677CFB615804B9E00FAB17D /* GlobalState.h */,
+ 6677CFB715804B9F00FAB17D /* GlobalState.m */,
);
name = Controllers;
sourceTree = "<group>";
@@ -800,6 +805,7 @@
6677CEDB1580432200FAB17D /* NITableViewModel.m in Sources */,
6677CEDF158043A800FAB17D /* RootController.m in Sources */,
6677CFB51580492C00FAB17D /* WifiViewController.m in Sources */,
+ 6677CFB815804B9F00FAB17D /* GlobalState.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
14 Settings/GlobalState.h
@@ -0,0 +1,14 @@
+//
+// GlobalState.h
+// Settings
+//
+// Created by Jeffrey Verkoeyen on 12-06-06.
+// Copyright (c) 2012 Memento. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface GlobalState : NSObject
++ (GlobalState *)sharedInstance;
+@property (nonatomic, readwrite, assign) BOOL wifi;
+@end
View
25 Settings/GlobalState.m
@@ -0,0 +1,25 @@
+//
+// GlobalState.m
+// Settings
+//
+// Created by Jeffrey Verkoeyen on 12-06-06.
+// Copyright (c) 2012 Memento. All rights reserved.
+//
+
+#import "GlobalState.h"
+
+@implementation GlobalState
+
+@synthesize wifi;
+
++ (GlobalState *)sharedInstance {
+ static GlobalState *sSingleton;
+ @synchronized(self) {
+ if (nil == sSingleton) {
+ sSingleton = [[self alloc] init];
+ }
+ return sSingleton;
+ }
+}
+
+@end
View
19 Settings/RootController.m
@@ -59,6 +59,25 @@ - (id)initWithStyle:(UITableViewStyle)style {
locationServices.cellStyle = UITableViewCellStyleValue1;
[contents addObject:locationServices];
+ // Group divider
+ [contents addObject:@""];
+
+ NITitleCellObject* sounds = [NITitleCellObject objectWithTitle:@"Sounds"
+ image:[UIImage imageNamed:@"Settings-Sound"]];
+ [contents addObject:sounds];
+ NITitleCellObject* brightness = [NITitleCellObject objectWithTitle:@"Brightness"
+ image:[UIImage imageNamed:@"Settings-Display"]];
+ [contents addObject:brightness];
+ NITitleCellObject* wallpaper = [NITitleCellObject objectWithTitle:@"Wallpaper"];
+ [contents addObject:wallpaper];
+
+ // Group divider
+ [contents addObject:@""];
+
+ NITitleCellObject* general = [NITitleCellObject objectWithTitle:@"General"
+ image:[UIImage imageNamed:@"Settings"]];
+ [contents addObject:general];
+
self.actions = [[NITableViewActions alloc] initWithController:self];
[self.actions attachNavigationAction:NIPushControllerAction([WifiViewController class])
toObject:wifi];
View
1 Settings/Settings-Prefix.pch
@@ -13,4 +13,5 @@
#import <Foundation/Foundation.h>
#import "NimbusCore.h"
#import "NimbusModels.h"
+#import "GlobalState.h"
#endif
View
80 Settings/WifiViewController.m
@@ -8,11 +8,21 @@
#import "WifiViewController.h"
+typedef enum {
+ WifiToggleSwitch,
+ AskToJoinSwitch,
+} FormIds;
+
@interface WifiViewController ()
+@property (nonatomic, readwrite, retain) NITableViewModel* model;
+@property (nonatomic, readwrite, retain) NITableViewActions* actions;
@end
@implementation WifiViewController
+@synthesize model;
+@synthesize actions;
+
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
@@ -21,4 +31,74 @@ - (id)initWithStyle:(UITableViewStyle)style {
return self;
}
+- (void)refreshModel {
+ NSMutableArray* contents =
+ [NSMutableArray arrayWithObjects:
+ [NISwitchFormElement switchElementWithID:WifiToggleSwitch
+ labelText:@"Wi-Fi"
+ value:[GlobalState sharedInstance].wifi
+ didChangeTarget:self
+ didChangeSelector:@selector(didChangeWifi:)],
+ nil];
+
+ if (![GlobalState sharedInstance].wifi) {
+ [contents addObjectsFromArray:
+ [NSArray arrayWithObjects:
+ [NITableViewModelFooter footerWithTitle:@"Location accuracy is improved when Wi-Fi is enabled."],
+ nil]];
+ self.tableView.delegate = self;
+
+ } else {
+ [contents addObjectsFromArray:
+ [NSArray arrayWithObjects:
+ @"Choose a Network...",
+ nil]];
+ id wifi = [NITitleCellObject objectWithTitle:@"Wi-Fi 1"];
+ [contents addObject:wifi];
+ [contents addObjectsFromArray:[NSArray arrayWithObjects:
+ @"",
+ [NISwitchFormElement switchElementWithID:AskToJoinSwitch
+ labelText:@"Ask to Join Networks"
+ value:NO
+ didChangeTarget:self
+ didChangeSelector:@selector(didChangeAsk:)],
+ nil]];
+ self.actions = [[NITableViewActions alloc] initWithController:self];
+ [self.actions attachTapAction:^BOOL(id object, UIViewController *controller) {
+ NSLog(@"Did tap wifi network...connect!");
+ return YES; // Returning yes indicates that we want to deselect the cell immediately.
+ } toObject:wifi];
+ [self.actions attachDetailAction:^BOOL(id object, UIViewController *controller) {
+ NSLog(@"Did tap detail button of wifi network. Show details!");
+ return NO;
+ } toObject:wifi];
+ self.tableView.delegate = [self.actions forwardingTo:self];
+ }
+
+ self.model = [[NITableViewModel alloc] initWithSectionedArray:contents delegate:(id)[NICellFactory class]];
+ self.tableView.dataSource = self.model;
+}
+
+- (void)loadView {
+ [super loadView];
+
+ [self refreshModel];
+}
+
+- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
+ return NIIsSupportedOrientation(toInterfaceOrientation);
+}
+
+- (void)didChangeWifi:(UISwitch *)control {
+ [GlobalState sharedInstance].wifi = control.on;
+
+ [self refreshModel];
+ // We'll figure out animations later.
+ [self.tableView reloadData];
+}
+
+- (void)didChangeAsk:(UISwitch *)control {
+
+}
+
@end

0 comments on commit f9ec539

Please sign in to comment.
Something went wrong with that request. Please try again.