Skip to content

Commit

Permalink
Merge branch 'release-1.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Jul 24, 2014
2 parents 73604d1 + 095b4a8 commit aa28a94
Show file tree
Hide file tree
Showing 7 changed files with 223 additions and 60 deletions.
47 changes: 36 additions & 11 deletions Core/Source/iOS/BlocksAdditions/DTActionSheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,50 @@ @implementation DTActionSheet
BOOL _isDeallocating;
}

- (id)init
// designated initializer
- (id)init
{
self = [super init];
if (self)
{
_actionsPerIndex = [[NSMutableDictionary alloc] init];
self.delegate = self;
}
return self;
self = [super init];
if (self)
{
_actionsPerIndex = [[NSMutableDictionary alloc] init];
self.delegate = self;
}
return self;
}

// designated initializer
- (id)initWithTitle:(NSString *)title
{
return [self initWithTitle:title delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
}

- (id)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [self init];
if (self)
{
self.title = title;
self.title = title;

if (otherButtonTitles != nil) {
[self addButtonWithTitle:otherButtonTitles];
va_list args;
va_start(args, otherButtonTitles);
NSString *title = nil;
while( (title = va_arg(args, NSString *)) ) {
[self addButtonWithTitle:title];
}
va_end(args);
}

if (destructiveButtonTitle) {
[self addDestructiveButtonWithTitle:destructiveButtonTitle block:nil];
}
if (cancelButtonTitle) {
[self addCancelButtonWithTitle:cancelButtonTitle block:nil];
}

_externalDelegate = delegate;
}

return self;
Expand Down
67 changes: 43 additions & 24 deletions Core/Source/iOS/BlocksAdditions/DTAlertView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,51 @@ @implementation DTAlertView


// overwrite standard initializer so that we can set our own delegate
- (id)init
{
self = [super init];
if (self)
{
_actionsPerIndex = [[NSMutableDictionary alloc] init];
self.delegate = self;
}

return self;
}

- (void)dealloc
{
_isDeallocating = YES;
}

// designated initializer
- (id)init
{
self = [super init];
if (self)
{
_actionsPerIndex = [[NSMutableDictionary alloc] init];
self.delegate = self;
}
return self;
}

- (id)initWithTitle:(NSString *)title message:(NSString *)message
{
self = [super initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
return [self initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
}

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
{
self = [self init];
if (self)
{
_actionsPerIndex = [[NSMutableDictionary alloc] init];
self.delegate = self;
self.title = title;
self.message = message;

if (otherButtonTitles != nil) {
[self addButtonWithTitle:otherButtonTitles];
va_list args;
va_start(args, otherButtonTitles);
NSString *title = nil;
while( (title = va_arg(args, NSString *)) ) {
[self addButtonWithTitle:title];
}
va_end(args);
}
if (cancelButtonTitle) {
[self addCancelButtonWithTitle:cancelButtonTitle block:nil];
}

_externalDelegate = delegate;
}
return self;
}
Expand Down Expand Up @@ -85,6 +105,14 @@ - (void)setCancelBlock:(DTAlertViewBlock)block

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSNumber *key = [NSNumber numberWithInteger:buttonIndex];

DTAlertViewBlock block = [_actionsPerIndex objectForKey:key];
if (block)
{
block();
}

if ([_externalDelegate respondsToSelector:@selector(alertView:clickedButtonAtIndex:)])
{
[_externalDelegate alertView:self clickedButtonAtIndex:buttonIndex];
Expand Down Expand Up @@ -130,15 +158,6 @@ - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSNumber *key = [NSNumber numberWithInteger:buttonIndex];

DTAlertViewBlock block = [_actionsPerIndex objectForKey:key];

if (block)
{
block();
}

if ([_externalDelegate respondsToSelector:@selector(alertView:didDismissWithButtonIndex:)])
{
[_externalDelegate alertView:self didDismissWithButtonIndex:buttonIndex];
Expand Down
4 changes: 4 additions & 0 deletions DTFoundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
A7FB1219175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; settings = {ATTRIBUTES = (Public, ); }; };
A7FB121A175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; };
A7FB121B175C9D5000D4B7F0 /* DTWeakSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */; };
BC4D93C1198044CC00961495 /* DTActionSheetTest.m in Sources */ = {isa = PBXBuildFile; fileRef = BC4D93C0198044C800961495 /* DTActionSheetTest.m */; };
C0494033163C863A470098D8 /* DTZipArchiveNode.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C0494CD06FFAB6AEAC8ADAD4 /* DTZipArchiveNode.h */; };
C04941BC829C1022DF240F4C /* DTZipArchiveNode.m in Sources */ = {isa = PBXBuildFile; fileRef = C0494FCC2C675F2CDF315027 /* DTZipArchiveNode.m */; };
C049420F39CD4294FCE0F549 /* DTZipArchiveGZip.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C04943358446F1A9BA86F458 /* DTZipArchiveGZip.h */; };
Expand Down Expand Up @@ -827,6 +828,7 @@
A7FAA3871652291D006ED151 /* NSURL+DTComparing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+DTComparing.h"; sourceTree = "<group>"; };
A7FAA3881652291D006ED151 /* NSURL+DTComparing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+DTComparing.m"; sourceTree = "<group>"; };
A7FB1218175C9D5000D4B7F0 /* DTWeakSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTWeakSupport.h; sourceTree = "<group>"; };
BC4D93C0198044C800961495 /* DTActionSheetTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DTActionSheetTest.m; sourceTree = "<group>"; };
C0494136CFE5018E95613EA7 /* gzip_sample.txt.gz */ = {isa = PBXFileReference; lastKnownFileType = archive.gzip; path = gzip_sample.txt.gz; sourceTree = "<group>"; };
C04942C8BD89694FA3602A10 /* gzip_sample.txt.original */ = {isa = PBXFileReference; lastKnownFileType = file.original; path = gzip_sample.txt.original; sourceTree = "<group>"; };
C04943358446F1A9BA86F458 /* DTZipArchiveGZip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DTZipArchiveGZip.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1589,6 +1591,7 @@
A7D60FE515D3B15300AEDD1B /* Source */ = {
isa = PBXGroup;
children = (
BC4D93C0198044C800961495 /* DTActionSheetTest.m */,
A7640E4016F3226B003A7B43 /* DTASN1 */,
A768BE4217FC40E6008834C6 /* DTBlockFunctionsTest.h */,
A768BE4317FC40E6008834C6 /* DTBlockFunctionsTest.m */,
Expand Down Expand Up @@ -2736,6 +2739,7 @@
files = (
A705E8A2197ED5D2001B16A7 /* DTLogTest.m in Sources */,
A7917C8E191A31A300964D63 /* DTScriptingTest.m in Sources */,
BC4D93C1198044CC00961495 /* DTActionSheetTest.m in Sources */,
A7917C8F191A31A300964D63 /* NSArrayDTErrorTest.m in Sources */,
A7917C91191A31A300964D63 /* DTZipArchiveTest.m in Sources */,
A7917C8A191A31A300964D63 /* DTASN1SerializationTest.m in Sources */,
Expand Down
47 changes: 32 additions & 15 deletions Demo/DTProgressHUDDemo/Resources/Base.lproj/Main_iPhone.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@
<action selector="showInfiniteProgressPressed:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="giO-tw-95G"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8Ce-MQ-aMo">
<rect key="frame" x="19" y="316" width="277" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="gIy-D5-eRI"/>
<constraint firstAttribute="width" constant="277" id="nxq-Oi-W2z"/>
</constraints>
<state key="normal" title="Show DTActionSheet">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showDTActionSheet:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="9p0-PT-8LX"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="JyR-G9-NUt">
<rect key="frame" x="20" y="32" width="277" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand Down Expand Up @@ -132,13 +117,44 @@
<action selector="hidePressed:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="eJy-K1-61N"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="8Ce-MQ-aMo">
<rect key="frame" x="19" y="316" width="277" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="gIy-D5-eRI"/>
<constraint firstAttribute="width" constant="277" id="nxq-Oi-W2z"/>
</constraints>
<state key="normal" title="Show DTActionSheet">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showDTActionSheet:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="9p0-PT-8LX"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="right" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IH4-d0-toA">
<rect key="frame" x="20" y="354" width="277" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="jg2-tj-hBR"/>
<constraint firstAttribute="width" constant="277" id="lF2-DZ-aS6"/>
</constraints>
<state key="normal" title="Show DTAlertView">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="showDTAlertViewidsender:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="RqG-kI-lHZ"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DJh-Fe-y6C" firstAttribute="trailing" secondItem="8Ce-MQ-aMo" secondAttribute="trailing" constant="1" id="1QR-SL-90q"/>
<constraint firstItem="DJh-Fe-y6C" firstAttribute="top" secondItem="bhl-G4-Opf" secondAttribute="bottom" constant="84" id="2wD-3Q-MnD"/>
<constraint firstAttribute="trailing" secondItem="DJh-Fe-y6C" secondAttribute="trailing" constant="23" id="Bi9-UI-Sos"/>
<constraint firstAttribute="trailing" secondItem="phX-rF-Ucj" secondAttribute="trailing" id="DT0-UQ-LXl"/>
<constraint firstItem="8Ce-MQ-aMo" firstAttribute="trailing" secondItem="IH4-d0-toA" secondAttribute="trailing" constant="-1" id="Inw-Gz-cbH"/>
<constraint firstAttribute="trailing" secondItem="jb8-0v-n9D" secondAttribute="trailing" constant="23" id="J6E-MF-dC6"/>
<constraint firstAttribute="trailing" secondItem="UdA-xj-qh9" secondAttribute="trailing" constant="24" id="KgY-g6-huc"/>
<constraint firstAttribute="trailing" secondItem="JyR-G9-NUt" secondAttribute="trailing" constant="23" id="NUE-7c-bo9"/>
Expand All @@ -149,6 +165,7 @@
<constraint firstItem="phX-rF-Ucj" firstAttribute="top" secondItem="kh9-bI-dsS" secondAttribute="top" id="ZyE-ey-D99"/>
<constraint firstItem="phX-rF-Ucj" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="bgf-WY-f5c"/>
<constraint firstItem="bhl-G4-Opf" firstAttribute="top" secondItem="JyR-G9-NUt" secondAttribute="bottom" constant="8" id="gIL-P7-jwO"/>
<constraint firstItem="IH4-d0-toA" firstAttribute="top" secondItem="8Ce-MQ-aMo" secondAttribute="bottom" constant="8" id="iVE-KI-8A3"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="phX-rF-Ucj" secondAttribute="bottom" id="knm-GB-MkK"/>
<constraint firstItem="JyR-G9-NUt" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="12" id="moE-Nj-euQ"/>
<constraint firstItem="yTU-xt-6ui" firstAttribute="top" secondItem="DJh-Fe-y6C" secondAttribute="bottom" constant="36" id="qaq-SL-9SM"/>
Expand Down
27 changes: 22 additions & 5 deletions Demo/DTProgressHUDDemo/Source/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "DTProgressHUD.h"
#import "DTActionSheet.h"
#import "DTAlertView.h"

@interface ViewController ()

Expand Down Expand Up @@ -100,20 +101,36 @@ - (IBAction)showDTActionSheet:(id)sender
DTActionSheet *actionSheet = [[DTActionSheet alloc] initWithTitle:@"This is a block-based DTActionSheet"
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet addDestructiveButtonWithTitle:@"Say hi" block:^
destructiveButtonTitle:@"Destructive"
otherButtonTitles:@"a", @"b", nil];

[actionSheet addButtonWithTitle:@"Say hi" block:^
{
NSLog(@"Hi!");
}];

[actionSheet addCancelButtonWithTitle:@"Cancel" block:^
{
NSLog(@"Cancelled :-(");
}];
[actionSheet showInView:self.view];
}

- (IBAction)showDTAlertViewidsender:(id)sender {
DTAlertView *alertView = [[DTAlertView alloc] initWithTitle:@"DTAlertView"
message:@"This is a block-based DTAlertView"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"a", @"b", nil];

[alertView addButtonWithTitle:@"Say hi" block:^
{
NSLog(@"Hi!");
}];
[alertView addCancelButtonWithTitle:@"Cancel" block:^
{
NSLog(@"Cancelled :-(");
}];
[alertView show];
}

- (void)_createProgressHUD
Expand Down
61 changes: 61 additions & 0 deletions Test/Source/DTActionSheetTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// DTActionSheetTest.m
// DTFoundation
//
// Created by Rene Pirringer on 22.07.14.
// Copyright (c) 2014 Cocoanetics. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "DTActionSheet.h"


@interface DTActionSheet(Private) <UIActionSheetDelegate>
@end


@implementation DTActionSheet(Private)
@end


@interface DTActionSheetTest : XCTestCase
@end


@implementation DTActionSheetTest

- (void)testInitMethods {
__block BOOL blockExecuted = NO;
DTActionSheet *actionSheet = [[DTActionSheet alloc] init];
[actionSheet addButtonWithTitle:@"Ok" block:^{
blockExecuted = YES;
}];

[actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1];

XCTAssertTrue(blockExecuted, @"The ok button block should be executed");

blockExecuted = NO;
actionSheet = [[DTActionSheet alloc] initWithTitle:@"Foo"];
[actionSheet addButtonWithTitle:@"Ok" block:^{
blockExecuted = YES;
}];

[actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1];

XCTAssertTrue(blockExecuted, @"The ok button block should be executed");

blockExecuted = NO;
actionSheet = [[DTActionSheet alloc] initWithTitle:@"Foo" delegate:nil cancelButtonTitle:@"cancel" destructiveButtonTitle:nil otherButtonTitles:@"a", @"b", nil];
[actionSheet addButtonWithTitle:@"Ok" block:^{
blockExecuted = YES;
}];

[actionSheet actionSheet:actionSheet clickedButtonAtIndex:actionSheet.numberOfButtons - 1];

XCTAssertTrue(blockExecuted, @"The ok button block should be executed");
}


@end
Loading

0 comments on commit aa28a94

Please sign in to comment.