Share UIImage instance for memory reservation.
====
Icons:
+ Folder-*.png
+ TextDocument-*.png
By Photoshopedia
http://www.photoshopedia.com/
http://www.iconspedia.com/pack/xedia-2164/
All rights reserved Photoshopedia - http://www.photoshopedia.com/373
====
+Icons:
+ sub_blue_up-*.png
+ http://www.iconspedia.com/icon/sub-blue-up-14-07.html
+----------------------------------------------------
+Primo Icon Set by Webdesigner Depot
+http://www.webdesignerdepot.com
+----------------------------------------------------
+
+TERMS OF USE:
+
+This product may be used free of charge for personal or commercial purposes. Attribution is not necessary but will be appreciated.
+
+You may not modify, sell or distribute this file on any websites, CD-Roms or any other means, either electronically or other without written consent from Webdesigner Depot.
+
+If you'd like to share this file with others, please direct them to our website where they can download their copy.
+
+Thanks for supporting our website and enjoy!
+
+
+Webdesigner Depot
+
92DE33A015231CFC00AD06EC /* Folder-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339C15231CFC00AD06EC /* Folder-48.png */; };
92DE33A115231CFC00AD06EC /* TextDocument-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339D15231CFC00AD06EC /* TextDocument-32.png */; };
92DE33A215231CFC00AD06EC /* TextDocument-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE339E15231CFC00AD06EC /* TextDocument-48.png */; };
+ 92DE33B11524478E00AD06EC /* sub_blue_up-32.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */; };
+ 92DE33B21524478E00AD06EC /* sub_blue_up-48.png in Resources */ = {isa = PBXBuildFile; fileRef = 92DE33B01524478E00AD06EC /* sub_blue_up-48.png */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
92DE339C15231CFC00AD06EC /* Folder-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Folder-48.png"; sourceTree = "<group>"; };
92DE339D15231CFC00AD06EC /* TextDocument-32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TextDocument-32.png"; sourceTree = "<group>"; };
92DE339E15231CFC00AD06EC /* TextDocument-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TextDocument-48.png"; sourceTree = "<group>"; };
+ 92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sub_blue_up-32.png"; sourceTree = "<group>"; };
+ 92DE33B01524478E00AD06EC /* sub_blue_up-48.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sub_blue_up-48.png"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
92DE339C15231CFC00AD06EC /* Folder-48.png */,
92DE339D15231CFC00AD06EC /* TextDocument-32.png */,
92DE339E15231CFC00AD06EC /* TextDocument-48.png */,
+ 92DE33AF1524478E00AD06EC /* sub_blue_up-32.png */,
+ 92DE33B01524478E00AD06EC /* sub_blue_up-48.png */,
);
name = images;
sourceTree = "<group>";
92DE33A015231CFC00AD06EC /* Folder-48.png in Resources */,
92DE33A115231CFC00AD06EC /* TextDocument-32.png in Resources */,
92DE33A215231CFC00AD06EC /* TextDocument-48.png in Resources */,
+ 92DE33B11524478E00AD06EC /* sub_blue_up-32.png in Resources */,
+ 92DE33B21524478E00AD06EC /* sub_blue_up-48.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@property NSString *name;
@property NSString *path;
@property BOOL isDirectory;
+@property BOOL isUp;
-(NSString*)description;
@synthesize name;
@synthesize path;
@synthesize isDirectory;
+@synthesize isUp;
-(NSString*)description {
return name;
FileItem *fileItem = [FileItem alloc];
fileItem.name = name;
fileItem.isDirectory = NO;
+ fileItem.isUp = NO;
return fileItem;
}
@interface MasterViewController () {
NSMutableArray *_objects;
Storage *storage;
+
+ UIImage *imgFolder;
+ UIImage *imgDocument;
+ UIImage *imgUp;
}
@end
self.navigationItem.rightBarButtonItem = addButton;
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
+ imgFolder = nil;
+ imgDocument = nil;
if (!storage) {
storage = [Storage init];
}
// Load initial items.
- for (NSString *file in [storage listItems]) {
- [self insertItem: file];
- }
+ [self insertItems];
}
- (void)viewDidUnload
- (void)insertNewObject:(id)sender
{
- if (!_objects) {
- _objects = [[NSMutableArray alloc] init];
+ FileItem *item = [FileItem allocWithName: [[NSDate date] description]];
+ [self insertItem: item];
+}
+
+#pragma mark - Item operations
+
+- (void)insertItems {
+ for (FileItem *file in [storage listItems]) {
+ [self insertItem: file];
+ }
+ if (!storage.isTopDir) {
+ FileItem *up = [FileItem allocWithName:@"UP"];
+ up.isUp = YES;
+ [self insertItem: up];
}
- [_objects insertObject:[NSDate date] atIndex:0];
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
- [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
-- (void)insertItem:(NSString *)item {
+- (void)removeAllItems {
+ NSUInteger n = [_objects count];
+
+ NSMutableArray *rmItems = [[NSMutableArray alloc] initWithCapacity:n];
+ for (int i = 0; i < n; i++) {
+ NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
+ [rmItems addObject: indexPath];
+ }
+ [_objects removeAllObjects];
+ [self.tableView deleteRowsAtIndexPaths: rmItems withRowAnimation:UITableViewRowAnimationAutomatic];
+}
+
+- (void)insertItem:(FileItem *)item {
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
FileItem *fItem = [_objects objectAtIndex:indexPath.row];
cell.textLabel.text = [fItem name];
- if (fItem.isDirectory) {
- cell.imageView.image = [UIImage imageNamed:@"Folder-32"];
+ if (fItem.isUp) {
+ if (!imgUp) {
+ imgUp = [UIImage imageNamed:@"sub_blue_up-32"];
+ }
+ cell.imageView.image = imgUp;
+ } else if (fItem.isDirectory) {
+ if (!imgFolder) {
+ imgFolder = [UIImage imageNamed:@"Folder-32"];
+
+ }
+ cell.imageView.image = imgFolder;
} else {
- cell.imageView.image = [UIImage imageNamed:@"TextDocument-32"];
+ if (!imgDocument) {
+ imgDocument = [UIImage imageNamed:@"TextDocument-32"];
+ }
+ cell.imageView.image = imgDocument;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
- NSDate *object = [_objects objectAtIndex:indexPath.row];
- self.detailViewController.detailItem = object;
+ FileItem *item = [_objects objectAtIndex:indexPath.row];
+ if (item.isUp) {
+ // switch view items
+ [self removeAllItems];
+ [storage updir];
+ [self insertItems];
+ } else if (item.isDirectory) {
+ // switch view items
+ [self removeAllItems];
+ [storage chdir: item.name];
+ [self insertItems];
+
+ } else {
+ [self.detailViewController setDetailItem:item];
+ }
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
- NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
+ NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
FileItem *item = [_objects objectAtIndex:indexPath.row];
- if (item.isDirectory) {
+ if (item.isUp) {
+ CustomSegue *customSegue = (CustomSegue*)segue;
+ customSegue.isStop = YES;
+
+ // switch view items
+ [self removeAllItems];
+ [storage updir];
+ [self insertItems];
+ } else if (item.isDirectory) {
CustomSegue *customSegue = (CustomSegue*)segue;
customSegue.isStop = YES;
+
+ // switch view items
+ [self removeAllItems];
+ [storage chdir: item.name];
+ [self insertItems];
+
} else {
[[segue destinationViewController] setDetailItem:item];
}
+ (id)init;
+/*
+ * Enumerate current directory and return array of FileItem.
+ */
-(NSArray*)listItems;
+/*
+ * Change directory.
+ */
+-(void)chdir:(NSString *)subdir;
+
+-(void)updir;
+
+/*
+ * Is current directory Top?
+ */
+-(BOOL)isTopDir;
@end
return storage;
}
-/*
- * Enumerate current directory and return array of FileItem.
- */
-(NSArray*)listItems {
NSError *error = nil;
NSString *currentPath = [documentRoot stringByAppendingString: currentDirectory];
return result;
}
+-(void)chdir:(NSString *)subdir {
+ NSString *newCurrent = [currentDirectory stringByAppendingPathComponent:subdir];
+ self.currentDirectory = newCurrent;
+}
+
+-(void)updir {
+ NSString *parent = [currentDirectory stringByDeletingLastPathComponent];
+ if ([parent isEqualToString:@"/"]) {
+ self.currentDirectory = parent;
+ } else {
+ self.currentDirectory = [parent stringByAppendingString:@"/"];
+ }
+}
+
+-(BOOL)isTopDir {
+ return [currentDirectory isEqualToString:@"/"];
+}
@end