Skip to content

Commit

Permalink
Merge branch 'master' of git@github.com:Empact/kuler-iphone
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseclark committed Aug 3, 2008
2 parents a6fb883 + 1e20db4 commit 32da1ac
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 0 deletions.
16 changes: 16 additions & 0 deletions native/Classes/RootViewController.h
@@ -0,0 +1,16 @@
//
// RootViewController.h
// kuler-iphone
//
// Created by Benjamin Ortuzar on 02/08/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface RootViewController : UITableViewController {

}

@end
138 changes: 138 additions & 0 deletions native/Classes/RootViewController.m
@@ -0,0 +1,138 @@
//
// RootViewController.m
// kuler-iphone
//
// Created by Benjamin Ortuzar on 02/08/2008.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "RootViewController.h"
#import "kuler_iphoneAppDelegate.h"
#import "TableViewCell.h"


@implementation RootViewController

- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {

NSLog(@"initializing RootViewController");
self.title = @"Themes";
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.rowHeight = 48.0;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
self.tableView.sectionHeaderHeight = 0;
}
return self;
}





- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
kuler_iphoneAppDelegate *appDelegate = (kuler_iphoneAppDelegate *)[[UIApplication sharedApplication] delegate];
NSUInteger count = [appDelegate countOfList];
// If no themes were parsed because the RSS feed was not available,
// return a count of 1 so that the data source method tableView:cellForRowAtIndexPath: is called.
// It also calls -[kuler_iphoneAppDelegate isDataSourceAvailable] to determine what to show in the table.
if ([appDelegate isDataSourceAvailable] == NO) {
return 1;
}
return count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifier";

TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[TableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}

// Set up the cell.
kuler_iphoneAppDelegate *appDelegate = (kuler_iphoneAppDelegate *)[[UIApplication sharedApplication] delegate];

// If the RSS feed isn't accessible (which could happen if the network isn't available), show an informative
// message in the first row of the table.
if ([appDelegate isDataSourceAvailable] == NO) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"DefaultTableViewCell"] autorelease];
cell.text = NSLocalizedString(@"RSS Host Not Available", @"RSS Host Not Available message");
cell.textColor = [UIColor colorWithWhite:0.5 alpha:0.5];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}

Theme *themeForRow = [appDelegate objectInListAtIndex:indexPath.row];
[cell setTheme:themeForRow];
return cell;
}

/*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
*/
/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
}
if (editingStyle == UITableViewCellEditingStyleInsert) {
}
}
*/
/*
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/


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


- (void)viewDidLoad {
[super viewDidLoad];
}


- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated {
}

- (void)viewDidDisappear:(BOOL)animated {
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}


@end

20 changes: 20 additions & 0 deletions native/Classes/TableViewCell.h
@@ -0,0 +1,20 @@

#import <UIKit/UIKit.h>
#import "Theme.h"

@interface TableViewCell : UITableViewCell {

@private
Theme *_theme;
UILabel *_themeNameLabel;
UIImageView *_themeImageView;
}

@property (nonatomic, retain) UILabel *themeNameLabel;
@property (nonatomic, retain) UIImageView *themeImageView;


- (Theme *)theme;
- (void)setTheme:(Theme *)newTheme;

@end
150 changes: 150 additions & 0 deletions native/Classes/TableViewCell.m
@@ -0,0 +1,150 @@
#import "TableViewCell.h"


static UIImage *themeImage = nil;

@interface TableViewCell()
- (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold;
@end

@implementation TableViewCell

@synthesize themeNameLabel = _themeNameLabel;
@synthesize themeImageView = _themeImageView;

+ (void)initialize
{
//deleted
themeImage = [[UIImage imageNamed:@"theme_sample.png"] retain];
}

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
UIView *myContentView = self.contentView;

// Add an image view to display a waveform image of the earthquake.
self.themeImageView = [[UIImageView alloc] initWithImage:themeImage];
[myContentView addSubview:self.themeImageView];
[self.themeImageView release];

// A label that displays the name of the theme.
self.themeNameLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] selectedColor:[UIColor whiteColor] fontSize:14.0 bold:YES];
self.themeNameLabel.textAlignment = UITextAlignmentLeft; // default
[myContentView addSubview:self.themeNameLabel];
[self.themeNameLabel release];


// Position the magnitudeImageView above all of the other views so
// it's not obscured. It's a transparent image, so any views
// that overlap it will still be visible.
[myContentView bringSubviewToFront:self.themeImageView];
}
return self;
}

- (Theme *)theme
{
return _theme;
}

// Rather than using one of the standard UITableViewCell content properties like 'text',
// we're using a custom property called 'theme' to populate the table cell. Whenever the
// value of that property changes, we need to call [self setNeedsDisplay] to force the
// cell to be redrawn.
- (void)setTheme:(Theme *)newTheme
{
[newTheme retain];
[_theme release];
_theme = newTheme;

//self.themeNameLabel.text = newTheme.title;
self.themeNameLabel.text = @"Theme Title";
self.themeImageView.image = themeImage;

[self setNeedsDisplay];
}



- (void)layoutSubviews {

#define LEFT_COLUMN_OFFSET 10
#define LEFT_COLUMN_WIDTH 200

#define MIDDLE_COLUMN_OFFSET 180
#define MIDDLE_COLUMN_WIDTH 100

#define UPPER_ROW_TOP 4
#define LOWER_ROW_TOP 28

[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;

// In this example we will never be editing, but this illustrates the appropriate pattern
if (!self.editing) {

CGFloat boundsX = contentRect.origin.x;
CGRect frame;

// Place the title label.
frame = CGRectMake(boundsX + LEFT_COLUMN_OFFSET, UPPER_ROW_TOP, LEFT_COLUMN_WIDTH, 20);
self.themeNameLabel.frame = frame;

// Place the waveform image.
UIImageView *imageView = self.themeImageView;
frame = [imageView frame];
frame.origin.x = boundsX + MIDDLE_COLUMN_OFFSET;
frame.origin.y = UPPER_ROW_TOP;
imageView.frame = frame;


}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
/*
Views are drawn most efficiently when they are opaque and do not have a clear background, so in newLabelForMainText: the labels are made opaque and given a white background. To show selection properly, however, the views need to be transparent (so that the selection color shows through).
*/
[super setSelected:selected animated:animated];

