Permalink
Browse files

Initial checkin

  • Loading branch information...
0 parents commit 4d063064293830f172154256e35b269effbb8169 @clawoo committed Feb 9, 2011
Showing with 4,651 additions and 0 deletions.
  1. +21 −0 Classes/RCLAppDelegate.h
  2. +90 −0 Classes/RCLAppDelegate.m
  3. +32 −0 Classes/RCLAsyncDownloader.h
  4. +77 −0 Classes/RCLAsyncDownloader.m
  5. +16 −0 Classes/RCLAsyncImageView.h
  6. +14 −0 Classes/RCLAsyncImageView.m
  7. +31 −0 Classes/RCLCache.h
  8. +48 −0 Classes/RCLCache.m
  9. +21 −0 Classes/RCLString.h
  10. +24 −0 Classes/RCLString.m
  11. +14 −0 Classes/RootViewController.h
  12. +165 −0 Classes/RootViewController.m
  13. +542 −0 MainWindow.xib
  14. +30 −0 RCL-Info.plist
  15. +1,383 −0 RCL.xcodeproj/clw.mode1v3
  16. +641 −0 RCL.xcodeproj/clw.pbxuser
  17. +290 −0 RCL.xcodeproj/project.pbxproj
  18. +14 −0 RCL_Prefix.pch
  19. +384 −0 RootViewController.xib
  20. +18 −0 build/Debug-iphonesimulator/RCL.app.dSYM/Contents/Info.plist
  21. BIN build/Debug-iphonesimulator/RCL.app.dSYM/Contents/Resources/DWARF/RCL
  22. BIN build/Debug-iphonesimulator/RCL.app/Info.plist
  23. BIN build/Debug-iphonesimulator/RCL.app/MainWindow.nib
  24. +1 −0 build/Debug-iphonesimulator/RCL.app/PkgInfo
  25. BIN build/Debug-iphonesimulator/RCL.app/RCL
  26. BIN build/Debug-iphonesimulator/RCL.app/RootViewController.nib
  27. +7 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCL.LinkFileList
  28. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAppDelegate.o
  29. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAsyncDownloader.o
  30. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAsyncDownloader.o~$
  31. +5 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAsyncDownloader.o~>
  32. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAsyncDownloader.o~?
  33. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLAsyncImageView.o
  34. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLCache.o
  35. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLString.o
  36. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLString.o~$
  37. 0 build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RCLString.o~>
  38. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/RootViewController.o
  39. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/Objects-normal/i386/main.o
  40. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/RCL-all-target-headers.hmap
  41. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/RCL-generated-files.hmap
  42. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/RCL-own-target-headers.hmap
  43. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/RCL-project-headers.hmap
  44. +15 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/RCL.dep
  45. BIN build/RCL.build/Debug-iphonesimulator/RCL.build/RCL.hmap
  46. +14 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/RCL~.dep
  47. +396 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/build-state.dat
  48. +341 −0 build/RCL.build/Debug-iphonesimulator/RCL.build/build-state~.dat
  49. BIN build/RCL.build/RCL.pbxindex/categories.pbxbtree
  50. BIN build/RCL.build/RCL.pbxindex/cdecls.pbxbtree
  51. BIN build/RCL.build/RCL.pbxindex/decls.pbxbtree
  52. BIN build/RCL.build/RCL.pbxindex/files.pbxbtree
  53. BIN build/RCL.build/RCL.pbxindex/imports.pbxbtree
  54. BIN build/RCL.build/RCL.pbxindex/pbxindex.header
  55. BIN build/RCL.build/RCL.pbxindex/protocols.pbxbtree
  56. BIN build/RCL.build/RCL.pbxindex/refs.pbxbtree
  57. BIN build/RCL.build/RCL.pbxindex/strings.pbxstrings/control
  58. BIN build/RCL.build/RCL.pbxindex/strings.pbxstrings/strings
  59. BIN build/RCL.build/RCL.pbxindex/subclasses.pbxbtree
  60. BIN build/RCL.build/RCL.pbxindex/symbols0.pbxsymbols
  61. +17 −0 main.m
