From 29cc49574857f03af94b3df17bcbc9e96bca9393 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Thu, 31 May 2012 16:46:23 +0300 Subject: [PATCH] Show last modified date instead of content type in folder listing. Disable refresh button while deleting object. Update version. --- Classes/AddPhotoViewController.m | 2 + Classes/ComputeModel.h | 2 + Classes/ComputeModel.m | 55 ++++++--- Classes/FolderViewController.h | 2 + Classes/FolderViewController.m | 9 +- Classes/FolderViewController.xib | 172 +++++++++++++++++++++++++---- Classes/StorageObject.h | 4 + Classes/StorageObject.m | 20 +++- Classes/StorageObjectViewController.m | 4 +- Classes/UploadGenericFileViewController.m | 3 + OpenStack-Info.plist | 4 +- 11 files changed, 231 insertions(+), 46 deletions(-) diff --git a/Classes/AddPhotoViewController.m b/Classes/AddPhotoViewController.m index e774f91..2a1fe23 100755 --- a/Classes/AddPhotoViewController.m +++ b/Classes/AddPhotoViewController.m @@ -19,6 +19,7 @@ #import "FolderViewController.h" #import "NSObject+Conveniences.h" #import "APICallback.h" +#import "ComputeModel.h" #define kName 0 @@ -397,6 +398,7 @@ [activityIndicatorView removeFromSuperview]; object.data = nil; object.sharing = folder.sharing; + object.lastModified = [ComputeModel dateFromRFC1123String:[request.responseHeaders objectForKey:@"Date"]]; BOOL currentFolderIsRoot = NO; if ([folderViewController.folder isEqual:container.rootFolder]) { currentFolderIsRoot = YES; diff --git a/Classes/ComputeModel.h b/Classes/ComputeModel.h index 4c570bb..c42d0e8 100755 --- a/Classes/ComputeModel.h +++ b/Classes/ComputeModel.h @@ -24,6 +24,8 @@ - (NSDate *)dateForKey:(NSString *)key inDict:(NSDictionary *)dict; + (NSDate *)dateFromString:(NSString *)dateString; ++ (NSDate *)dateFromRFC1123String:(NSString *)dateString; ++ (NSString *)localDateDescriptionFromDate:(NSDate *)date; - (NSDate *)dateFromString:(NSString *)dateString; - (NSComparisonResult)compare:(ComputeModel *)aComputeModel; diff --git a/Classes/ComputeModel.m b/Classes/ComputeModel.m index 702e85e..1849785 100755 --- a/Classes/ComputeModel.m +++ b/Classes/ComputeModel.m @@ -59,24 +59,49 @@ #pragma mark - #pragma mark Date Parser -+ (NSDate *)dateFromString:(NSString *)dateString { - return nil; // temporarily removing date parsing for performance - - /* - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; - // example: 2009-11-04T19:46:20.192723 ++ (NSDate *)dateFromString:(NSString *)dateString { + // example: 2009-11-04T19:46:20.192723 // 2010-01-26T12:07:32-06:00 + NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary]; + NSDateFormatter *dateFormatter = [threadDict objectForKey:@"iso8601DateFormatter"]; + if (!dateFormatter) { + dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; + [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"]; + [threadDict setObject:dateFormatter forKey:@"iso8601DateFormatter"]; + [dateFormatter release]; + } + + return [dateFormatter dateFromString:[dateString stringByReplacingOccurrencesOfString:@":" + withString:@"" + options:NSBackwardsSearch + range:NSMakeRange(([dateString length] - 3), 1)]]; +} - // this is nasty, but -06:00 is not a valid timezone format. converting to -0600 style - dateString = [NSString stringWithFormat:@"%@%@", [dateString substringToIndex:22], [dateString substringFromIndex:23]]; - [dateFormatter setDateFormat:@"yyyy-MM-dd'T'H:mm:ssZ"]; ++ (NSDate *)dateFromRFC1123String:(NSString *)dateString { + NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary]; + NSDateFormatter *dateFormatter = [threadDict objectForKey:@"rfc1123DateFormatter"]; + if (!dateFormatter) { + dateFormatter = [[NSDateFormatter alloc] init]; + [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; + [dateFormatter setDateFormat:@"eee, dd MMM yyyy HH:mm:ss 'GMT'"]; + [threadDict setObject:dateFormatter forKey:@"rfc1123DateFormatter"]; + [dateFormatter release]; + } + return [dateFormatter dateFromString:dateString]; +} - NSDate *date = [dateFormatter dateFromString:dateString]; - [dateFormatter release]; - - return date; - */ ++ (NSString *)localDateDescriptionFromDate:(NSDate *)date { + NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary]; + NSDateFormatter *dateFormatterLocal = [threadDict objectForKey:@"dateFormatterLocal"]; + if (!dateFormatterLocal) { + dateFormatterLocal = [[NSDateFormatter alloc] init]; + [dateFormatterLocal setTimeZone:[NSTimeZone localTimeZone]]; + [dateFormatterLocal setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; + [threadDict setObject:dateFormatterLocal forKey:@"dateFormatterLocal"]; + [dateFormatterLocal release]; + } + return [dateFormatterLocal stringFromDate:date]; } - (NSDate *)dateFromString:(NSString *)dateString { diff --git a/Classes/FolderViewController.h b/Classes/FolderViewController.h index 08f596e..b6af52d 100755 --- a/Classes/FolderViewController.h +++ b/Classes/FolderViewController.h @@ -32,6 +32,7 @@ IBOutlet UITableView *tableView; IBOutlet UIBarButtonItem *homeButton; + IBOutlet UIBarButtonItem *refreshButton; FolderDetailViewController *folderDetailVC; StorageObjectViewController *selectedObjectViewController; } @@ -48,6 +49,7 @@ @property (nonatomic, assign) BOOL folderHasBeenRemoved; @property (nonatomic, assign) BOOL refreshWhenAppeared; @property (nonatomic, retain) IBOutlet UITableView *tableView; +@property (nonatomic, retain) IBOutlet UIBarButtonItem *refreshButton; @property (nonatomic, assign) FolderDetailViewController *folderDetailVC; @property (nonatomic, assign) StorageObjectViewController *selectedObjectViewController; diff --git a/Classes/FolderViewController.m b/Classes/FolderViewController.m index 241067c..3e4990b 100755 --- a/Classes/FolderViewController.m +++ b/Classes/FolderViewController.m @@ -28,11 +28,12 @@ #import "APICallback.h" #import "OpenStackAppDelegate.h" #import +#import "ComputeModel.h" @implementation FolderViewController -@synthesize account, container, folder, containersViewController, selectedContainerIndexPath, contentsLoaded, parentFolderViewController, selectedFolderIndexPath, tableView, needsRefreshing, folderHasBeenRemoved, refreshWhenAppeared, folderDetailVC, selectedObjectViewController; +@synthesize account, container, folder, containersViewController, selectedContainerIndexPath, contentsLoaded, parentFolderViewController, selectedFolderIndexPath, tableView, needsRefreshing, folderHasBeenRemoved, refreshWhenAppeared, folderDetailVC, selectedObjectViewController, refreshButton; - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); @@ -250,7 +251,10 @@ udic.UTI = (NSString *)uti; if ([udic.icons count] > 0) cell.imageView.image = [udic.icons objectAtIndex:0]; - cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", [item humanizedBytes], [item contentType]]; + if ([item lastModifiedString]) + cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@", [item humanizedBytes], [item lastModifiedString]]; + else + cell.detailTextLabel.text = [item humanizedBytes]; } return cell; @@ -466,6 +470,7 @@ [deleteActionSheet release]; [parentFolderViewController release]; [selectedFolderIndexPath release]; + [refreshButton release]; [super dealloc]; } diff --git a/Classes/FolderViewController.xib b/Classes/FolderViewController.xib index 8676cbe..b708b23 100755 --- a/Classes/FolderViewController.xib +++ b/Classes/FolderViewController.xib @@ -1,14 +1,14 @@ - 1056 - 10K549 - 1306 - 1038.36 - 461.00 + 1296 + 11E53 + 2182 + 1138.47 + 569.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 301 + 1181 YES @@ -23,11 +23,8 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -49,6 +46,7 @@ 266 {{0, 416}, {320, 44}} + NO NO IBCocoaTouchFramework @@ -72,6 +70,7 @@ 274 {320, 416} + 3 @@ -90,6 +89,7 @@ {320, 460} + 3 @@ -122,6 +122,22 @@ + tableView + + + + 27 + + + + refreshButton + + + + 28 + + + dataSource @@ -144,21 +160,15 @@ 26 - - - tableView - - - - 27 - YES 0 - + + YES + @@ -222,18 +232,26 @@ YES -1.CustomClassName + -1.IBPluginDependency -2.CustomClassName + -2.IBPluginDependency 10.IBPluginDependency 13.IBPluginDependency + 22.IBPluginDependency + 24.IBPluginDependency 9.IBPluginDependency - + YES FolderViewController + com.apple.InterfaceBuilder.IBCocoaTouchPlugin UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -248,17 +266,123 @@ - 27 + 28 + + + + YES + + FolderViewController + OpenStackViewController + + YES + + YES + homeButtonPressed: + refreshButtonPressed: + + + YES + id + id + + + + YES + + YES + homeButtonPressed: + refreshButtonPressed: + + + YES + + homeButtonPressed: + id + + + refreshButtonPressed: + id + + + + + YES + + YES + homeButton + refreshButton + tableView + + + YES + UIBarButtonItem + UIBarButtonItem + UITableView + + + + YES + + YES + homeButton + refreshButton + tableView + + + YES + + homeButton + UIBarButtonItem + + + refreshButton + UIBarButtonItem + + + tableView + UITableView + + + + + IBProjectSource + ./Classes/FolderViewController.h + + + + OpenStackViewController + UIViewController + + toolbar + UIToolbar + + + toolbar + + toolbar + UIToolbar + + + + IBProjectSource + ./Classes/OpenStackViewController.h + + + - 0 IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 YES 3 - 301 + 1181 diff --git a/Classes/StorageObject.h b/Classes/StorageObject.h index dd7caa0..af2405b 100755 --- a/Classes/StorageObject.h +++ b/Classes/StorageObject.h @@ -15,7 +15,9 @@ NSString *hash; NSUInteger bytes; NSString *contentType; + NSString *iso8601DateString; NSDate *lastModified; + NSString *lastModifiedString; NSData *data; NSString *publicURI; NSString *sharing; @@ -31,6 +33,8 @@ @property (nonatomic, retain) NSData *data; @property (nonatomic, retain) NSString *publicURI; @property (nonatomic, retain) NSString *sharing; +@property (nonatomic, retain) NSString *iso8601DateString; +@property (nonatomic, retain) NSString *lastModifiedString; @property (nonatomic, retain) NSMutableDictionary *metadata; - (NSString *)humanizedBytes; diff --git a/Classes/StorageObject.m b/Classes/StorageObject.m index e62ed73..296ba20 100755 --- a/Classes/StorageObject.m +++ b/Classes/StorageObject.m @@ -13,7 +13,7 @@ @implementation StorageObject -@synthesize name, fullPath, hash, bytes, contentType, lastModified, data, publicURI, sharing, metadata; +@synthesize name, fullPath, hash, bytes, contentType, lastModified, data, publicURI, sharing, metadata, iso8601DateString, lastModifiedString; #pragma mark - #pragma mark Serialization @@ -61,7 +61,8 @@ object.hash = [dict objectForKey:@"x_object_hash"]; object.bytes = [[dict objectForKey:@"bytes"] intValue]; object.contentType = [dict objectForKey:@"content_type"]; - object.lastModified = [ComputeModel dateFromString:[dict objectForKey:@"last_modified"]]; + //object.lastModified = [ComputeModel dateFromString:[dict objectForKey:@"last_modified"]]; + object.iso8601DateString = [dict objectForKey:@"last_modified"]; object.publicURI = [dict objectForKey:@"x_object_public"]; object.sharing = [dict objectForKey:@"x_object_sharing"]; object.metadata = nil; @@ -123,6 +124,19 @@ } #pragma mark - +#pragma mark Properties + +- (NSString *)lastModifiedString { + if (!lastModifiedString) { + if (!self.lastModified && [self.iso8601DateString length]) + self.lastModified = [ComputeModel dateFromString:self.iso8601DateString]; + if (self.lastModified) + lastModifiedString = [[ComputeModel localDateDescriptionFromDate:self.lastModified] retain]; + } + return lastModifiedString; +} + +#pragma mark - #pragma mark Memory Management -(void)dealloc { @@ -133,6 +147,8 @@ [lastModified release]; [data release]; [metadata release]; + [iso8601DateString release]; + [lastModifiedString release]; [super dealloc]; } diff --git a/Classes/StorageObjectViewController.m b/Classes/StorageObjectViewController.m index 4060936..1b9d0de 100755 --- a/Classes/StorageObjectViewController.m +++ b/Classes/StorageObjectViewController.m @@ -660,6 +660,7 @@ - (void)deleteObjectRow { [self.folder.objects removeObjectForKey:self.object.name]; [self.folderViewController.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:selectedIndexPath] withRowAnimation:UITableViewRowAnimationLeft]; + self.folderViewController.refreshButton.enabled = YES; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { @@ -672,7 +673,7 @@ activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:activityMessage] text:activityMessage]; [activityIndicatorView addToView:self.view]; - + self.folderViewController.refreshButton.enabled = NO; [[self.account.manager deleteObject:self.container object:self.object] success:^(OpenStackRequest *request) { [activityIndicatorView removeFromSuperview]; @@ -682,6 +683,7 @@ if (account.shared) self.folderViewController.needsRefreshing = YES; } else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + self.folderViewController.selectedObjectViewController = nil; if (!account.shared) [self.folderViewController setDetailViewController]; else diff --git a/Classes/UploadGenericFileViewController.m b/Classes/UploadGenericFileViewController.m index 62f1c5c..ccbd5cb 100755 --- a/Classes/UploadGenericFileViewController.m +++ b/Classes/UploadGenericFileViewController.m @@ -20,6 +20,7 @@ #import "RSTextFieldCell.h" #import "NSObject+Conveniences.h" #import "APICallback.h" +#import "ComputeModel.h" #define kName 0 #define kContentType 1 @@ -259,6 +260,8 @@ [activityIndicatorView removeFromSuperview]; object.data = nil; object.sharing = folder.sharing; + object.lastModified = [ComputeModel dateFromRFC1123String:[request.responseHeaders objectForKey:@"Date"]]; + BOOL currentFolderIsRoot = NO; if ([folderViewController.folder isEqual:container.rootFolder]) { currentFolderIsRoot = YES; diff --git a/OpenStack-Info.plist b/OpenStack-Info.plist index 34f592c..295f5aa 100755 --- a/OpenStack-Info.plist +++ b/OpenStack-Info.plist @@ -43,7 +43,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.4 + 1.0.5 CFBundleSignature ???? CFBundleURLTypes @@ -58,7 +58,7 @@ CFBundleVersion - 20120529.0 + 20120531.0 LSRequiresIPhoneOS NSMainNibFile -- 1.7.10.4