Changeset 785
- Timestamp:
- 07/27/08 01:01:42 (5 months ago)
- Location:
- trunk/TwitterFon
- Files:
-
- 2 removed
- 6 modified
-
Classes/Controllers/MessageCell.h (modified) (2 diffs)
-
Classes/Controllers/MessageCell.m (modified) (4 diffs)
-
Classes/Controllers/ProfileImageButton.h (deleted)
-
Classes/Controllers/ProfileImageButton.m (deleted)
-
Classes/Controllers/TimelineViewController.m (modified) (5 diffs)
-
Classes/Twitter/Message.h (modified) (1 diff)
-
Classes/Twitter/Message.m (modified) (3 diffs)
-
TwitterFon.xcodeproj/project.pbxproj (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TwitterFon/Classes/Controllers/MessageCell.h
r770 r785 1 1 #import <UIKit/UIKit.h> 2 2 #import "Message.h" 3 #import "ProfileImageButton.h"4 3 5 4 #define MESSAGE_REUSE_INDICATOR @"MessageCell" … … 10 9 UILabel* nameLabel; 11 10 UILabel* textLabel; 12 13 ProfileImageButton* imageView; 11 NSObject* delegate; 14 12 } 15 13 16 14 @property (nonatomic, assign) Message* message; 17 @property (nonatomic, assign) ProfileImageButton* imageView;18 15 19 - (void)update ;16 - (void)update:(id)delegate; 20 17 21 18 @end -
trunk/TwitterFon/Classes/Controllers/MessageCell.m
r770 r785 3 3 #import "StringUtil.h" 4 4 5 @interface NSObject (MessageCellDelegate) 6 - (void)didTouchDetailButton:(id)sender; 7 @end 8 9 @interface MessageCell (Private) 10 - (void)didTouchAccessory:(id)sender; 11 @end 12 5 13 @implementation MessageCell 6 14 7 15 @synthesize message; 8 @synthesize imageView;9 16 10 17 - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier … … 19 26 nameLabel.font = [UIFont boldSystemFontOfSize:14]; 20 27 nameLabel.textAlignment = UITextAlignmentLeft; 21 nameLabel.frame = CGRectMake(LEFT, 0, CELL_WIDTH , 16);28 nameLabel.frame = CGRectMake(LEFT, 0, CELL_WIDTH - DETAIL_BUTTON_WIDTH, 16); 22 29 23 30 [self.contentView addSubview:nameLabel]; … … 34 41 [self.contentView addSubview:textLabel]; 35 42 36 imageView = [[[ProfileImageButton alloc] initWithFrame:CGRectZero] autorelease]; 37 [self.contentView addSubview:imageView]; 38 43 self.selectionStyle = UITableViewCellSelectionStyleBlue; 44 45 self.target = self; 46 self.accessoryAction = @selector(didTouchAccessory:); 47 39 48 return self; 40 49 } 41 50 42 - (void) update51 - (void)didTouchAccessory:(id)sender 43 52 { 53 if (delegate) { 54 [delegate didTouchDetailButton:self]; 55 } 56 } 57 58 - (void)update:(id)aDelegate 59 { 60 delegate = aDelegate; 44 61 nameLabel.text = message.user.screenName; 45 62 textLabel.text = [message.text unescapeHTML]; … … 51 68 [super layoutSubviews]; 52 69 self.backgroundColor = self.contentView.backgroundColor; 53 if (self.accessoryType == UITableViewCellAccessoryNone) {54 self.selectionStyle = UITableViewCellSelectionStyleNone;55 }56 else {57 self.selectionStyle = UITableViewCellSelectionStyleBlue;58 }59 imageView.frame = CGRectMake(IMAGE_PADDING, 0, IMAGE_WIDTH, message.cellHeight);60 70 textLabel.frame = [textLabel textRectForBounds:message.textBounds limitedToNumberOfLines:10]; 61 71 } -
trunk/TwitterFon/Classes/Controllers/TimelineViewController.m
r782 r785 1 // 2 // TimelieViewController.m 3 // TwitterFon 4 // 5 // Created by kaz on 7/23/08. 6 // Copyright 2008 naan studio. All rights reserved. 7 // 8 1 9 #import <QuartzCore/QuartzCore.h> 2 10 #import "TimelineViewController.h" … … 95 103 96 104 cell.message = m; 97 cell.imageView.row = indexPath.row; 98 [cell.imageView setImage:[imageStore getImage:m.user delegate:self] forState:UIControlStateNormal]; 99 [cell.imageView addTarget:self action:@selector(didTouchProfileImage:) forControlEvents:UIControlEventTouchUpInside]; 100 105 cell.image = [imageStore getImage:m.user delegate:self]; 106 101 107 if (tag == TAB_FRIENDS) { 102 108 NSString *str = [NSString stringWithFormat:@"@%@", username]; … … 115 121 cell.contentView.backgroundColor = [UIColor messageColor:m.unread]; 116 122 } 117 118 [cell update ];123 124 [cell update:self]; 119 125 120 126 return cell; 121 127 } 122 128 123 - (void)didTouchProfileImage:(id)sender 124 { 125 ProfileImageButton *button = (ProfileImageButton*)sender; 126 Message* m = [timeline messageAtIndex:button.row]; 127 128 TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 129 PostViewController* postView = appDelegate.postView; 130 131 if (postView.view.hidden == false) return; 132 133 NSString *msg; 134 if (tag == MSG_TYPE_MESSAGES) { 135 msg = [NSString stringWithFormat:@"d %@ ", m.user.screenName]; 136 } 137 else { 138 msg = [NSString stringWithFormat:@"@%@ ", m.user.screenName]; 139 } 140 141 [[self navigationController].view addSubview:postView.view]; 142 [postView startEditWithString:msg setDelegate:self]; 143 } 144 145 - (void)didReceiveMemoryWarning 146 { 147 [super didReceiveMemoryWarning]; 148 } 149 150 - (IBAction) post: (id) sender 151 { 152 TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 153 PostViewController* postView = appDelegate.postView; 154 155 [[self navigationController].view addSubview:postView.view]; 156 [postView startEditWithDelegate:self]; 157 } 158 159 - (IBAction) reload: (id) sender 160 { 161 [timeline update:tag]; 162 } 163 164 165 // 166 // UITableViewDelegate 167 // 168 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 169 { 170 Message *m = [timeline messageAtIndex:indexPath.row]; 171 return m.cellHeight; 172 } 173 174 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 175 { 176 Message *m = [timeline messageAtIndex:indexPath.row]; 129 - (void)didTouchDetailButton:(MessageCell*)cell 130 { 131 Message *m = cell.message; 177 132 if (!m) return; 178 133 NSString *pat = @"(((http(s?))\\:\\/\\/)([0-9a-zA-Z\\-]+\\.)+[a-zA-Z]{2,6}(\\:[0-9]+)?(\\/([0-9a-zA-Z_#!:.?+=&%@~*\';,\\-\\/\\$])*)?)"; 179 134 NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; 180 135 if ([m.text matches:pat withSubstring:array]) { 181 136 182 137 TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 183 138 WebViewController *webView = appDelegate.webView; … … 189 144 } 190 145 146 - (void)didReceiveMemoryWarning 147 { 148 [super didReceiveMemoryWarning]; 149 } 150 151 - (IBAction) post: (id) sender 152 { 153 TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 154 PostViewController* postView = appDelegate.postView; 155 156 [[self navigationController].view addSubview:postView.view]; 157 [postView startEditWithDelegate:self]; 158 } 159 160 - (IBAction) reload: (id) sender 161 { 162 [timeline update:tag]; 163 } 164 165 166 // 167 // UITableViewDelegate 168 // 169 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 170 { 171 Message *m = [timeline messageAtIndex:indexPath.row]; 172 return m.cellHeight; 173 } 174 175 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 176 { 177 Message* m = [timeline messageAtIndex:indexPath.row]; 178 179 TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 180 PostViewController* postView = appDelegate.postView; 181 182 if (postView.view.hidden == false) return; 183 184 NSString *msg; 185 if (tag == MSG_TYPE_MESSAGES) { 186 msg = [NSString stringWithFormat:@"d %@ ", m.user.screenName]; 187 } 188 else { 189 msg = [NSString stringWithFormat:@"@%@ ", m.user.screenName]; 190 } 191 192 [[self navigationController].view addSubview:postView.view]; 193 [postView startEditWithString:msg setDelegate:self]; 194 } 195 191 196 - (void)postViewAnimationDidFinish:(BOOL)didPost 192 197 { … … 258 263 if (!self.view.hidden) { 259 264 NSMutableArray *indexPath = [[[NSMutableArray alloc] init] autorelease]; 265 // 266 // Avoid to create too many table cell. 267 // 268 if (count > 8) count = 8; 260 269 for (int i = 0; i < count; ++i) { 261 270 [indexPath addObject:[NSIndexPath indexPathForRow:i inSection:0]]; -
trunk/TwitterFon/Classes/Twitter/Message.h
r759 r785 9 9 } MessageType; 10 10 11 #define IMAGE_PADDING 10 12 #define H_MARGIN 10 13 #define INDICATOR_WIDTH 23 14 #define IMAGE_WIDTH 48 11 #define IMAGE_PADDING 10 12 #define H_MARGIN 10 13 #define INDICATOR_WIDTH 20 14 #define DETAIL_BUTTON_WIDTH 19 15 #define IMAGE_WIDTH 48 15 16 16 #define TOP 1617 #define LEFT (IMAGE_PADDING * 2 + IMAGE_WIDTH)18 #define CELL_WIDTH (320 - INDICATOR_WIDTH - LEFT)17 #define TOP 16 18 #define LEFT (IMAGE_PADDING * 2 + IMAGE_WIDTH) 19 #define CELL_WIDTH (320 - INDICATOR_WIDTH - LEFT) 19 20 20 21 @interface Message : NSObject -
trunk/TwitterFon/Classes/Twitter/Message.m
r766 r785 59 59 - (void)updateAttribute 60 60 { 61 // Set accessoryType and bounds width 62 // 63 NSRange r = [text rangeOfString:@"http://"]; 64 int textWidth = CELL_WIDTH; 65 if (r.location != NSNotFound) { 66 //accessoryType = UITableViewCellAccessoryDisclosureIndicator; 67 accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 68 textWidth -= DETAIL_BUTTON_WIDTH; 69 } 70 else { 71 accessoryType = UITableViewCellAccessoryNone; 72 } 73 74 61 75 // Calculate cell height here 62 76 // … … 69 83 70 84 textLabel.text = text; 71 bounds = CGRectMake(0, 0, 320 - INDICATOR_WIDTH - LEFT, 200);85 bounds = CGRectMake(0, 0, textWidth, 200); 72 86 result = [textLabel textRectForBounds:bounds limitedToNumberOfLines:10]; 73 87 result.size.height += 18; … … 75 89 cellHeight = result.size.height; 76 90 [textLabel release]; 77 78 // Set accessoryType79 //80 NSRange r = [text rangeOfString:@"http://"];81 if (r.location != NSNotFound) {82 accessoryType = UITableViewCellAccessoryDisclosureIndicator;83 }84 else {85 accessoryType = UITableViewCellAccessoryNone;86 }87 91 88 // Set text bounds 89 // 90 textBounds = CGRectMake(LEFT, TOP, CELL_WIDTH, cellHeight - TOP); 92 textBounds = CGRectMake(LEFT, TOP, textWidth, cellHeight - TOP); 91 93 } 92 94 -
trunk/TwitterFon/TwitterFon.xcodeproj/project.pbxproj
r782 r785 34 34 6EEBF7160E3B20610003EA63 /* SettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7130E3B20610003EA63 /* SettingsTableViewController.m */; }; 35 35 6EEBF71D0E3B20830003EA63 /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7180E3B20830003EA63 /* MessageCell.m */; }; 36 6EEBF71E0E3B20830003EA63 /* ProfileImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF71A0E3B20830003EA63 /* ProfileImageButton.m */; };37 36 6EEBF71F0E3B20830003EA63 /* TimelineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */; }; 38 37 6EEBF7240E3B20910003EA63 /* PostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7210E3B20910003EA63 /* PostViewController.m */; }; … … 99 98 6EEBF7170E3B20830003EA63 /* MessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MessageCell.h; path = Controllers/MessageCell.h; sourceTree = "<group>"; }; 100 99 6EEBF7180E3B20830003EA63 /* MessageCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MessageCell.m; path = Controllers/MessageCell.m; sourceTree = "<group>"; }; 101 6EEBF7190E3B20830003EA63 /* ProfileImageButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ProfileImageButton.h; path = Controllers/ProfileImageButton.h; sourceTree = "<group>"; };102 6EEBF71A0E3B20830003EA63 /* ProfileImageButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ProfileImageButton.m; path = Controllers/ProfileImageButton.m; sourceTree = "<group>"; };103 100 6EEBF71B0E3B20830003EA63 /* TimelineViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimelineViewController.h; path = Controllers/TimelineViewController.h; sourceTree = "<group>"; }; 104 101 6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TimelineViewController.m; path = Controllers/TimelineViewController.m; sourceTree = "<group>"; }; … … 254 251 6EEBF7170E3B20830003EA63 /* MessageCell.h */, 255 252 6EEBF7180E3B20830003EA63 /* MessageCell.m */, 256 6EEBF7190E3B20830003EA63 /* ProfileImageButton.h */,257 6EEBF71A0E3B20830003EA63 /* ProfileImageButton.m */,258 253 6EEBF71B0E3B20830003EA63 /* TimelineViewController.h */, 259 254 6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */, … … 453 448 6EEBF7160E3B20610003EA63 /* SettingsTableViewController.m in Sources */, 454 449 6EEBF71D0E3B20830003EA63 /* MessageCell.m in Sources */, 455 6EEBF71E0E3B20830003EA63 /* ProfileImageButton.m in Sources */,456 450 6EEBF71F0E3B20830003EA63 /* TimelineViewController.m in Sources */, 457 451 6EEBF7240E3B20910003EA63 /* PostViewController.m in Sources */,
