Skip to content

Commit

Permalink
Merge pull request #6 from deasmi/master
Browse files Browse the repository at this point in the history
Rotation bug fix and updated pull to refresh time/date label
  • Loading branch information
Samuel Sutch committed Feb 29, 2012
2 parents 13afbbd + 85b60ac commit 47e57df
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 9 deletions.
1 change: 1 addition & 0 deletions Readdit/Classes/RDBrowserController.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ - (void)setItem:(NSDictionary *)i
webView.delegate = self;
webView.scalesPageToFit = YES;
webView.dataDetectorTypes = UIDataDetectorTypeLink | UIDataDetectorTypePhoneNumber;
[webView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight)];
backItem.target = forwardItem.target = refreshItem.target = webView;
backItem.action = @selector(goBack);
forwardItem.action = @selector(goForward);
Expand Down
2 changes: 1 addition & 1 deletion Readdit/Lib/YMRefreshView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- (void)flipImageAnimated:(BOOL)animated;
- (void)toggleActivityView:(BOOL)isON;
- (void)setStatus:(int)status;

- (void)setUpdateLabel;
@property BOOL isFlipped;

@end
Expand Down
22 changes: 14 additions & 8 deletions Readdit/Lib/YMRefreshView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import "YMRefreshView.h"
#import <QuartzCore/QuartzCore.h>

#import "ZelNSDateFormatter+Extras.h"

#define kReleaseToReloadStatus 0
#define kPullToReloadStatus 1
Expand Down Expand Up @@ -115,13 +115,8 @@ - (void)setLastUpdatedDate:(NSDate *)newDate
}

lastUpdatedDate = [newDate retain];

NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
lastUpdatedLabel.text = [NSString stringWithFormat:
@"Last Updated: %@", [formatter stringFromDate:lastUpdatedDate]];
[formatter release];
[self setUpdateLabel];

}
else
{
Expand All @@ -147,6 +142,17 @@ - (void)setStatus:(int)status
}
}

-(void)setUpdateLabel
{
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
lastUpdatedLabel.text = [NSString stringWithFormat:
@"Last Updated: %@", [NSDateFormatter dateDifferenceStringFromDate:lastUpdatedDate]];
[formatter release];

}

- (void)toggleActivityView:(BOOL)isON
{
if (!isON)
Expand Down
1 change: 1 addition & 0 deletions Readdit/Lib/YMTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
checkForRefresh = YES; // only check offset when dragging
}
[[self refreshHeaderView] setUpdateLabel ];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Expand Down
19 changes: 19 additions & 0 deletions Readdit/Lib/ZelNSDateFormatter+Extras.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// ZelNSDateFormatter+Extras.h
//
// Created by Dean Smith on 16/03/2011.
//

#import <Foundation/NSDateFormatter.h>

@interface NSDateFormatter (Extras)
+ (NSString *)dateDifferenceStringFromString:(NSString *)dateString
withFormat:(NSString *)dateFormat;



+(NSString*)dateDifferenceStringFromDate:(NSDate*)date;

@end


53 changes: 53 additions & 0 deletions Readdit/Lib/ZelNSDateFormatter+Extras.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// ZelNSDateFormatter+Extras.m
//
// Created by Dean Smith on 16/03/2011.
//

#import "ZelNSDateFormatter+Extras.h"

@implementation NSDateFormatter (Extras)

+ (NSString *)dateDifferenceStringFromString:(NSString *)dateString
withFormat:(NSString *)dateFormat
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setDateFormat:dateFormat];
NSDate *date = [dateFormatter dateFromString:dateString];
return [NSDateFormatter dateDifferenceStringFromDate:date];
}


+(NSString*)dateDifferenceStringFromDate:(NSDate*)date {
NSDate *now = [NSDate date];
double time = [date timeIntervalSinceDate:now];
time *= -1;
if (time < 60) {
return @"seconds ago";
} else if (time < 3600) {
int diff = round(time / 60);
if (diff == 1)
return [NSString stringWithFormat:@"1 minute ago", diff];
return [NSString stringWithFormat:@"%d minutes ago", diff];
} else if (time < 86400) {
int diff = round(time / 60 / 60);
if (diff == 1)
return [NSString stringWithFormat:@"1 hour ago", diff];
return [NSString stringWithFormat:@"%d hours ago", diff];
} else if (time < 604800) {
int diff = round(time / 60 / 60 / 24);
if (diff == 1)
return [NSString stringWithFormat:@"yesterday", diff];
if (diff == 7)
return [NSString stringWithFormat:@"last week", diff];
return[NSString stringWithFormat:@"%d days ago", diff];
} else {
int diff = round(time / 60 / 60 / 24 / 7);
if (diff == 1)
return [NSString stringWithFormat:@"last week", diff];
return [NSString stringWithFormat:@"%d weeks ago", diff];
}
}

@end
6 changes: 6 additions & 0 deletions Readdit/Readdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
2804200C108E984D000629CD /* RDBrowserController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2804200A108E984D000629CD /* RDBrowserController.m */; };
2892E4100DC94CBA00A64D0F /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */; };
28AD73600D9D9599002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD735F0D9D9599002E5188 /* MainWindow.xib */; };
5A707DC514FD83F500E8E425 /* ZelNSDateFormatter+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = 5A707DC414FD83F500E8E425 /* ZelNSDateFormatter+Extras.m */; };
7B80610814F3DEC000B9C081 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B8060F414F3DEC000B9C081 /* MBProgressHUD.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -424,6 +425,8 @@
28A0AAE50D9B0CCF005BE974 /* Readdit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Readdit_Prefix.pch; sourceTree = "<group>"; };
28AD735F0D9D9599002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = MainWindow.xib; path = Resources/MainWindow.xib; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
5A707DC314FD83F500E8E425 /* ZelNSDateFormatter+Extras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "ZelNSDateFormatter+Extras.h"; path = "Lib/ZelNSDateFormatter+Extras.h"; sourceTree = "<group>"; };
5A707DC414FD83F500E8E425 /* ZelNSDateFormatter+Extras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "ZelNSDateFormatter+Extras.m"; path = "Lib/ZelNSDateFormatter+Extras.m"; sourceTree = "<group>"; };
7B8060F314F3DEC000B9C081 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBProgressHUD.h; sourceTree = "<group>"; };
7B8060F414F3DEC000B9C081 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBProgressHUD.m; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Readdit-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Readdit-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -990,6 +993,8 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
5A707DC314FD83F500E8E425 /* ZelNSDateFormatter+Extras.h */,
5A707DC414FD83F500E8E425 /* ZelNSDateFormatter+Extras.m */,
15B8DB3212344A3E008DA31D /* YMRefreshView.h */,
15B8DB3312344A3E008DA31D /* YMRefreshView.m */,
15B8DB3412344A3E008DA31D /* YMTableViewController.h */,
Expand Down Expand Up @@ -1278,6 +1283,7 @@
15ACAE9A1241471100737799 /* RDPileItemCell.m in Sources */,
15FA9403124FFAB300FC0528 /* RDMagazineController.m in Sources */,
7B80610814F3DEC000B9C081 /* MBProgressHUD.m in Sources */,
5A707DC514FD83F500E8E425 /* ZelNSDateFormatter+Extras.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 47e57df

Please sign in to comment.