diff --git a/NoticeView.xcodeproj/project.pbxproj b/NoticeView.xcodeproj/project.pbxproj index b8ca471..c106ecb 100644 --- a/NoticeView.xcodeproj/project.pbxproj +++ b/NoticeView.xcodeproj/project.pbxproj @@ -29,6 +29,8 @@ 748A6A5D157D0D06003C7655 /* WBStickyNoticeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 748A6A5C157D0D06003C7655 /* WBStickyNoticeView.m */; }; 7492FA45157C8CD700FB834C /* WBBlueGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7492FA42157C8CD700FB834C /* WBBlueGradientView.m */; }; 7492FA46157C8CD700FB834C /* WBRedGradientView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7492FA44157C8CD700FB834C /* WBRedGradientView.m */; }; + FE07240C16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = FE07240B16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m */; }; + FED81FA916B97A1C00254985 /* WBNoticeOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = FED81FA816B97A1C00254985 /* WBNoticeOperation.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -68,6 +70,10 @@ 7492FA42157C8CD700FB834C /* WBBlueGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBBlueGradientView.m; sourceTree = ""; }; 7492FA43157C8CD700FB834C /* WBRedGradientView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBRedGradientView.h; sourceTree = ""; }; 7492FA44157C8CD700FB834C /* WBRedGradientView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBRedGradientView.m; sourceTree = ""; }; + FE07240A16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSOperationQueue+WBNoticeExtensions.h"; sourceTree = ""; }; + FE07240B16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSOperationQueue+WBNoticeExtensions.m"; sourceTree = ""; }; + FED81FA716B97A1C00254985 /* WBNoticeOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WBNoticeOperation.h; sourceTree = ""; }; + FED81FA816B97A1C00254985 /* WBNoticeOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WBNoticeOperation.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -99,8 +105,12 @@ 592BDDE315645BEE00B78820 /* WBNoticeView */ = { isa = PBXGroup; children = ( + FE07240A16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.h */, + FE07240B16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m */, 746CBCFE1570A1D100B844B1 /* WBErrorNoticeView.h */, 746CBCFF1570A1D100B844B1 /* WBErrorNoticeView.m */, + FED81FA716B97A1C00254985 /* WBNoticeOperation.h */, + FED81FA816B97A1C00254985 /* WBNoticeOperation.m */, 746CBD061570A8FA00B844B1 /* WBSuccessNoticeView.h */, 746CBD071570A8FA00B844B1 /* WBSuccessNoticeView.m */, 748A6A5B157D0D06003C7655 /* WBStickyNoticeView.h */, @@ -263,6 +273,8 @@ 7492FA46157C8CD700FB834C /* WBRedGradientView.m in Sources */, 748A6A59157D0B74003C7655 /* WBGrayGradientView.m in Sources */, 748A6A5D157D0D06003C7655 /* WBStickyNoticeView.m in Sources */, + FED81FA916B97A1C00254985 /* WBNoticeOperation.m in Sources */, + FE07240C16BAB0F000B46F59 /* NSOperationQueue+WBNoticeExtensions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.h b/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.h new file mode 100644 index 0000000..22dce17 --- /dev/null +++ b/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.h @@ -0,0 +1,19 @@ +// +// NSOperationQueue+WBNoticeExtensions.h +// NoticeView +// +// Created by Johannes Plunien on 1/31/13. +// Copyright (c) 2013 Tito Ciuro. All rights reserved. +// + +#import +#import "WBNoticeView.h" +#import "WBNoticeOperation.h" + +@interface NSOperationQueue (WBNoticeExtensions) + ++ (WBNoticeOperation *)addNoticeView:(WBNoticeView *)noticeView; ++ (WBNoticeOperation *)addNoticeView:(WBNoticeView *)noticeView + filterDuplicates:(BOOL)filterDuplicates; + +@end diff --git a/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.m b/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.m new file mode 100644 index 0000000..d9b4d68 --- /dev/null +++ b/NoticeView/WBNoticeView/NSOperationQueue+WBNoticeExtensions.m @@ -0,0 +1,38 @@ +// +// NSOperationQueue+WBNoticeExtensions.m +// NoticeView +// +// Created by Johannes Plunien on 1/31/13. +// Copyright (c) 2013 Tito Ciuro. All rights reserved. +// + +#import "NSOperationQueue+WBNoticeExtensions.h" + +@implementation NSOperationQueue (WBNoticeExtensions) + ++ (WBNoticeOperation *)addNoticeView:(WBNoticeView *)noticeView +{ + return [self addNoticeView:noticeView filterDuplicates:NO]; +} + ++ (WBNoticeOperation *)addNoticeView:(WBNoticeView *)noticeView + filterDuplicates:(BOOL)filterDuplicates +{ + if (filterDuplicates) { + for (NSOperation *operation in [[self mainQueue] operations]) { + if ([operation isKindOfClass:[WBNoticeOperation class]] == NO) { + continue; + } + WBNoticeOperation *noticeOperation = (WBNoticeOperation *)operation; + if ([noticeOperation.noticeView isEqual:noticeView]) { + return nil; + } + } + } + WBNoticeOperation *operation = [[WBNoticeOperation alloc] init]; + operation.noticeView = noticeView; + [[self mainQueue] addOperation:operation]; + return operation; +} + +@end diff --git a/NoticeView/WBNoticeView/WBNoticeOperation.h b/NoticeView/WBNoticeView/WBNoticeOperation.h new file mode 100644 index 0000000..ba370b2 --- /dev/null +++ b/NoticeView/WBNoticeView/WBNoticeOperation.h @@ -0,0 +1,17 @@ +// +// WBNoticeOperation.h +// NoticeView +// +// Created by Johannes Plunien on 1/30/13. +// Copyright (c) 2013 Tito Ciuro. All rights reserved. +// + +#import +#import "WBNoticeView.h" + +@interface WBNoticeOperation : NSOperation + +@property (nonatomic, assign) BOOL dismissedInteractively; +@property (nonatomic, strong) WBNoticeView *noticeView; + +@end diff --git a/NoticeView/WBNoticeView/WBNoticeOperation.m b/NoticeView/WBNoticeView/WBNoticeOperation.m new file mode 100644 index 0000000..239bc21 --- /dev/null +++ b/NoticeView/WBNoticeView/WBNoticeOperation.m @@ -0,0 +1,37 @@ +// +// WBNoticeOperation.m +// NoticeView +// +// Created by Johannes Plunien on 1/30/13. +// Copyright (c) 2013 Tito Ciuro. All rights reserved. +// + +#import "WBNoticeOperation.h" + +@interface WBNoticeOperation () + +@property (nonatomic, assign, getter = isExecuting) BOOL executing; +@property (nonatomic, assign, getter = isFinished) BOOL finished; + +@end + +@implementation WBNoticeOperation + +- (void)start +{ + self.executing = YES; + self.finished = NO; + __weak __typeof(&*self)weakSelf = self; + self.noticeView.dismissalBlock = ^(BOOL dismissedInteractively) { + [weakSelf willChangeValueForKey:@"isFinished"]; + [weakSelf willChangeValueForKey:@"isExecuting"]; + weakSelf.executing = NO; + weakSelf.finished = YES; + weakSelf.dismissedInteractively = dismissedInteractively; + [weakSelf didChangeValueForKey:@"isExecuting"]; + [weakSelf didChangeValueForKey:@"isFinished"]; + }; + [self.noticeView show]; +} + +@end diff --git a/NoticeView/WBNoticeView/WBNoticeView.m b/NoticeView/WBNoticeView/WBNoticeView.m index 19abbf8..56f9dcf 100644 --- a/NoticeView/WBNoticeView/WBNoticeView.m +++ b/NoticeView/WBNoticeView/WBNoticeView.m @@ -70,6 +70,11 @@ [self doesNotRecognizeSelector:_cmd]; } +- (BOOL)isEqual:(WBNoticeView *)object +{ + return [self.title isEqual:object.title] && [self.message isEqual:object.message]; +} + #pragma mark - - (void)displayNotice diff --git a/NoticeView/WBViewController.m b/NoticeView/WBViewController.m index 547693a..e06d48e 100644 --- a/NoticeView/WBViewController.m +++ b/NoticeView/WBViewController.m @@ -30,6 +30,7 @@ #import "WBErrorNoticeView.h" #import "WBSuccessNoticeView.h" #import "WBStickyNoticeView.h" +#import "NSOperationQueue+WBNoticeExtensions.h" @interface WBViewController () @property (nonatomic, readwrite, weak) WBNoticeView *currentNoticeView; @@ -70,6 +71,16 @@ [notice show]; } +- (IBAction)showQueuedErrorNotice:(id)sender +{ + WBErrorNoticeView *notice = [WBErrorNoticeView errorNoticeInView:self.view title:@"Queued Network Error" message:@"Check your network connection."]; + WBNoticeOperation *operation = [NSOperationQueue addNoticeView:notice filterDuplicates:YES]; + __block WBNoticeOperation *weakOperation = operation; + operation.completionBlock = ^{ + NSLog(@"Queued notice operation dismissed! Interactively: %@", weakOperation.dismissedInteractively ? @"YES" : @"NO"); + }; +} + - (IBAction)showLargeErrorNotice:(id)sender { WBErrorNoticeView *notice = [WBErrorNoticeView errorNoticeInView:self.view title:@"Network Error" message:@"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book."]; diff --git a/NoticeView/en.lproj/MainStoryboard.storyboard b/NoticeView/en.lproj/MainStoryboard.storyboard index 1cb9af3..4654974 100644 --- a/NoticeView/en.lproj/MainStoryboard.storyboard +++ b/NoticeView/en.lproj/MainStoryboard.storyboard @@ -1,8 +1,8 @@ - + - - + + @@ -77,6 +77,21 @@ +