Skip to content

Commit

Permalink
using Friend.
Browse files Browse the repository at this point in the history
  • Loading branch information
mootoh committed Jun 21, 2009
1 parent ee1df93 commit 585182f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Classes/Friend.h
Expand Up @@ -20,11 +20,11 @@
NSDate *last_update;
}

@property (nonatomic, assign) NSString *name;
@property (nonatomic, assign) NSString *image_url;
@property (nonatomic, assign) UIImage *image;
@property (nonatomic, assign) CLLocation *location;
@property (nonatomic, assign) NSDate *last_update;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *image_url;
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) CLLocation *location;
@property (nonatomic, retain) NSDate *last_update;

- (id) initWithName:(NSString *)nm;
- (void) update; // retrieve latest information from the server
Expand Down
13 changes: 13 additions & 0 deletions Classes/Friend.m
Expand Up @@ -58,4 +58,17 @@ - (void) cacheImage
{
}

- (BOOL) isEqual:(id) other
{
NSLog(@"Friend:isEqual");
Friend *other_friend = (Friend *)other;
return [name isEqualToString:other_friend.name];
}

- (NSString *) description
{
return [NSString stringWithFormat:@"Friend %p: name=%@", self, name];
//return [NSString stringWithFormat:@"Friend %p: name=%@", self, @"hoge"];
}

@end
16 changes: 10 additions & 6 deletions Classes/FriendsPickViewController.m
Expand Up @@ -11,6 +11,7 @@
#import "TwitterFriends.h"
#import "AppDelegate.h"
#import "MySelf.h"
#import "Friend.h"

@interface FriendsPickViewController (Private)
- (UIImage *) getIcon:(NSDictionary *)user;
Expand Down Expand Up @@ -61,11 +62,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.accessoryType = UITableViewCellAccessoryNone;

NSDictionary *user = [twitter_friends objectAtIndex:indexPath.row];
Friend *friend = [[[Friend alloc] initWithName:[user objectForKey:@"screen_name"]] autorelease];
UIImage *img = [self getIcon:user];
cell.imageView.image = img;
cell.textLabel.text = [user objectForKey:@"screen_name"];
cell.textLabel.text = friend.name;

if ([my_self.friends containsObject:[user objectForKey:@"screen_name"]])
if ([my_self.friends containsObject:friend])
cell.accessoryType = UITableViewCellAccessoryCheckmark;

return cell;
Expand All @@ -75,17 +77,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
{
NSDictionary *user = [twitter_friends objectAtIndex:indexPath.row];
NSString *friend_name = [user objectForKey:@"screen_name"];
Friend *friend = [[[Friend alloc] initWithName:friend_name] autorelease];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

if ([my_self.friends containsObject:friend_name]) {
[my_self.friends removeObject:friend_name];
if ([my_self.friends containsObject:friend]) {
[my_self.friends removeObject:friend];
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
[my_self.friends addObject:friend_name];
[my_self.friends addObject:friend];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

[[NSUserDefaults standardUserDefaults] setObject:my_self.friends forKey:DR_FRIENDS];
//[[NSUserDefaults standardUserDefaults] setObject:my_self.friends forKey:DR_FRIENDS];
}

#pragma mark others
Expand Down
2 changes: 2 additions & 0 deletions Classes/MySelf.m
Expand Up @@ -88,10 +88,12 @@ - (NSArray *) twitterFriends

- (void) addFriend:(Friend *)friend
{
[friends addObject:friend];
}

- (void) removeFriend:(Friend *)friend;
{
[friends removeObject:friend];
}

- (void) saveFriends
Expand Down

0 comments on commit 585182f

Please sign in to comment.