Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dkasper/Humanity-iPhone
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammon Bartram committed Nov 6, 2011
2 parents 701ccdb + 8fe4829 commit f9216f8
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/*
*.ipa
*.xcuserstate
*.xcbkptlist
.DS_Store
4 changes: 4 additions & 0 deletions Humanity/Humanity.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
F7B78FB21465F4F000B7A3E4 /* members.png in Resources */ = {isa = PBXBuildFile; fileRef = F7B78FAA1465F4F000B7A3E4 /* members.png */; };
F7B78FB31465F4F000B7A3E4 /* messages.png in Resources */ = {isa = PBXBuildFile; fileRef = F7B78FAB1465F4F000B7A3E4 /* messages.png */; };
F7B78FB41465F4F000B7A3E4 /* settings.png in Resources */ = {isa = PBXBuildFile; fileRef = F7B78FAC1465F4F000B7A3E4 /* settings.png */; };
F7B78FC61466102A00B7A3E4 /* GroupConstants.h in Sources */ = {isa = PBXBuildFile; fileRef = F7B78FC51466102900B7A3E4 /* GroupConstants.h */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -214,6 +215,7 @@
F7B78FAA1465F4F000B7A3E4 /* members.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = members.png; sourceTree = "<group>"; };
F7B78FAB1465F4F000B7A3E4 /* messages.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = messages.png; sourceTree = "<group>"; };
F7B78FAC1465F4F000B7A3E4 /* settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = settings.png; sourceTree = "<group>"; };
F7B78FC51466102900B7A3E4 /* GroupConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GroupConstants.h; path = "Group Screen/GroupConstants.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -499,6 +501,7 @@
F7B78F981465E23C00B7A3E4 /* MessageTableCell.m */,
F7B78F9E1465E58600B7A3E4 /* MessageTableCellContentView.h */,
F7B78F9F1465E58600B7A3E4 /* MessageTableCellContentView.m */,
F7B78FC51466102900B7A3E4 /* GroupConstants.h */,
);
name = "Group Screen";
sourceTree = "<group>";
Expand Down Expand Up @@ -666,6 +669,7 @@
F7B78F961465DAEC00B7A3E4 /* MessageTextView.m in Sources */,
F7B78F991465E23C00B7A3E4 /* MessageTableCell.m in Sources */,
F7B78FA01465E58700B7A3E4 /* MessageTableCellContentView.m in Sources */,
F7B78FC61466102A00B7A3E4 /* GroupConstants.h in Sources */,
66A1058F1466200800E5FC75 /* HMButton.m in Sources */,
66A105981466297C00E5FC75 /* KeychainItemWrapper.m in Sources */,
);
Expand Down
19 changes: 6 additions & 13 deletions Humanity/Humanity/Group List Screen/GroupListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return [temp count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}

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

static NSString *CellIdentifier = @"GroupListMessageCell";
Expand All @@ -89,13 +93,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}

[cell setMessageCellGroup:@"Some Pod" message:@"Hello"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
GroupViewController *vc = [[GroupViewController alloc] init];
vc.groupName = @"Test Name";
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
Expand Down Expand Up @@ -124,17 +130,6 @@ - (void)setTableHeaderView
[listHeaderView release];
}

-(void)setFooterView
{
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 370, 320, 50)];

footerView.backgroundColor = [UIColor redColor];

[self.view addSubview:footerView];
[footerView release];
}


#pragma mark - View lifecycle