UIColor *backgroundColor = nil;
if (selected) {
backgroundColor = [UIColor clearColor];
} else {
backgroundColor = [UIColor whiteColor];
}

self.themeNameLabel.backgroundColor = backgroundColor;
self.themeNameLabel.highlighted = selected;
self.themeNameLabel.opaque = !selected;

}

- (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor selectedColor:(UIColor *)selectedColor fontSize:(CGFloat)fontSize bold:(BOOL)bold
{
/*
Create and configure a label.
*/

UIFont *font;
if (bold) {
font = [UIFont boldSystemFontOfSize:fontSize];
} else {
font = [UIFont systemFontOfSize:fontSize];
}

/*
Views are drawn most efficiently when they are opaque and do not have a clear background, so set these defaults. To show selection properly, however, the views need to be transparent (so that the selection color shows through). This is handled in setSelected:animated:.
*/
UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectZero];
newLabel.backgroundColor = [UIColor whiteColor];
newLabel.opaque = YES;
newLabel.textColor = primaryColor;
newLabel.highlightedTextColor = selectedColor;
newLabel.font = font;

return newLabel;
}

@end
7 changes: 7 additions & 0 deletions native/Classes/Theme.m
Expand Up @@ -22,5 +22,12 @@ @implementation Theme
@synthesize edited = _edited;


-(NSString *)description{
NSString *result;
result = [[NSString alloc] initWithFormat:@"title: %@", _title];

return result;
}


@end
2 changes: 2 additions & 0 deletions native/Classes/ThemeFeedReader.m
Expand Up @@ -95,6 +95,7 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
// If the number of parsed themes is greater than MAX_ELEMENTS, abort the parse.
// Otherwise the application runs very slowly on the device.
if (parsedItemsCounter >= MAX_THEMES) {
NSLog("max themes reached.");
[parser abortParsing];
}

Expand Down Expand Up @@ -133,6 +134,7 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName names

if ([elementName isEqualToString:@"kuler:themeTitle"]) {
self.currentObject.title = self.contentOfCurrentProperty;
NSLog(@"we found the title element");

} else if ([elementName isEqualToString:@"kuler:themeID"]) {
self.currentObject.themeID = self.contentOfCurrentProperty;
Expand Down
11 changes: 11 additions & 0 deletions native/Classes/kuler_iphoneAppDelegate.h
Expand Up @@ -10,10 +10,21 @@

@interface kuler_iphoneAppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
UINavigationController *navigationController;

NSMutableArray *list;
BOOL _isDataSourceAvailable;
}

@property (nonatomic, retain) NSMutableArray *list;
@property (nonatomic, retain) UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;


- (BOOL)isDataSourceAvailable;
- (NSUInteger)countOfList;
- (id)objectInListAtIndex:(NSUInteger)theIndex;
- (void)getList:(id *)objsPtr range:(NSRange)range;

@end

0 comments on commit 32da1ac

Please sign in to comment.