Changeset 739
- Timestamp:
- 07/24/08 01:19:40 (6 months ago)
- Location:
- trunk/TwitterFon
- Files:
-
- 2 added
- 1 removed
- 11 modified
- 1 moved
-
Classes/MessageCell.h (modified) (1 diff)
-
Classes/MessageCell.m (modified) (5 diffs)
-
Classes/PostViewController.m (modified) (3 diffs)
-
Classes/REString.h (added)
-
Classes/REString.m (added)
-
Classes/StringUtil.h (modified) (1 diff)
-
Classes/StringUtil.m (modified) (1 diff)
-
Classes/TimelineViewController.m (modified) (4 diffs)
-
Classes/WebViewController.h (modified) (1 diff)
-
Classes/WebViewController.m (modified) (7 diffs)
-
Classes/main.m (moved) (moved from trunk/TwitterFon/main.m)
-
MainWindow.xib (modified) (10 diffs)
-
PostView.xib (deleted)
-
TimelineView.xib (modified) (6 diffs)
-
TwitterFon.xcodeproj/project.pbxproj (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TwitterFon/Classes/MessageCell.h
r737 r739 16 16 17 17 - (void)update; 18 + (CGFloat)heightForCell:(NSString*)text; 18 19 19 20 @end -
trunk/TwitterFon/Classes/MessageCell.m
r737 r739 1 1 #import "MessageCell.h" 2 #import "ColorUtils.h" 3 #import "StringUtil.h" 2 4 3 5 @implementation MessageCell … … 5 7 @synthesize message; 6 8 @synthesize imageView; 9 10 #define IMAGE_PADDING 10 11 #define H_MARGIN 10 12 #define INDICATOR_WIDTH 23 13 #define IMAGE_WIDTH 48 14 15 #define TOP 16 16 #define LEFT (IMAGE_PADDING * 2 + IMAGE_WIDTH) 7 17 8 18 - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier … … 33 43 [self.contentView addSubview:imageView]; 34 44 35 //self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;36 45 self.selectionStyle = UITableViewCellSelectionStyleNone; 37 46 … … 42 51 { 43 52 nameLabel.text = message.user.screenName; 44 textLabel.text = message.text;53 textLabel.text = [message.text unescapeHTML]; 45 54 } 46 55 … … 52 61 CGRect bounds; 53 62 54 const int TOP = 16; 55 const int LEFT = 68; 56 const int HMARGIN = 10; 57 const int VMARGIN = 0; 58 59 imageView.frame = CGRectMake(10, 0, 48, rc.size.height); 63 NSRange r = [textLabel.text rangeOfString:@"http://"]; 64 if (r.location != NSNotFound) { 65 self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 66 } 67 else { 68 self.accessoryType = UITableViewCellAccessoryNone; 69 } 60 70 61 nameLabel.frame = CGRectMake(LEFT, VMARGIN, rc.size.width - LEFT - HMARGIN, 16); 62 bounds = CGRectMake(LEFT, TOP, rc.size.width - LEFT - HMARGIN, rc.size.height - TOP); 71 self.backgroundColor = self.contentView.backgroundColor; 72 imageView.frame = CGRectMake(IMAGE_PADDING, 0, IMAGE_WIDTH, rc.size.height); 73 74 int contentWidth = 320 - INDICATOR_WIDTH - LEFT; 75 nameLabel.frame = CGRectMake(LEFT, 0, contentWidth, 16); 76 bounds = CGRectMake(LEFT, TOP, contentWidth, rc.size.height - TOP); 63 77 textLabel.frame = [textLabel textRectForBounds:bounds limitedToNumberOfLines:10]; 64 78 } 65 79 80 + (CGFloat)heightForCell:(NSString*)text 81 { 82 CGRect bounds; 83 CGRect result; 84 UILabel *textLabel = [[UILabel alloc] initWithFrame: CGRectZero]; 85 86 textLabel.font = [UIFont systemFontOfSize:13]; 87 textLabel.numberOfLines = 10; 88 89 textLabel.text = text; 90 bounds = CGRectMake(0, 0, 320 - INDICATOR_WIDTH - LEFT, 200); 91 result = [textLabel textRectForBounds:bounds limitedToNumberOfLines:10]; 92 result.size.height += 18; 93 if (result.size.height < IMAGE_WIDTH + 1) result.size.height = IMAGE_WIDTH + 1; 94 [textLabel release]; 95 return result.size.height; 96 97 } 98 66 99 @end -
trunk/TwitterFon/Classes/PostViewController.m
r738 r739 16 16 @interface NSObject (PostTweetDelegate) 17 17 - (void)postTweetDidSucceed:(Message*)message; 18 - (void)postViewAnimationDidStart;19 18 - (void)postViewAnimationDidFinish:(BOOL)didPost; 20 - (void)postViewAnimationDidCancel;21 19 @end 22 20 … … 80 78 81 79 CATransition *animation = [CATransition animation]; 82 [animation setDelegate:self];80 // [animation setDelegate:self]; 83 81 [animation setType:kCATransitionMoveIn]; 84 82 [animation setSubtype:kCATransitionFromBottom]; … … 174 172 // CAAnimationDelegate 175 173 // 176 - (void)animationDidSt art:(CAAnimation *)animation174 - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished 177 175 { 178 if (animation == [[self.view layer] animationForKey:kHideAnimationKey]) { 179 if([delegate respondsToSelector:@selector(postViewAnimationDidStart)]) { 180 [delegate postViewAnimationDidStart]; 176 [self.view removeFromSuperview]; 177 178 if (finished) { 179 if ([delegate respondsToSelector:@selector(postViewAnimationDidFinish:)]) { 180 [delegate postViewAnimationDidFinish:didPost]; 181 181 } 182 182 } 183 }184 183 185 - (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished186 {187 if (animation == [[self.view layer] animationForKey:kHideAnimationKey]) {188 [self.view removeFromSuperview];189 190 if (finished) {191 if ([delegate respondsToSelector:@selector(postViewAnimationDidFinish:)]) {192 [delegate postViewAnimationDidFinish:didPost];193 }194 }195 else {196 if ([delegate respondsToSelector:@selector(postViewAnimationDidCancel)]) {197 [delegate postViewAnimationDidCancel];198 }199 }200 }201 184 } 202 185 @end -
trunk/TwitterFon/Classes/StringUtil.h
r720 r739 11 11 @interface NSString (NSStringUtils) 12 12 - (NSString*)encodeAsURIComponent; 13 - (NSString*)escapeHTML; 14 - (NSString*)unescapeHTML; 15 + (NSString*)localizedString:(NSString*)key; 13 16 @end 17 18 -
trunk/TwitterFon/Classes/StringUtil.m
r720 r739 15 15 return [s autorelease]; 16 16 } 17 18 - (NSString*)escapeHTML 19 { 20 NSMutableString* s = [NSMutableString string]; 21 22 int start = 0; 23 int len = [self length]; 24 NSCharacterSet* chs = [NSCharacterSet characterSetWithCharactersInString:@"<>&\""]; 25 26 while (start < len) { 27 NSRange r = [self rangeOfCharacterFromSet:chs options:0 range:NSMakeRange(start, len-start)]; 28 if (r.location == NSNotFound) { 29 [s appendString:[self substringFromIndex:start]]; 30 break; 31 } 32 33 if (start < r.location) { 34 [s appendString:[self substringWithRange:NSMakeRange(start, r.location-start)]]; 35 } 36 37 switch ([self characterAtIndex:r.location]) { 38 case '<': 39 [s appendString:@"<"]; 40 break; 41 case '>': 42 [s appendString:@">"]; 43 break; 44 case '"': 45 [s appendString:@"""]; 46 break; 47 case '&': 48 [s appendString:@"&"]; 49 break; 50 } 51 52 start = r.location + 1; 53 } 54 55 return s; 56 } 57 58 - (NSString*)unescapeHTML 59 { 60 NSMutableString* s = [NSMutableString string]; 61 NSMutableString* target = [self mutableCopy]; 62 NSCharacterSet* chs = [NSCharacterSet characterSetWithCharactersInString:@"&"]; 63 64 while ([target length] > 0) { 65 NSRange r = [target rangeOfCharacterFromSet:chs]; 66 if (r.location == NSNotFound) { 67 [s appendString:target]; 68 break; 69 } 70 71 if (r.location > 0) { 72 [s appendString:[target substringToIndex:r.location]]; 73 [target deleteCharactersInRange:NSMakeRange(0, r.location)]; 74 } 75 76 if ([target hasPrefix:@"<"]) { 77 [s appendString:@"<"]; 78 [target deleteCharactersInRange:NSMakeRange(0, 4)]; 79 } else if ([target hasPrefix:@">"]) { 80 [s appendString:@">"]; 81 [target deleteCharactersInRange:NSMakeRange(0, 4)]; 82 } else if ([target hasPrefix:@"""]) { 83 [s appendString:@"\""]; 84 [target deleteCharactersInRange:NSMakeRange(0, 6)]; 85 } else if ([target hasPrefix:@"&"]) { 86 [s appendString:@"&"]; 87 [target deleteCharactersInRange:NSMakeRange(0, 5)]; 88 } else { 89 [s appendString:@"&"]; 90 [target deleteCharactersInRange:NSMakeRange(0, 1)]; 91 } 92 } 93 94 return s; 95 } 96 97 + (NSString*)localizedString:(NSString*)key 98 { 99 return [[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:key]; 100 } 101 17 102 @end 103 104 105 -
trunk/TwitterFon/Classes/TimelineViewController.m
r738 r739 4 4 #import "MessageCell.h" 5 5 #import "ColorUtils.h" 6 #import "StringUtil.h" 7 #import "REString.h" 6 8 7 9 @interface NSObject (TimelineViewControllerDelegate) … … 43 45 44 46 [timeline restore:tag]; 45 [timeline update:tag];47 // [timeline update:tag]; 46 48 } 47 49 … … 108 110 109 111 cell.message = m; 110 //cell.image = [imageStore getImage:m.user delegate:self]; 111 112 cell.imageView.row = indexPath.row; 112 113 [cell.imageView setImage:[imageStore getImage:m.user delegate:self] forState:UIControlStateNormal]; 113 114 [cell.imageView addTarget:self action:@selector(didTouchProfileImage:) forControlEvents:UIControlEventTouchUpInside]; 114 cell.imageView.row = indexPath.row;115 115 116 116 if (tag == TAB_FRIENDS) { … … 187 187 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 188 188 { 189 CGRect bounds;190 CGRect result;191 UILabel *textLabel = [[UILabel alloc] initWithFrame: CGRectZero];192 189 Message *m = [timeline messageAtIndex:indexPath.row]; 193 194 textLabel.font = [UIFont systemFontOfSize:13]; 195 textLabel.numberOfLines = 10; 196 197 textLabel.text = m.text; 198 bounds = CGRectMake(0, 0, 240, 200); 199 result = [textLabel textRectForBounds:bounds limitedToNumberOfLines:10]; 200 result.size.height += 18; 201 if (result.size.height < 48 + 1) result.size.height = 48 + 1; 202 [textLabel release]; 203 return result.size.height; 190 return [MessageCell heightForCell:m.text]; 204 191 } 205 192 206 193 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 207 194 { 208 // Message *m = [timeline messageAtIndex:indexPath.row]; 209 webView.hidesBottomBarWhenPushed = YES; 210 webView.url = @"http://www.naan.net/"; 211 [[self navigationController] pushViewController:webView animated:YES]; 212 } 213 214 - (void)postViewAnimationDidStart 215 { 216 [[self navigationController] setNavigationBarHidden:FALSE animated:YES]; 195 Message *m = [timeline messageAtIndex:indexPath.row]; 196 if (!m) return; 197 NSString *pat = @"(((http(s?))\\:\\/\\/)([0-9a-zA-Z\\-]+\\.)+[a-zA-Z]{2,6}(\\:[0-9]+)?(\\/([0-9a-zA-Z_#!:.?+=&%@~*\';,\\-\\/\\$])*)?)"; 198 NSString *text = m.text; 199 NSMutableArray *array = [[NSMutableArray alloc] init]; 200 if ([text matches:pat withSubstring:array]) { 201 webView.hidesBottomBarWhenPushed = YES; 202 [webView setUrl:[array objectAtIndex:0]]; 203 [[self navigationController] pushViewController:webView animated:YES]; 204 } 217 205 } 218 206 219 207 - (void)postViewAnimationDidFinish:(BOOL)didPost 220 208 { 221 if (didPost && tag == TAB_FRIENDS) { 209 if (didPost && tag == TAB_FRIENDS && 210 self.navigationController.topViewController == self) { 222 211 // 223 212 // Do animation if the controller displays friends timeline. -
trunk/TwitterFon/Classes/WebViewController.h
r738 r739 11 11 12 12 @interface WebViewController : UIViewController { 13 IBOutlet UIWebView* webView; 14 NSString* url; 13 IBOutlet UIWebView* webView; 14 NSString* url; 15 BOOL needsReload; 15 16 } 16 17 17 @property(nonatomic, copy) NSString* url;18 - (void)setUrl:(NSString*)aUrl; 18 19 19 20 @end -
trunk/TwitterFon/Classes/WebViewController.m
r738 r739 16 16 @implementation WebViewController 17 17 18 @synthesize url;19 20 18 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 21 19 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { … … 24 22 return self; 25 23 } 26 27 /*28 Implement loadView if you want to create a view hierarchy programmatically29 - (void)loadView {30 }31 */32 33 24 34 25 - (void)viewDidLoad … … 40 31 action:@selector(postTweet:)]; 41 32 self.navigationItem.rightBarButtonItem = postButton; 33 needsReload = false; 34 url = [[NSString alloc] init]; 42 35 } 43 36 … … 45 38 { 46 39 [super viewDidAppear:animated]; 47 if (animated ) {40 if (animated && needsReload) { 48 41 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]]; 49 42 self.title = url; … … 51 44 } 52 45 46 - (void)webViewDidFinishLoad:(UIWebView *)aWebView 47 { 48 self.title = [aWebView stringByEvaluatingJavaScriptFromString:@"document.title"]; 49 } 50 51 - (void)setUrl:(NSString*)aUrl 52 { 53 needsReload = ([url compare:aUrl] == 0) ? false : true; 54 url = [aUrl copy]; 55 } 53 56 54 57 - (void)postTweet:(id)sender … … 60 63 61 64 [[self navigationController].view addSubview:postView.view]; 62 [postView startEditWithString:url insertAfter:TRUE setDelegate:self]; 65 UIViewController *c = [self.navigationController.viewControllers objectAtIndex:0]; 66 [postView startEditWithString:[NSString stringWithFormat:@" %@", url] insertAfter:TRUE setDelegate:c]; 63 67 64 68 } … … 72 76 - (void)dealloc { 73 77 [super dealloc]; 78 [url release]; 74 79 } 75 80 -
trunk/TwitterFon/MainWindow.xib
r738 r739 10 10 <bool key="EncodedWithXMLCoder">YES</bool> 11 11 <integer value="164"/> 12 <integer value="235"/> 12 13 </object> 13 14 <object class="NSArray" key="IBDocument.PluginDependencies"> … … 197 198 </object> 198 199 <object class="IBUIView" id="308163607"> 199 < nilkey="NSNextResponder"/>200 <reference key="NSNextResponder"/> 200 201 <int key="NSvFlags">290</int> 201 202 <object class="NSMutableArray" key="NSSubviews"> … … 261 262 <reference key="IBUIToolbar" ref="609196020"/> 262 263 </object> 263 <object class="IBUIBarButtonItem" id="571423707">264 <object class="NSCustomResource" key="IBUIImage">265 <string key="NSClassName">NSImage</string>266 <string key="NSResourceName">library.png</string>267 </object>268 <int key="IBUIStyle">1</int>269 <reference key="IBUIToolbar" ref="609196020"/>270 </object>271 <object class="IBUIBarButtonItem" id="423124433">272 <int key="IBUIStyle">1</int>273 <int key="IBUISystemItemIdentifier">15</int>274 <reference key="IBUIToolbar" ref="609196020"/>275 </object>276 264 <object class="IBUIBarButtonItem" id="629353764"> 277 265 <float key="IBUIWidth">3.900000e+01</float> … … 321 309 </object> 322 310 <string key="NSFrameSize">{320, 240}</string> 311 <reference key="NSSuperview"/> 323 312 <object class="NSColor" key="IBUIBackgroundColor"> 324 313 <int key="NSColorSpace">1</int> … … 405 394 <object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/> 406 395 </object> 396 <object class="IBUIBarButtonItem" id="571423707"> 397 <object class="NSCustomResource" key="IBUIImage"> 398 <string key="NSClassName">NSImage</string> 399 <string key="NSResourceName">library.png</string> 400 </object> 401 <int key="IBUIStyle">1</int> 402 </object> 403 <object class="IBUIBarButtonItem" id="423124433"> 404 <int key="IBUIStyle">1</int> 405 <int key="IBUISystemItemIdentifier">15</int> 406 </object> 407 407 </object> 408 408 <object class="IBObjectContainer" key="IBDocument.Objects"> … … 832 832 <bool key="EncodedWithXMLCoder">YES</bool> 833 833 <reference ref="474449565"/> 834 <reference ref="609196020"/>835 834 <reference ref="72805672"/> 836 835 <reference ref="393388047"/> 836 <reference ref="609196020"/> 837 837 </object> 838 838 <reference key="parent" ref="957960031"/> … … 845 845 </object> 846 846 <object class="IBObjectRecord"> 847 <int key="objectID">235</int>848 <reference key="object" ref="609196020"/>849 <object class="NSMutableArray" key="children">850 <bool key="EncodedWithXMLCoder">YES</bool>851 <reference ref="629353764"/>852 <reference ref="1064367590"/>853 <reference ref="638520527"/>854 <reference ref="423124433"/>855 <reference ref="122934535"/>856 <reference ref="571423707"/>857 </object>858 <reference key="parent" ref="308163607"/>859 </object>860 <object class="IBObjectRecord">861 847 <int key="objectID">236</int> 862 848 <reference key="object" ref="72805672"/> … … 867 853 <reference key="object" ref="393388047"/> 868 854 <reference key="parent" ref="308163607"/> 869 </object>870 <object class="IBObjectRecord">871 <int key="objectID">238</int>872 <reference key="object" ref="629353764"/>873 <reference key="parent" ref="609196020"/>874 </object>875 <object class="IBObjectRecord">876 <int key="objectID">239</int>877 <reference key="object" ref="1064367590"/>878 <reference key="parent" ref="609196020"/>879 </object>880 <object class="IBObjectRecord">881 <int key="objectID">240</int>882 <reference key="object" ref="638520527"/>883 <reference key="parent" ref="609196020"/>884 </object>885 <object class="IBObjectRecord">886 <int key="objectID">241</int>887 <reference key="object" ref="423124433"/>888 <reference key="parent" ref="609196020"/>889 </object>890 <object class="IBObjectRecord">891 <int key="objectID">242</int>892 <reference key="object" ref="122934535"/>893 <reference key="parent" ref="609196020"/>894 </object>895 <object class="IBObjectRecord">896 <int key="objectID">243</int>897 <reference key="object" ref="571423707"/>898 <reference key="parent" ref="609196020"/>899 855 </object> 900 856 <object class="IBObjectRecord"> … … 945 901  
