Skip to content

Commit

Permalink
Users can now refresh briefs in the app manually by clicking the refr…
Browse files Browse the repository at this point in the history
…esh icon in the preview.
  • Loading branch information
capttaco committed Apr 11, 2010
1 parent 06d2971 commit 605abfe
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 30 deletions.
8 changes: 8 additions & 0 deletions Briefs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
D4D4BB2C11710AAA009D70D0 /* BFRemoteBriefSaver.xib in Resources */ = {isa = PBXBuildFile; fileRef = D4D4BB2A11710AAA009D70D0 /* BFRemoteBriefSaver.xib */; };
D4D4BB3011710E52009D70D0 /* confirm-action.png in Resources */ = {isa = PBXBuildFile; fileRef = D4D4BB2E11710E52009D70D0 /* confirm-action.png */; };
D4D4BB3111710E52009D70D0 /* confirm-cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = D4D4BB2F11710E52009D70D0 /* confirm-cancel.png */; };
D4D4BC371172552B009D70D0 /* preview-refresh-bg.png in Resources */ = {isa = PBXBuildFile; fileRef = D4D4BC361172552B009D70D0 /* preview-refresh-bg.png */; };
D4D4BC39117255A2009D70D0 /* PreviewRefreshLoad.xib in Resources */ = {isa = PBXBuildFile; fileRef = D4D4BC38117255A2009D70D0 /* PreviewRefreshLoad.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -339,6 +341,8 @@
D4D4BB2A11710AAA009D70D0 /* BFRemoteBriefSaver.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = BFRemoteBriefSaver.xib; path = Classes/BFRemoteBriefSaver.xib; sourceTree = "<group>"; };
D4D4BB2E11710E52009D70D0 /* confirm-action.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "confirm-action.png"; path = "images/buttons/confirm-action.png"; sourceTree = "<group>"; };
D4D4BB2F11710E52009D70D0 /* confirm-cancel.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "confirm-cancel.png"; path = "images/buttons/confirm-cancel.png"; sourceTree = "<group>"; };
D4D4BC361172552B009D70D0 /* preview-refresh-bg.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "preview-refresh-bg.png"; path = "images/bg/preview-refresh-bg.png"; sourceTree = "<group>"; };
D4D4BC38117255A2009D70D0 /* PreviewRefreshLoad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PreviewRefreshLoad.xib; path = Classes/PreviewRefreshLoad.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -535,6 +539,7 @@
D43CE16C114F0DC800DA07D5 /* backgrounds */ = {
isa = PBXGroup;
children = (
D4D4BC361172552B009D70D0 /* preview-refresh-bg.png */,
D4D4B7CA11700D74009D70D0 /* pop-up-bgfull.png */,
D4A0C31E116D81420088E5F6 /* pop-slider-bg-filled.png */,
D4A0C268116AF9610088E5F6 /* pop-up-320bg.png */,
Expand Down Expand Up @@ -720,6 +725,7 @@
D4A0C34F116D91930088E5F6 /* loading views */ = {
isa = PBXGroup;
children = (
D4D4BC38117255A2009D70D0 /* PreviewRefreshLoad.xib */,
D4A0C33D116D84360088E5F6 /* FullPageRemoteLoad.xib */,
D4A0C261116AD85C0088E5F6 /* BFLoadingViewController.xib */,
);
Expand Down Expand Up @@ -969,6 +975,8 @@
D4D4BB2C11710AAA009D70D0 /* BFRemoteBriefSaver.xib in Resources */,
D4D4BB3011710E52009D70D0 /* confirm-action.png in Resources */,
D4D4BB3111710E52009D70D0 /* confirm-cancel.png in Resources */,
D4D4BC371172552B009D70D0 /* preview-refresh-bg.png in Resources */,
D4D4BC39117255A2009D70D0 /* PreviewRefreshLoad.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions Classes/BFBriefInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@

- (id)initWithDictionary:(NSDictionary *)dictionary atPath:(NSString *)path;
- (BriefRef *)insertIntoManagedContext:(NSManagedObjectContext *)context;
- (BriefRef *)mergeInfoIntoBrief:(BriefRef *)ref;

@end
5 changes: 5 additions & 0 deletions Classes/BFBriefInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ - (BriefRef *)insertIntoManagedContext:(NSManagedObjectContext *)context
{
BriefRef *ref = (BriefRef *) [NSEntityDescription insertNewObjectForEntityForName:@"BriefRef" inManagedObjectContext:context];

return [self mergeInfoIntoBrief:ref];
}

- (BriefRef *)mergeInfoIntoBrief:(BriefRef *)ref
{
[ref setFilePath:pathToBrieflist];
[ref setTitle:title];
[ref setTotalNumberOfScenes:[NSNumber numberWithInt:numberOfScenes]];
Expand Down
1 change: 1 addition & 0 deletions Classes/BFDataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef enum {

// Add & Remove Data API
- (BriefRef *)addBriefAtPath:(NSString *)path usingData:(NSData *)data fromURL:(NSString *)url;
- (BriefRef *)updateBrief:(BriefRef *)brief usingData:(NSData *)data;
- (void)addBriefcastInformation:(BFBriefcast *)briefcast;

- (void)removeBrief:(BriefRef *)brief;
Expand Down
24 changes: 19 additions & 5 deletions Classes/BFDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "BFBriefCellController.h"
#import "BFBriefcastCellController.h"
#import "BFBriefcast+CoreDataAdditions.h"
#import "NSDictionary+BFAdditions.h"
#import "BFBriefInfo.h"
#import "BFArrayBriefDataSource.h"

Expand Down Expand Up @@ -238,10 +239,11 @@ - (BriefRef *)addBriefAtPath:(NSString *)path usingData:(NSData *)data fromURL:(

// else, get the reference and update it's download date
else {
[brief setDateLastDownloaded:[NSDate date]];
[data writeToFile:destination atomically:YES];

return brief;
// [brief setDateLastDownloaded:[NSDate date]];
// [data writeToFile:destination atomically:YES];
//
// return brief;
return [self updateBrief:brief usingData:data];
}
}

Expand All @@ -268,7 +270,19 @@ - (BriefRef *)addBriefAtPath:(NSString *)path fromURL:(NSString *)url

return newRef;
}

- (BriefRef *)updateBrief:(BriefRef *)brief usingData:(NSData *)data
{
// update the brief meta data
BFBriefInfo *info = [BFBriefInfo infoForBriefData:[NSDictionary dictionaryFromData:data] atPath:brief.filePath];
brief = [info mergeInfoIntoBrief:brief];
[brief setDateLastDownloaded:[NSDate date]];
[self save];

// write the new file
[data writeToFile:brief.filePath atomically:YES];

return brief;
}

///////////////////////////////////////////////////////////////////////////////
#pragma mark -
Expand Down
13 changes: 2 additions & 11 deletions Classes/BFPreviewBriefViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@
#import "BFBriefDataSource.h"
#import "BriefRef.h"
#import "BFBriefViewDelegate.h"
#import "BFLoadingViewController.h"

// Adapted from code seen on http://cocoawithlove.com/2009/01/multiple-virtual-pages-in-uiscrollview.html
//
// The following copyright, accompanied the code:
// Copyright 2009 Matt Gallagher. All rights reserved.
//
// Permission is given to use this source code file, free of charge, in any
// project, commercial or otherwise, entirely at your risk, with the condition
// that any redistribution (in part or whole) of source code must retain
// this copyright and permission notice. Attribution in compiled projects is
// appreciated but not required.

@interface BFPreviewBriefViewController : UIViewController <BFBriefViewDelegate, UIActionSheetDelegate>
@interface BFPreviewBriefViewController : UIViewController <BFBriefViewDelegate, UIActionSheetDelegate, BFLoadingViewDelegate>
{
IBOutlet BFPreviewBriefView *previewView;
IBOutlet BFBriefInfoView *infoView;
Expand Down
73 changes: 59 additions & 14 deletions Classes/BFPreviewBriefViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ - (void)viewDidLoad
[self.view addSubview:previewView];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc
{
Expand Down Expand Up @@ -251,10 +237,69 @@ - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger
}
}



///////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark BFLoadingViewDelegate Methods

- (void)shouldReloadBrief
{
// setup the loading controller
NSString *location = briefBeingPreviewed.fromURL;
BFLoadingViewController *loadingController = [[BFLoadingViewController alloc] initWithNibName:@"PreviewRefreshLoad" bundle:nil];
loadingController.view.frame = CGRectOffset(loadingController.view.frame, 9.0f, 4.0f);

loadingController.view.alpha = 0.0;
[infoView addSubview:[loadingController view]];
[UIView beginAnimations:@"fade-in refresh view" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration:0.5f];
loadingController.view.alpha = 1.0f;
[UIView commitAnimations];

[loadingController setDelegate:self];
[loadingController load:location withStatus:@"Changing underwear..."];
}

- (void)loadingFadeDidStop:(NSString *)animationId finished:(NSNumber *)finished context:(void *)context
{
BFLoadingViewController *controller = context;
[[controller view] removeFromSuperview];
}

- (void)beginLoadingFadeOutAnimation:(id)loading
{
BFLoadingViewController *controller = loading;
[UIView beginAnimations:@"fade-out refresh view" context:controller];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(loadingFadeDidStop:finished:context:)];
controller.view.alpha = 0.0f;
[UIView commitAnimations];
}

- (void)loadingView:(BFLoadingViewController *)controller didCompleteWithData:(NSData *)data
{
[self performSelector:@selector(beginLoadingFadeOutAnimation:) withObject:controller afterDelay:1.0f];

// refresh data, reload brief-info
briefBeingPreviewed = [[BFDataManager sharedBFDataManager] updateBrief:briefBeingPreviewed usingData:data];
[self prepareInfoView:briefBeingPreviewed];

}

- (void)loadingView:(BFLoadingViewController *)controller didNotCompleteWithError:(NSError *)error
{
// TODO: handle error
}

- (void)loadingView:(BFLoadingViewController *)controller didCancelConnection:(NSString *)url
{
// TODO: handle cancelation
}



@end
Loading

0 comments on commit 605abfe

Please sign in to comment.