Skip to content

Commit

Permalink
Make ALValueCell a public API
Browse files Browse the repository at this point in the history
  • Loading branch information
rpetrich committed Mar 5, 2011
1 parent 802d3e5 commit 2dabe3b
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 105 deletions.
105 changes: 1 addition & 104 deletions ALApplicationPreferenceViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "ALApplicationTableDataSource.h"

#import "ALApplicationList.h"
#import "ALValueCell.h"

#import <Preferences/Preferences.h>

Expand Down Expand Up @@ -30,44 +31,6 @@ - (id)valueForCellAtIndexPath:(NSIndexPath *)indexPath;

@end

/// ALValueCell

@protocol ALValueCellDelegate;

__attribute__((visibility("hidden")))
@interface ALValueCell : UITableViewCell {
@private
id<ALValueCellDelegate> _delegate;
}

@property (nonatomic, assign) id<ALValueCellDelegate> delegate;

- (void)loadValue:(id)value;

- (void)didSelect;

@end

__attribute__((visibility("hidden")))
@protocol ALValueCellDelegate <NSObject>
@required
- (void)valueCell:(ALValueCell *)valueCell didChangeToValue:(id)newValue;
@end

@implementation ALValueCell

@synthesize delegate;

- (void)loadValue:(id)value
{
}

- (void)didSelect
{
}

@end

__attribute__((visibility("hidden")))
@interface ALPreferencesTableDataSource : ALApplicationTableDataSource<ALValueCellDelegate> {
@private
Expand Down Expand Up @@ -111,72 +74,6 @@ @interface PSViewController (OS32)
- (void)setSpecifier:(PSSpecifier *)specifier;
@end

__attribute__((visibility("hidden")))
@interface ALSwitchCell : ALValueCell {
@private
UISwitch *switchView;
}

@property (nonatomic, readonly) UISwitch *switchView;

@end

@implementation ALSwitchCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchView addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];
[self setAccessoryView:switchView];
}
return self;
}

- (void)dealloc
{
[switchView release];
[super dealloc];
}

@synthesize switchView = _switchView;

- (void)loadValue:(id)value
{
switchView.on = [value boolValue];
}

- (void)valueChanged
{
id value = [NSNumber numberWithBool:switchView.on];
[[self delegate] valueCell:self didChangeToValue:value];
}

@end

__attribute__((visibility("hidden")))
@interface ALCheckCell : ALValueCell {
}

@end

@implementation ALCheckCell

- (void)loadValue:(id)value
{
[self setAccessoryType:[value boolValue] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
}

- (void)didSelect
{
UITableViewCellAccessoryType type = [self accessoryType];
[self setAccessoryType:(type == UITableViewCellAccessoryNone) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
id value = [NSNumber numberWithBool:type == UITableViewCellAccessoryNone];
[[self delegate] valueCell:self didChangeToValue:value];
}

@end

@implementation ALApplicationPreferenceViewController

- (id)initForContentSize:(CGSize)size
Expand Down
36 changes: 36 additions & 0 deletions ALValueCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#import <UIKit/UIKit.h>

@protocol ALValueCellDelegate;

@interface ALValueCell : UITableViewCell {
@private
id<ALValueCellDelegate> _delegate;
}

@property (nonatomic, assign) id<ALValueCellDelegate> delegate;

- (void)loadValue:(id)value;

- (void)didSelect;

@end

@protocol ALValueCellDelegate <NSObject>
@required
- (void)valueCell:(ALValueCell *)valueCell didChangeToValue:(id)newValue;
@end

@interface ALSwitchCell : ALValueCell {
@private
UISwitch *switchView;
}

@property (nonatomic, readonly) UISwitch *switchView;

@end

@interface ALCheckCell : ALValueCell {
}

@end

65 changes: 65 additions & 0 deletions ALValueCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#import "ALValueCell.h"

@implementation ALValueCell

@synthesize delegate;

- (void)loadValue:(id)value
{
}

- (void)didSelect
{
}

@end

@implementation ALSwitchCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
switchView = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchView addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];
[self setAccessoryView:switchView];
}
return self;
}

- (void)dealloc
{
[switchView release];
[super dealloc];
}

@synthesize switchView = _switchView;

- (void)loadValue:(id)value
{
switchView.on = [value boolValue];
}

- (void)valueChanged
{
id value = [NSNumber numberWithBool:switchView.on];
[[self delegate] valueCell:self didChangeToValue:value];
}

@end

@implementation ALCheckCell

- (void)loadValue:(id)value
{
[self setAccessoryType:[value boolValue] ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
}

- (void)didSelect
{
UITableViewCellAccessoryType type = [self accessoryType];
[self setAccessoryType:(type == UITableViewCellAccessoryNone) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone];
id value = [NSNumber numberWithBool:type == UITableViewCellAccessoryNone];
[[self delegate] valueCell:self didChangeToValue:value];
}

@end
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ all clean package install::
else

LIBRARY_NAME = libapplist
libapplist_OBJC_FILES = ALApplicationList.m ALApplicationTableDataSource.m
libapplist_OBJC_FILES = ALApplicationList.m ALApplicationTableDataSource.m ALValueCell.m
libapplist_FRAMEWORKS = UIKit CoreGraphics QuartzCore
libapplist_PRIVATE_FRAMEWORKS = AppSupport ImageIO

Expand Down

0 comments on commit 2dabe3b

Please sign in to comment.