Changeset 785

Show
Ignore:
Timestamp:
07/27/08 01:01:42 (5 months ago)
Author:
kaz
Message:

Modified user interface behavior:

Location:
trunk/TwitterFon
Files:
2 removed
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/TwitterFon/Classes/Controllers/MessageCell.h

    r770 r785  
    11#import <UIKit/UIKit.h> 
    22#import "Message.h" 
    3 #import "ProfileImageButton.h" 
    43 
    54#define MESSAGE_REUSE_INDICATOR @"MessageCell" 
     
    109        UILabel*        nameLabel; 
    1110        UILabel*        textLabel; 
    12  
    13     ProfileImageButton* imageView; 
     11    NSObject*       delegate; 
    1412} 
    1513 
    1614@property (nonatomic, assign) Message*              message; 
    17 @property (nonatomic, assign) ProfileImageButton*   imageView; 
    1815 
    19 - (void)update; 
     16- (void)update:(id)delegate; 
    2017 
    2118@end 
  • trunk/TwitterFon/Classes/Controllers/MessageCell.m

    r770 r785  
    33#import "StringUtil.h" 
    44 
     5@interface NSObject (MessageCellDelegate) 
     6- (void)didTouchDetailButton:(id)sender; 
     7@end 
     8 
     9@interface MessageCell (Private) 
     10- (void)didTouchAccessory:(id)sender; 
     11@end 
     12 
    513@implementation MessageCell 
    614 
    715@synthesize message; 
    8 @synthesize imageView; 
    916 
    1017- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier 
     
    1926    nameLabel.font = [UIFont boldSystemFontOfSize:14]; 
    2027    nameLabel.textAlignment = UITextAlignmentLeft; 
    21     nameLabel.frame = CGRectMake(LEFT, 0, CELL_WIDTH, 16); 
     28    nameLabel.frame = CGRectMake(LEFT, 0, CELL_WIDTH - DETAIL_BUTTON_WIDTH, 16); 
    2229     
    2330    [self.contentView addSubview:nameLabel]; 
     
    3441    [self.contentView addSubview:textLabel]; 
    3542     
    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     
    3948        return self; 
    4049} 
    4150 
    42 - (void)update 
     51- (void)didTouchAccessory:(id)sender 
    4352{ 
     53    if (delegate) { 
     54        [delegate didTouchDetailButton:self]; 
     55    } 
     56} 
     57 
     58- (void)update:(id)aDelegate 
     59{ 
     60    delegate = aDelegate; 
    4461        nameLabel.text = message.user.screenName; 
    4562        textLabel.text = [message.text unescapeHTML];   
     
    5168        [super layoutSubviews]; 
    5269    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); 
    6070    textLabel.frame = [textLabel textRectForBounds:message.textBounds limitedToNumberOfLines:10]; 
    6171} 
  • 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 
    19#import <QuartzCore/QuartzCore.h> 
    210#import "TimelineViewController.h" 
     
    95103     
    96104        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 
    101107    if (tag == TAB_FRIENDS) { 
    102108        NSString *str = [NSString stringWithFormat:@"@%@", username]; 
     
    115121        cell.contentView.backgroundColor = [UIColor messageColor:m.unread]; 
    116122    } 
    117      
    118         [cell update]; 
     123    
     124        [cell update:self]; 
    119125 
    120126        return cell; 
    121127} 
    122128 
    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; 
    177132    if (!m) return; 
    178133    NSString *pat = @"(((http(s?))\\:\\/\\/)([0-9a-zA-Z\\-]+\\.)+[a-zA-Z]{2,6}(\\:[0-9]+)?(\\/([0-9a-zA-Z_#!:.?+=&%@~*\';,\\-\\/\\$])*)?)"; 
    179134    NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease]; 
    180135    if ([m.text matches:pat withSubstring:array]) { 
    181  
     136         
    182137        TwitterFonAppDelegate *appDelegate = (TwitterFonAppDelegate*)[UIApplication sharedApplication].delegate; 
    183138        WebViewController *webView = appDelegate.webView; 
     
    189144} 
    190145 
     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 
    191196- (void)postViewAnimationDidFinish:(BOOL)didPost 
    192197{ 
     
    258263    if (!self.view.hidden) { 
    259264        NSMutableArray *indexPath = [[[NSMutableArray alloc] init] autorelease]; 
     265        // 
     266        // Avoid to create too many table cell. 
     267        // 
     268        if (count > 8) count = 8; 
    260269        for (int i = 0; i < count; ++i) { 
    261270            [indexPath addObject:[NSIndexPath indexPathForRow:i inSection:0]]; 
  • trunk/TwitterFon/Classes/Twitter/Message.h

    r759 r785  
    99} MessageType; 
    1010 
    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 
    1516 
    16 #define TOP             16 
    17 #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) 
    1920 
    2021@interface Message : NSObject 
  • trunk/TwitterFon/Classes/Twitter/Message.m

    r766 r785  
    5959- (void)updateAttribute 
    6060{ 
     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     
    6175    // Calculate cell height here 
    6276    // 
     
    6983     
    7084    textLabel.text = text; 
    71     bounds = CGRectMake(0, 0, 320 - INDICATOR_WIDTH - LEFT, 200); 
     85    bounds = CGRectMake(0, 0, textWidth, 200); 
    7286    result = [textLabel textRectForBounds:bounds limitedToNumberOfLines:10]; 
    7387    result.size.height += 18; 
     
    7589    cellHeight = result.size.height; 
    7690    [textLabel release]; 
    77      
    78     // Set accessoryType 
    79     // 
    80     NSRange r = [text rangeOfString:@"http://"]; 
    81     if (r.location != NSNotFound) {     
    82         accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    83     } 
    84     else { 
    85         accessoryType = UITableViewCellAccessoryNone; 
    86     } 
    8791 
    88     // Set text bounds 
    89     // 
    90     textBounds = CGRectMake(LEFT, TOP, CELL_WIDTH, cellHeight - TOP); 
     92    textBounds = CGRectMake(LEFT, TOP, textWidth, cellHeight - TOP); 
    9193} 
    9294 
  • trunk/TwitterFon/TwitterFon.xcodeproj/project.pbxproj

    r782 r785  
    3434                6EEBF7160E3B20610003EA63 /* SettingsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7130E3B20610003EA63 /* SettingsTableViewController.m */; }; 
    3535                6EEBF71D0E3B20830003EA63 /* MessageCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7180E3B20830003EA63 /* MessageCell.m */; }; 
    36                 6EEBF71E0E3B20830003EA63 /* ProfileImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF71A0E3B20830003EA63 /* ProfileImageButton.m */; }; 
    3736                6EEBF71F0E3B20830003EA63 /* TimelineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */; }; 
    3837                6EEBF7240E3B20910003EA63 /* PostViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EEBF7210E3B20910003EA63 /* PostViewController.m */; }; 
     
    9998                6EEBF7170E3B20830003EA63 /* MessageCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MessageCell.h; path = Controllers/MessageCell.h; sourceTree = "<group>"; }; 
    10099                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>"; }; 
    103100                6EEBF71B0E3B20830003EA63 /* TimelineViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimelineViewController.h; path = Controllers/TimelineViewController.h; sourceTree = "<group>"; }; 
    104101                6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TimelineViewController.m; path = Controllers/TimelineViewController.m; sourceTree = "<group>"; }; 
     
    254251                                6EEBF7170E3B20830003EA63 /* MessageCell.h */, 
    255252                                6EEBF7180E3B20830003EA63 /* MessageCell.m */, 
    256                                 6EEBF7190E3B20830003EA63 /* ProfileImageButton.h */, 
    257                                 6EEBF71A0E3B20830003EA63 /* ProfileImageButton.m */, 
    258253                                6EEBF71B0E3B20830003EA63 /* TimelineViewController.h */, 
    259254                                6EEBF71C0E3B20830003EA63 /* TimelineViewController.m */, 
     
    453448                                6EEBF7160E3B20610003EA63 /* SettingsTableViewController.m in Sources */, 
    454449                                6EEBF71D0E3B20830003EA63 /* MessageCell.m in Sources */, 
    455                                 6EEBF71E0E3B20830003EA63 /* ProfileImageButton.m in Sources */, 
    456450                                6EEBF71F0E3B20830003EA63 /* TimelineViewController.m in Sources */, 
    457451                                6EEBF7240E3B20910003EA63 /* PostViewController.m in Sources */,