@@ -0,0 +1,21 @@
+//
+// RCLAppDelegate.h
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright __MyCompanyName__ 2011. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface RCLAppDelegate : NSObject <UIApplicationDelegate> {
+
+ UIWindow *window;
+ UINavigationController *navigationController;
+}
+
+@property (nonatomic, retain) IBOutlet UIWindow *window;
+@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
+
+@end
+
@@ -0,0 +1,90 @@
+//
+// RCLAppDelegate.m
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright __MyCompanyName__ 2011. All rights reserved.
+//
+
+#import "RCLAppDelegate.h"
+#import "RootViewController.h"
+
+
+@implementation RCLAppDelegate
+
+@synthesize window;
+@synthesize navigationController;
+
+
+#pragma mark -
+#pragma mark Application lifecycle
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+
+ // Override point for customization after application launch.
+
+ // Add the navigation controller's view to the window and display.
+ [window addSubview:navigationController.view];
+ [window makeKeyAndVisible];
+
+ return YES;
+}
+
+
+- (void)applicationWillResignActive:(UIApplication *)application {
+ /*
+ Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
+ Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ */
+}
+
+
+- (void)applicationDidEnterBackground:(UIApplication *)application {
+ /*
+ Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
+ If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
+ */
+}
+
+
+- (void)applicationWillEnterForeground:(UIApplication *)application {
+ /*
+ Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
+ */
+}
+
+
+- (void)applicationDidBecomeActive:(UIApplication *)application {
+ /*
+ Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
+ */
+}
+
+
+- (void)applicationWillTerminate:(UIApplication *)application {
+ /*
+ Called when the application is about to terminate.
+ See also applicationDidEnterBackground:.
+ */
+}
+
+
+#pragma mark -
+#pragma mark Memory management
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
+ /*
+ Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
+ */
+}
+
+
+- (void)dealloc {
+ [navigationController release];
+ [window release];
+ [super dealloc];
+}
+
+
+@end
+
@@ -0,0 +1,32 @@
+//
+// RCLAsyncDownloader.h
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#define RCL_MAX_CONCURRENT_DOWNLOADS 10
+
+@class RCLAsyncDownloader;
+@protocol RCLAsyncDownloaderDelegate
+
+- (void)downloader:(RCLAsyncDownloader *) didDownloadData:(NSData *)data;
+- (void)downloader:(RCLAsyncDownloader *) didUpdateProgress:(float)progress;
+@end
+
+
+@interface RCLAsyncDownloader : NSObject {
+ NSOperationQueue *queue_;
+ BOOL terminate_;
+}
+
+@property (nonatomic, retain) NSOperationQueue *queue;
+@property (nonatomic) BOOL terminate;
+
++ (RCLAsyncDownloader *)instance;
+- (void)downloadURL:(NSURL *)url withDelegate:(id<RCLAsyncDownloaderDelegate>)delegate;
+- (void)terminateInstance;
+@end
@@ -0,0 +1,77 @@
+//
+// RCLAsyncDownloader.m
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "RCLAsyncDownloader.h"
+
+@interface RCLDownloadOperation : NSOperation
+{
+ id<RCLAsyncDownloaderDelegate> delegate_;
+ NSURL *url_;
+ NSData *downloadedData_;
+}
+
+@property (nonatomic, assign) id<RCLAsyncDownloaderDelegate> delegate;
+@property (nonatomic, retain) NSURL *url;
+@end
+
+@implementation RCLDownloadOperation
+@synthesize url = url_;
+
+- (void)start {
+ downloadedData_ = [[NSMutableData alloc] init];
+ NSURLRequest *request = [[[NSURLRequest alloc] initWithURL:url_] autorelease];
+ NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request
+ delegate:self
+ startImmediately:YES];
+}
+
+@end
+
+
+@implementation RCLAsyncDownloader
+@synthesize queue = queue_;
+@synthesize terminate = terminate_;
+
++ (RCLAsyncDownloader *)instance {
+ static RCLAsyncDownloader *sharedInstance;
+ if (!sharedInstance) {
+ sharedInstance = [[RCLAsyncDownloader alloc] init];
+ sharedInstance.queue = [[NSOperationQueue alloc] init];
+ sharedInstance.queue.maxConcurrentOperationCount = RCL_MAX_CONCURRENT_DOWNLOADS;
+ }
+ else if (sharedInstance.terminate) {
+ [sharedInstance release];
+ sharedInstance = nil;
+ }
+
+ return sharedInstance;
+}
+
+#pragma mark -
+#pragma mark Download
+- (void)downloadURL:(NSURL *)url withDelegate:(id<RCLAsyncDownloaderDelegate>)delegate {
+ RCLDownloadOperation *op = [[RCLDownloadOperation alloc] init];
+ op.delegate = delegate;
+ op.url = url;
+ [queue_ addOperation:op];
+}
+
+
+#pragma mark -
+#pragma Memory management
+- (void)terminateInstance {
+ terminate_ = YES;
+ [RCLAsyncDownloader instance];
+}
+
+- (void)dealloc {
+ self.queue = nil;
+ [super dealloc];
+}
+
+@end
@@ -0,0 +1,16 @@
+//
+// RCLAsyncImageView.h
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+
+@interface RCLAsyncImageView : NSObject {
+
+}
+
+@end
@@ -0,0 +1,14 @@
+//
+// RCLAsyncImageView.m
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "RCLAsyncImageView.h"
+
+
+@implementation RCLAsyncImageView
+
+@end
@@ -0,0 +1,31 @@
+//
+// RCLCache.h
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+#define RCL_DOCUMENTS_DIRECTORY [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
+#define RCL_CACHE_DIRECTORY [RCL_DOCUMENTS_DIRECTORY stringByAppendingPathComponent:@"RCLCache"]
+#define RCL_USE_CACHE 1
+
+/*!
+ RCLCache is a generic cache manager.
+
+ Normally you will call the cache manager as a singleton
+ using the instance() method.
+ */
+@interface RCLCache : NSObject {
+}
+
+//! Shared instance, the preferred way of using the cache manager
++ (RCLCache *)instance;
+
+- (void)storeData:(NSData *)object forKeyPath:(NSString *)keyPath;
+- (BOOL)objectAvailableForKeyPath:(NSString *)keyPath;
+- (NSData *)objectForKeyPath:(NSString *)keyPath;
+
+@end
@@ -0,0 +1,48 @@
+//
+// RCLCache.m
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "RCLCache.h"
+#import "RCLString.h"
+
+@implementation RCLCache
+
++ (RCLCache *)instance {
+ static RCLCache *sharedInstance;
+ if (!sharedInstance) {
+ sharedInstance = [[RCLCache alloc] init];
+ }
+ return sharedInstance;
+}
+
+- (void)storeData:(NSData *)object forKeyPath:(NSString *)keyPath {
+ NSAssert(keyPath != nil, @"keyPath must not be nil");
+ NSAssert([keyPath length] != 0, @"keyPath must not be empty");
+ NSString *filePath = [RCL_CACHE_DIRECTORY stringByAppendingPathComponent:[keyPath md5]];
+ [object writeToFile:filePath atomically:YES];
+}
+
+- (BOOL)objectAvailableForKeyPath:(NSString *)keyPath {
+ NSString *filePath = [RCL_CACHE_DIRECTORY stringByAppendingPathComponent:[keyPath md5]];
+ if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+ return NO;
+ }
+ return YES;
+}
+
+- (NSData *)objectForKeyPath:(NSString *)keyPath {
+ NSAssert(keyPath != nil, @"keyPath must not be nil");
+ NSAssert([keyPath length] != 0, @"keyPath must not be empty");
+
+ NSString *filePath = [RCL_CACHE_DIRECTORY stringByAppendingPathComponent:[keyPath md5]];
+ if ([self objectAvailableForKeyPath:keyPath]) {
+ return [NSData dataWithContentsOfFile:filePath];
+ }
+ return nil;
+}
+
+@end
@@ -0,0 +1,21 @@
+//
+// RCLString.h
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <CommonCrypto/CommonDigest.h>
+
+//! NSString category
+/*!
+ A collection of useful methods that extend NSString functionality
+ */
+@interface NSString (RCLString)
+
+//! Computes the MD5 hash of an NSString
+- (NSString *)md5;
+
+@end
@@ -0,0 +1,24 @@
+//
+// RCLString.m
+// RCL
+//
+// Created by clw on 2/9/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "RCLString.h"
+
+@implementation NSString (RCLString)
+
+- (NSString *)md5 {
+ const char *cStr = [self UTF8String];
+ unsigned char result[CC_MD5_DIGEST_LENGTH];
+ CC_MD5(cStr, strlen(cStr), result);
+ NSMutableString *hash = [NSMutableString string];
+ for (int i = 0; i < 16; i++) {
+ [hash appendFormat:@"%02X", result[i]];
+ }
+ return [hash lowercaseString];
+}
+
+@end
Oops, something went wrong.

0 comments on commit 4d06306

Please sign in to comment.