/*
Expand All @@ -157,8 +152,6 @@ - (void)viewDidLoad
[self setTableHeaderView];

[self.view addSubview:groupListTableView];

[self setFooterView];
}


Expand Down
16 changes: 16 additions & 0 deletions Humanity/Humanity/Group Screen/GroupConstants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GroupConstants.cpp
// Humanity
//
// Created by David Kasper on 11/5/11.
// Copyright (c) 2011 Humanity. All rights reserved.
//

#define CONTRACTED_TEXT_HEIGHT 30
#define EXPANDED_TEXT_HEIGHT 50
#define EXPANDED_HEIGHT 100
#define CONTRACTED_HEIGHT 50
#define PICTURE_SIZE 40
#define BUTTON_WIDTH 60
#define BUTTON_HEIGHT 25
#define MESSAGE_TEXT_WIDTH 250
3 changes: 3 additions & 0 deletions Humanity/Humanity/Group Screen/GroupViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

@interface GroupViewController : UITabBarController

@property (nonatomic, retain) NSString *groupName;
@property (nonatomic, retain) NSString *groupId;

@property (nonatomic, retain) MessageListViewController *messageListViewController;
@property (nonatomic, retain) MemberListViewController *memberListViewController;
@property (nonatomic, retain) MapViewController *mapViewController;
Expand Down
7 changes: 7 additions & 0 deletions Humanity/Humanity/Group Screen/GroupViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@implementation GroupViewController

@synthesize groupName = _groupName;
@synthesize groupId = _groupId;
@synthesize messageListViewController = _messageListViewController;
@synthesize memberListViewController = _memberListViewController;
@synthesize mapViewController = _mapViewController;
Expand All @@ -26,4 +28,9 @@ -(id) init {
return self;
}

-(void)setGroupName:(NSString *)name {
_groupName = [name retain];
self.title = _groupName;
}

@end
24 changes: 13 additions & 11 deletions Humanity/Humanity/Group Screen/MessageListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#import "MessageListViewController.h"
#import "MessageTableCell.h"

#define MESSAGE_VIEW_HEIGHT 70
#import "GroupConstants.h"

@implementation MessageListViewController

Expand All @@ -26,7 +25,7 @@ -(id)init {
self.title = @"Messages";
self.tabBarItem.image = [UIImage imageNamed:@"messages.png"];
self.messages = [[NSMutableArray alloc] init];
[self.messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"David Kasper", @"name", @"Hello World Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World", @"body", nil]];
[self.messages addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"David Kasper", @"name", @"Hello World Hello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello WorldHello World", @"content", nil]];
}
return self;
}
Expand All @@ -47,12 +46,13 @@ - (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.messageTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, MESSAGE_VIEW_HEIGHT, view.bounds.size.width, view.bounds.size.height - MESSAGE_VIEW_HEIGHT) style:UITableViewStylePlain];
self.messageTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CONTRACTED_HEIGHT, view.bounds.size.width, view.bounds.size.height - CONTRACTED_HEIGHT) style:UITableViewStylePlain];
self.messageTableView.delegate = self;
self.messageTableView.dataSource = self;
[view addSubview:self.messageTableView];

self.messageTextView = [[MessageTextView alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, MESSAGE_VIEW_HEIGHT)];
self.messageTextView = [[MessageTextView alloc] initWithFrame:CGRectMake(0, 0, view.bounds.size.width, CONTRACTED_HEIGHT)];
self.messageTextView.delegate = self;
[view addSubview:self.messageTextView];

self.toggleTextViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
Expand Down Expand Up @@ -93,7 +93,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[[self.messages objectAtIndex:indexPath.row] objectForKey:@"body"] sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake(280, 9999) lineBreakMode:UILineBreakModeWordWrap].height + 30;
return [[[self.messages objectAtIndex:indexPath.row] objectForKey:@"content"] sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake(MESSAGE_TEXT_WIDTH, 9999) lineBreakMode:UILineBreakModeWordWrap].height + (EXPANDED_HEIGHT - CONTRACTED_HEIGHT);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Expand All @@ -103,7 +103,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.name = [[self.messages objectAtIndex:indexPath.row] objectForKey:@"name"];
cell.body = [[self.messages objectAtIndex:indexPath.row] objectForKey:@"body"];
cell.content = [[self.messages objectAtIndex:indexPath.row] objectForKey:@"content"];

return cell;
}
Expand All @@ -112,20 +112,22 @@ -(void)toggleTextView:(id)sender {
if(self.messageTextView.enabled) {
[self.messageTextView contract];
CGRect newFrame = self.toggleTextViewButton.frame;
newFrame.origin.y = newFrame.origin.y - MESSAGE_VIEW_HEIGHT;
newFrame.origin.y = newFrame.origin.y - EXPANDED_HEIGHT;
newFrame.size.height = CONTRACTED_HEIGHT;
self.toggleTextViewButton.frame = newFrame;

newFrame = self.messageTableView.frame;
newFrame.origin.y -= 30;
newFrame.origin.y -= (EXPANDED_HEIGHT - CONTRACTED_HEIGHT);
self.messageTableView.frame = newFrame;
} else {
[self.messageTextView expand];
CGRect newFrame = self.toggleTextViewButton.frame;
newFrame.origin.y = newFrame.origin.y + MESSAGE_VIEW_HEIGHT;
newFrame.origin.y = newFrame.origin.y + EXPANDED_HEIGHT;
newFrame.size.height = 100;
self.toggleTextViewButton.frame = newFrame;

newFrame = self.messageTableView.frame;
newFrame.origin.y += 30;
newFrame.origin.y += (EXPANDED_HEIGHT - CONTRACTED_HEIGHT);
self.messageTableView.frame = newFrame;
}
}
Expand Down
6 changes: 5 additions & 1 deletion Humanity/Humanity/Group Screen/MessageTableCellContentView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "MessageTableCellContentView.h"
#import "GroupConstants.h"

@implementation MessageTableCellContentView

Expand All @@ -26,10 +27,13 @@ - (id)initWithFrame:(CGRect)frame
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{

[[UIImage imageNamed:@"map.png"] drawInRect:CGRectMake(5, 5, 50, 50)];

// Drawing code
[[self.delegate name] drawAtPoint:CGPointMake(60, 5) withFont:[UIFont boldSystemFontOfSize:18.0]];

[[self.delegate body] drawInRect:CGRectMake(60, 25, 250, 100) withFont:[UIFont systemFontOfSize:12.0] lineBreakMode:UILineBreakModeWordWrap];
[[self.delegate content] drawInRect:CGRectMake(60, 25, MESSAGE_TEXT_WIDTH, 100) withFont:[UIFont systemFontOfSize:12.0] lineBreakMode:UILineBreakModeWordWrap];
}

@end
2 changes: 2 additions & 0 deletions Humanity/Humanity/Group Screen/MessageTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, retain) UIButton *closeButton;
@property (nonatomic, retain) UIButton *sendButton;
@property (nonatomic, retain) UISwitch *locationSwitch;
@property (assign) BOOL enabled;
@property (nonatomic, assign) id delegate;

@end
57 changes: 37 additions & 20 deletions Humanity/Humanity/Group Screen/MessageTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,45 @@
//

#import "MessageTextView.h"

#define CONTRACTED_TEXT_HEIGHT 30
#define EXPANDED_TEXT_HEIGHT 60
#define EXPANDED_HEIGHT 100
#define CONTRACTED_HEIGHT 70
#define PICTURE_SIZE 40
#define BUTTON_WIDTH 40
#define BUTTON_HEIGHT 20
#import "GroupConstants.h"
#import "SCAPIRequestController.h"
#import "ASIHTTPRequest.h"
#import "ASIHTTPRequestAdditions.h"

@implementation MessageTextView

@synthesize textView = _textView;
@synthesize closeButton = _closeButton;
@synthesize sendButton = _sendButton;
@synthesize enabled = _enabled;
@synthesize locationSwitch = _locationSwitch;
@synthesize delegate = _delegate;

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.clipsToBounds = YES;
self.backgroundColor = [UIColor colorWithWhite:200/255.0 alpha:1.0];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(PICTURE_SIZE + 10, 5, self.bounds.size.width - PICTURE_SIZE - 15, CONTRACTED_TEXT_HEIGHT)];
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(PICTURE_SIZE + 10, 10, self.bounds.size.width - PICTURE_SIZE - 20, CONTRACTED_TEXT_HEIGHT)];
self.textView.font = [UIFont systemFontOfSize:14.0];
self.textView.userInteractionEnabled = NO;
[self addSubview:self.textView];

[self showPlaceholder];

self.sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.sendButton.frame = CGRectMake(self.bounds.size.width - BUTTON_WIDTH - 5, CONTRACTED_TEXT_HEIGHT + 10, BUTTON_WIDTH, BUTTON_HEIGHT);
self.sendButton.titleLabel.text = @"Send";
self.sendButton.backgroundColor = [UIColor greenColor];
self.sendButton.frame = CGRectMake(self.bounds.size.width - BUTTON_WIDTH - 5, EXPANDED_HEIGHT - BUTTON_HEIGHT - 5, BUTTON_WIDTH, BUTTON_HEIGHT);
[self.sendButton setTitle:@"Send" forState:UIControlStateNormal];
[self.sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
self.sendButton.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
self.sendButton.backgroundColor = [UIColor colorWithRed:48/255.0 green:128/255.0 blue:20/255.0 alpha:1.0];
[self.sendButton addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.sendButton];

self.locationSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(60, self.sendButton.frame.origin.y, BUTTON_WIDTH, BUTTON_HEIGHT)];
[self addSubview:self.locationSwitch];
}
return self;
}
Expand Down Expand Up @@ -70,10 +75,6 @@ -(void)expand {
self.textView.frame = newFrame;
self.enabled = YES;

newFrame = self.sendButton.frame;
newFrame.origin.y += EXPANDED_HEIGHT - CONTRACTED_HEIGHT;
self.sendButton.frame = newFrame;

newFrame = self.frame;
newFrame.size.height = EXPANDED_HEIGHT;
self.frame = newFrame;
Expand All @@ -90,15 +91,31 @@ -(void)contract {
self.textView.frame = newFrame;
self.enabled = NO;

newFrame = self.sendButton.frame;
newFrame.origin.y -= EXPANDED_HEIGHT - CONTRACTED_HEIGHT;
self.sendButton.frame = newFrame;

newFrame = self.frame;
newFrame.size.height = CONTRACTED_HEIGHT;
self.frame = newFrame;
}

-(void)send:(id)sender {
if(self.delegate && [self.delegate respondsToSelector:@selector(sendMessage)]) {
[self.delegate sendMessage];
}

ASIHTTPRequest *request = [ASIHTTPRequest apiRequestWithAPI:@"message/create.json" target:self selectorFormat:@"sendRequest"];
request.requestMethod = POST;
[request setPostValue:self.textView.text forKey:@"content"];
[[SCAPIRequestController sharedController] addRequest:request];
}

- (void) sendRequestDidFinish:(ASIHTTPRequest *) request {
self.textView.text = @"";
[self.delegate toggleTextView:nil];
}

- (void) sendRequestDidFail:(ASIHTTPRequest *) request {
NSLog(@"Error");
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
Expand Down
2 changes: 1 addition & 1 deletion Humanity/Humanity/MessageTableCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@property (nonatomic, retain) MessageTableCellContentView *messageContentView;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *body;
@property (nonatomic, retain) NSString *content;
@property (nonatomic, retain) NSString *time;

@end
2 changes: 1 addition & 1 deletion Humanity/Humanity/MessageTableCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ @implementation MessageTableCell

@synthesize messageContentView = _messageContentView;
@synthesize name = _name;
@synthesize body = _body;
@synthesize content = _content;
@synthesize time = _time;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Expand Down

0 comments on commit f9216f8

Please sign in to comment.