Skip to content

Commit

Permalink
Add basic state changes for wifi networks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Jun 7, 2012
1 parent d6bce94 commit f9ec539
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Settings.xcodeproj/project.pbxproj
Expand Up @@ -147,6 +147,7 @@
6677CFB11580440900FAB17D /* YouTube.png in Resources */ = {isa = PBXBuildFile; fileRef = 6677CF481580440900FAB17D /* YouTube.png */; }; 6677CFB11580440900FAB17D /* YouTube.png in Resources */ = {isa = PBXBuildFile; fileRef = 6677CF481580440900FAB17D /* YouTube.png */; };
6677CFB21580440900FAB17D /* YouTube@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 6677CF491580440900FAB17D /* YouTube@2x.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 */; }; 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 */ /* End PBXBuildFile section */


/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
Expand Down Expand Up @@ -332,6 +333,8 @@
6677CF491580440900FAB17D /* YouTube@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "YouTube@2x.png"; path = "resources/YouTube@2x.png"; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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 */ /* End PBXFileReference section */


/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -485,6 +488,8 @@
6677CEDE158043A800FAB17D /* RootController.m */, 6677CEDE158043A800FAB17D /* RootController.m */,
6677CFB31580492C00FAB17D /* WifiViewController.h */, 6677CFB31580492C00FAB17D /* WifiViewController.h */,
6677CFB41580492C00FAB17D /* WifiViewController.m */, 6677CFB41580492C00FAB17D /* WifiViewController.m */,
6677CFB615804B9E00FAB17D /* GlobalState.h */,
6677CFB715804B9F00FAB17D /* GlobalState.m */,
); );
name = Controllers; name = Controllers;
sourceTree = "<group>"; sourceTree = "<group>";
Expand Down Expand Up @@ -800,6 +805,7 @@
6677CEDB1580432200FAB17D /* NITableViewModel.m in Sources */, 6677CEDB1580432200FAB17D /* NITableViewModel.m in Sources */,
6677CEDF158043A800FAB17D /* RootController.m in Sources */, 6677CEDF158043A800FAB17D /* RootController.m in Sources */,
6677CFB51580492C00FAB17D /* WifiViewController.m in Sources */, 6677CFB51580492C00FAB17D /* WifiViewController.m in Sources */,
6677CFB815804B9F00FAB17D /* GlobalState.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
Expand Down
14 changes: 14 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions Settings/RootController.m
Expand Up @@ -59,6 +59,25 @@ - (id)initWithStyle:(UITableViewStyle)style {
locationServices.cellStyle = UITableViewCellStyleValue1; locationServices.cellStyle = UITableViewCellStyleValue1;
[contents addObject:locationServices]; [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 = [[NITableViewActions alloc] initWithController:self];
[self.actions attachNavigationAction:NIPushControllerAction([WifiViewController class]) [self.actions attachNavigationAction:NIPushControllerAction([WifiViewController class])
toObject:wifi]; toObject:wifi];
Expand Down
1 change: 1 addition & 0 deletions Settings/Settings-Prefix.pch
Expand Up @@ -13,4 +13,5 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "NimbusCore.h" #import "NimbusCore.h"
#import "NimbusModels.h" #import "NimbusModels.h"
#import "GlobalState.h"
#endif #endif
80 changes: 80 additions & 0 deletions Settings/WifiViewController.m
Expand Up @@ -8,11 +8,21 @@


#import "WifiViewController.h" #import "WifiViewController.h"


typedef enum {
WifiToggleSwitch,
AskToJoinSwitch,
} FormIds;

@interface WifiViewController () @interface WifiViewController ()
@property (nonatomic, readwrite, retain) NITableViewModel* model;
@property (nonatomic, readwrite, retain) NITableViewActions* actions;
@end @end


@implementation WifiViewController @implementation WifiViewController


@synthesize model;
@synthesize actions;

- (id)initWithStyle:(UITableViewStyle)style { - (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:UITableViewStyleGrouped]; self = [super initWithStyle:UITableViewStyleGrouped];
if (self) { if (self) {
Expand All @@ -21,4 +31,74 @@ - (id)initWithStyle:(UITableViewStyle)style {
return self; 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 @end

0 comments on commit f9ec539

Please sign in to comment.