Refactor table view cells (by introducing a subclass). t20
authorStefane Fermigier <sfermigier@nuxeo.com>
Mon, 08 Mar 2010 18:11:23 +0100
brancht20
changeset 36c162e52d9e5b
parent 35 63745f2fc58a
child 37 0c7da81f2e98
Refactor table view cells (by introducing a subclass).
Classes/FolderViewCell.h
Classes/FolderViewCell.m
Classes/FolderViewController.m
iNuxeo.xcodeproj/project.pbxproj
     1.1 new file mode 100644
     1.2 --- /dev/null
     1.3 +++ b/Classes/FolderViewCell.h
     1.4 @@ -0,0 +1,18 @@
     1.5 +//
     1.6 +//  FolderViewCell.h
     1.7 +//  iNuxeo
     1.8 +//
     1.9 +//  Created by Stefane Fermigier on 3/8/10.
    1.10 +//  Copyright 2010 Nuxeo. All rights reserved.
    1.11 +//
    1.12 +
    1.13 +#import <UIKit/UIKit.h>
    1.14 +#import "NXObject.h"
    1.15 +
    1.16 +@interface FolderViewCell : UITableViewCell {
    1.17 +
    1.18 +}
    1.19 +
    1.20 +- (id)initWithObject:(NXObject *)object;
    1.21 +
    1.22 +@end
     2.1 new file mode 100644
     2.2 --- /dev/null
     2.3 +++ b/Classes/FolderViewCell.m
     2.4 @@ -0,0 +1,73 @@
     2.5 +//
     2.6 +//  FolderViewCell.m
     2.7 +//  iNuxeo
     2.8 +//
     2.9 +//  Created by Stefane Fermigier on 3/8/10.
    2.10 +//  Copyright 2010 Nuxeo. All rights reserved.
    2.11 +//
    2.12 +
    2.13 +#import "FolderViewCell.h"
    2.14 +
    2.15 +@implementation FolderViewCell
    2.16 +
    2.17 +- (id)initWithObject:(NXObject *)object {
    2.18 +
    2.19 +    UILabel *titleLabel = nil;
    2.20 +    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(30, 3, 240, 18)] autorelease];
    2.21 +    titleLabel.tag = 1;
    2.22 +    titleLabel.font = [UIFont boldSystemFontOfSize:14];
    2.23 +    titleLabel.text = object.title;
    2.24 +    [self.contentView addSubview:titleLabel];
    2.25 +
    2.26 +    UILabel *infoLabel = nil;
    2.27 +    infoLabel = [[[UILabel alloc] initWithFrame:CGRectMake(30, 18, 240, 30)] autorelease];
    2.28 +    infoLabel.tag = 2;
    2.29 +    infoLabel.font = [UIFont systemFontOfSize:11];
    2.30 +    if ([object isFolder]) {
    2.31 +        infoLabel.text = @"Which info should we put here?";
    2.32 +    } else {
    2.33 +        //infoLabel.text = @"Updated xxx | Size: zzz";
    2.34 +        NSString *mimeType = (NSString *)[object getProperty:@"cmis:contentStreamMimeType"];
    2.35 +        NSNumber *size = (NSNumber *)[object getProperty:@"cmis:contentStreamLength"];
    2.36 +        infoLabel.text = [NSString stringWithFormat:@"Size: %@ | Mime-Type: %@",
    2.37 +                          size, mimeType];
    2.38 +    }
    2.39 +    [self.contentView addSubview:infoLabel];
    2.40 +
    2.41 +    NSString *imageName;
    2.42 +    if ([object isFolder]) {
    2.43 +        imageName = @"folder.png";
    2.44 +    } else {
    2.45 +        NSString *mimeType = (NSString*)[object getProperty:@"cmis:contentStreamMimeType"];
    2.46 +        NSLog(@"MimeType = %@", mimeType);
    2.47 +        if ([mimeType isEqualToString:@"application/pdf"]) {            
    2.48 +            imageName = @"page_white_acrobat.png";
    2.49 +        } else if ([mimeType hasPrefix:@"image/"]) {            
    2.50 +            imageName = @"camera.png";
    2.51 +        } else if ([mimeType hasPrefix:@"video/"]) {            
    2.52 +            imageName = @"film.png";
    2.53 +        } else if ([mimeType isEqualToString:@"text/html"]) {            
    2.54 +            imageName = @"html.png";
    2.55 +        } else if ([mimeType isEqualToString:@"application/vnd.ms-powerpoint"]
    2.56 +                   || [mimeType hasPrefix:@"application/vnd.ms-word"]
    2.57 +                   || [mimeType isEqualToString:@"application/vnd.ms-excel"]
    2.58 +                   || [mimeType isEqualToString:@"application/msword"]
    2.59 +                   || [mimeType isEqualToString:@"application/vnd.ms-office"]) {            
    2.60 +            imageName = @"page_white_office.png";
    2.61 +        } else {
    2.62 +            imageName = @"page_white_text.png";
    2.63 +        }
    2.64 +    }
    2.65 +    UIImageView *iconView;
    2.66 +    iconView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]] autorelease];
    2.67 +    CGRect imageFrame = iconView.frame;
    2.68 +    imageFrame.origin = CGPointMake(5, 15);
    2.69 +    iconView.frame = imageFrame;
    2.70 +    iconView.tag = 3;
    2.71 +    iconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    2.72 +    [self.contentView addSubview:iconView];
    2.73 +    
    2.74 +    return self;
    2.75 +}
    2.76 +
    2.77 +@end
     3.1 --- a/Classes/FolderViewController.m
     3.2 +++ b/Classes/FolderViewController.m
     3.3 @@ -10,6 +10,7 @@
     3.4  #import "DocViewController.h"
     3.5  #import "iNuxeoAppDelegate.h"
     3.6  #import "CmisClient.h"
     3.7 +#import "FolderViewCell.h"
     3.8  
     3.9  @implementation FolderViewController
    3.10  
    3.11 @@ -52,68 +53,15 @@
    3.12  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    3.13      static NSString *CellIdentifier = @"Cell";
    3.14      
    3.15 -    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    3.16 +    NXObject *object = [self.folder.children objectAtIndex:indexPath.row];
    3.17 +    
    3.18 +    FolderViewCell *cell = (FolderViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    3.19      if (cell == nil) {
    3.20 -        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    3.21 +        cell = [[[FolderViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    3.22      }
    3.23      
    3.24 -    NXObject *object = [self.folder.children objectAtIndex:indexPath.row];
    3.25 -
    3.26 -    UILabel *titleLabel = nil;
    3.27 -    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(30, 3, 240, 18)] autorelease];
    3.28 -    titleLabel.tag = 1;
    3.29 -    titleLabel.font = [UIFont boldSystemFontOfSize:14];
    3.30 -    titleLabel.text = object.title;
    3.31 -    [cell.contentView addSubview:titleLabel];
    3.32 -    
    3.33 -    UILabel *infoLabel = nil;
    3.34 -    infoLabel = [[[UILabel alloc] initWithFrame:CGRectMake(30, 18, 240, 30)] autorelease];
    3.35 -    infoLabel.tag = 2;
    3.36 -    infoLabel.font = [UIFont systemFontOfSize:11];
    3.37 -    if ([object isFolder]) {
    3.38 -        infoLabel.text = @"Which info should we put here?";
    3.39 -    } else {
    3.40 -        //infoLabel.text = @"Updated xxx | Size: zzz";
    3.41 -        NSString *mimeType = (NSString *)[object getProperty:@"cmis:contentStreamMimeType"];
    3.42 -        NSNumber *size = (NSNumber *)[object getProperty:@"cmis:contentStreamLength"];
    3.43 -        infoLabel.text = [NSString stringWithFormat:@"Size: %@ | Mime-Type: %@",
    3.44 -                          size, mimeType];
    3.45 -    }
    3.46 -    [cell.contentView addSubview:infoLabel];
    3.47 -    
    3.48 -    NSString *imageName;
    3.49 -    if ([object isFolder]) {
    3.50 -        imageName = @"folder.png";
    3.51 -    } else {
    3.52 -        NSString *mimeType = (NSString*)[object getProperty:@"cmis:contentStreamMimeType"];
    3.53 -        NSLog(@"MimeType = %@", mimeType);
    3.54 -        if ([mimeType isEqualToString:@"application/pdf"]) {            
    3.55 -            imageName = @"page_white_acrobat.png";
    3.56 -        } else if ([mimeType hasPrefix:@"image/"]) {            
    3.57 -            imageName = @"camera.png";
    3.58 -        } else if ([mimeType hasPrefix:@"video/"]) {            
    3.59 -            imageName = @"film.png";
    3.60 -        } else if ([mimeType isEqualToString:@"text/html"]) {            
    3.61 -            imageName = @"html.png";
    3.62 -        } else if ([mimeType isEqualToString:@"application/vnd.ms-powerpoint"]
    3.63 -                   || [mimeType hasPrefix:@"application/vnd.ms-word"]
    3.64 -                   || [mimeType isEqualToString:@"application/vnd.ms-excel"]
    3.65 -                   || [mimeType isEqualToString:@"application/msword"]
    3.66 -                   || [mimeType isEqualToString:@"application/vnd.ms-office"]) {            
    3.67 -            imageName = @"page_white_office.png";
    3.68 -        } else {
    3.69 -            imageName = @"page_white_text.png";
    3.70 -        }
    3.71 -    }
    3.72 -    UIImageView *iconView;
    3.73 -    iconView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]] autorelease];
    3.74 -    CGRect imageFrame = iconView.frame;
    3.75 -    imageFrame.origin = CGPointMake(5, 15);
    3.76 -    iconView.frame = imageFrame;
    3.77 -    iconView.tag = 3;
    3.78 -    iconView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    3.79 -    [cell.contentView addSubview:iconView];
    3.80 -    
    3.81 +    [cell initWithObject:object];
    3.82 +        
    3.83      return cell;
    3.84  }
    3.85  
     4.1 --- a/iNuxeo.xcodeproj/project.pbxproj
     4.2 +++ b/iNuxeo.xcodeproj/project.pbxproj
     4.3 @@ -45,6 +45,8 @@
     4.4  		781530D2113FFB7F0021E3DA /* SettingsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 781530C7113FFB7F0021E3DA /* SettingsView.xib */; };
     4.5  		781530D3113FFB7F0021E3DA /* DocViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 781530C8113FFB7F0021E3DA /* DocViewController.m */; };
     4.6  		781530D5113FFB7F0021E3DA /* DocView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 781530CB113FFB7F0021E3DA /* DocView.xib */; };
     4.7 +		782A7329114561B1009C4CC0 /* FolderViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 782A7328114561B1009C4CC0 /* FolderViewCell.m */; };
     4.8 +		782A732A114561B1009C4CC0 /* FolderViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 782A7328114561B1009C4CC0 /* FolderViewCell.m */; };
     4.9  		783C790C10CE49960049EA9D /* CmisClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 783C790B10CE49960049EA9D /* CmisClient.m */; };
    4.10  		783EC6E0113FFF27007F8A72 /* FolderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 783EC6DF113FFF27007F8A72 /* FolderView.xib */; };
    4.11  		783EC6E1113FFF27007F8A72 /* FolderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 783EC6DF113FFF27007F8A72 /* FolderView.xib */; };
    4.12 @@ -124,6 +126,8 @@
    4.13  		781530C8113FFB7F0021E3DA /* DocViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DocViewController.m; sourceTree = "<group>"; };
    4.14  		781530C9113FFB7F0021E3DA /* DocViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocViewController.h; sourceTree = "<group>"; };
    4.15  		781530CB113FFB7F0021E3DA /* DocView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DocView.xib; sourceTree = "<group>"; };
    4.16 +		782A7327114561B1009C4CC0 /* FolderViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FolderViewCell.h; sourceTree = "<group>"; };
    4.17 +		782A7328114561B1009C4CC0 /* FolderViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FolderViewCell.m; sourceTree = "<group>"; };
    4.18  		783C790A10CE49960049EA9D /* CmisClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CmisClient.h; path = Classes/CmisClient.h; sourceTree = "<group>"; };
    4.19  		783C790B10CE49960049EA9D /* CmisClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CmisClient.m; path = Classes/CmisClient.m; sourceTree = "<group>"; };
    4.20  		783EC6DF113FFF27007F8A72 /* FolderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FolderView.xib; sourceTree = "<group>"; };
    4.21 @@ -195,6 +199,8 @@
    4.22  				783EC6DF113FFF27007F8A72 /* FolderView.xib */,
    4.23  				28C286DF0D94DF7D0034E888 /* FolderViewController.h */,
    4.24  				28C286E00D94DF7D0034E888 /* FolderViewController.m */,
    4.25 +				782A7327114561B1009C4CC0 /* FolderViewCell.h */,
    4.26 +				782A7328114561B1009C4CC0 /* FolderViewCell.m */,
    4.27  				781530C6113FFB7F0021E3DA /* SearchView.xib */,
    4.28  				786BC084113C3CEE0091B621 /* SearchViewController.h */,
    4.29  				786BC085113C3CEE0091B621 /* SearchViewController.m */,
    4.30 @@ -519,6 +525,7 @@
    4.31  				786BC089113C3CEE0091B621 /* SearchViewController.m in Sources */,
    4.32  				78152FB4113ECD2B0021E3DA /* SettingsViewController.m in Sources */,
    4.33  				781530CE113FFB7F0021E3DA /* DocViewController.m in Sources */,
    4.34 +				782A7329114561B1009C4CC0 /* FolderViewCell.m in Sources */,
    4.35  			);
    4.36  			runOnlyForDeploymentPostprocessing = 0;
    4.37  		};
    4.38 @@ -541,6 +548,7 @@
    4.39  				781530D3113FFB7F0021E3DA /* DocViewController.m in Sources */,
    4.40  				781003DA113FFBF400BC45D9 /* CmisTestCase.m in Sources */,
    4.41  				783EC6FC1140031D007F8A72 /* RestApiTestCase.m in Sources */,
    4.42 +				782A732A114561B1009C4CC0 /* FolderViewCell.m in Sources */,
    4.43  			);
    4.44  			runOnlyForDeploymentPostprocessing = 0;
    4.45  		};