Skip to content

Commit

Permalink
Added 2 new methods, cleanup
Browse files Browse the repository at this point in the history
• Added +showWithTitle: and +dismissAfterDelay:
• Centralized defines
• Separated public from private defines
• Moved from float to NSTimeInterval (aka double) for delays
  • Loading branch information
Jonas Gessner committed Aug 25, 2013
1 parent 789e6a7 commit b8e4401
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 152 deletions.
22 changes: 20 additions & 2 deletions Demo/MMProgressHUDDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
69DA08D2158261EE000DC29E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 69DA08D0158261EE000DC29E /* InfoPlist.strings */; };
69DA08D5158261EE000DC29E /* MMProgressHUDTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 69DA08D4158261EE000DC29E /* MMProgressHUDTests.m */; };
DDBCC20617C2822A00C3BF8C /* MMLinearProgressView.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */; };
DDBE93BE17CA59FD00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; };
DDBE93BF17CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; };
DDBE93C017CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */; };
DDBE93C317CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; };
DDBE93C417CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; };
DDBE93C517CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */ = {isa = PBXBuildFile; fileRef = DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -146,7 +152,10 @@
DDB2DD6A17C626570077C18E /* MMProgressHUDDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMProgressHUDDefines.h; sourceTree = "<group>"; };
DDBCC20317C2822A00C3BF8C /* MMLinearProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMLinearProgressView.h; sourceTree = "<group>"; };
DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MMLinearProgressView.m; sourceTree = "<group>"; };
DDBCC20517C2822A00C3BF8C /* MMProgressView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MMProgressView.h; sourceTree = "<group>"; };
DDBCC20517C2822A00C3BF8C /* MMProgressView-Protocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MMProgressView-Protocol.h"; sourceTree = "<group>"; };
DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMProgressHUDDefines.m; sourceTree = "<group>"; };
DDBE93C117CA5BF300B78C77 /* MMProgressHUDDefines-Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MMProgressHUDDefines-Private.h"; sourceTree = "<group>"; };
DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MMProgressHUDDefines-Private.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -257,14 +266,17 @@
46F3F73D16D1E76700E255A2 /* MMVectorImage.h */,
46F3F73E16D1E76700E255A2 /* MMVectorImage.m */,
DDB2DD6A17C626570077C18E /* MMProgressHUDDefines.h */,
DDBE93BD17CA561D00B78C77 /* MMProgressHUDDefines.m */,
DDBE93C117CA5BF300B78C77 /* MMProgressHUDDefines-Private.h */,
DDBE93C217CA5BF300B78C77 /* MMProgressHUDDefines-Private.m */,
46A19B5B155493B500D65BB8 /* MMProgressHUD.h */,
46A19B5C155493B500D65BB8 /* MMProgressHUD.m */,
55AC1A0315A602A500D64C1F /* MMProgressHUDOverlayView.h */,
55AC1A0415A602A500D64C1F /* MMProgressHUDOverlayView.m */,
55F0596515A20BDD00A47983 /* MMProgressHUD+Class.m */,
55F0595F15A2083C00A47983 /* MMProgressHUD+Animations.h */,
55F0596015A2083C00A47983 /* MMProgressHUD+Animations.m */,
DDBCC20517C2822A00C3BF8C /* MMProgressView.h */,
DDBCC20517C2822A00C3BF8C /* MMProgressView-Protocol.h */,
DDBCC20317C2822A00C3BF8C /* MMLinearProgressView.h */,
DDBCC20417C2822A00C3BF8C /* MMLinearProgressView.m */,
550D504A15615BEF0092B975 /* MMRadialProgressView.h */,
Expand Down Expand Up @@ -508,11 +520,13 @@
46A19B4A155492E000D65BB8 /* MMViewController.m in Sources */,
46A19B5D155493B500D65BB8 /* MMProgressHUD.m in Sources */,
550D504C15615BEF0092B975 /* MMRadialProgressView.m in Sources */,
DDBE93BE17CA59FD00B78C77 /* MMProgressHUDDefines.m in Sources */,
5527AEFB159CD7650037D67D /* MMHud.m in Sources */,
5527AEFF159CD7D50037D67D /* MMProgressHUDWindow.m in Sources */,
5527AF03159CD8200037D67D /* MMProgressHUDViewController.m in Sources */,
55F0596115A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */,
55F0596615A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */,
DDBE93C317CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */,
55AC1A0515A602A500D64C1F /* MMProgressHUDOverlayView.m in Sources */,
DDBCC20617C2822A00C3BF8C /* MMLinearProgressView.m in Sources */,
46F3F73F16D1E76700E255A2 /* MMVectorImage.m in Sources */,
Expand All @@ -528,11 +542,13 @@
55F0589A159E04E200A47983 /* MMHudTests.m in Sources */,
55F0589B159E058600A47983 /* MMProgressHUD.m in Sources */,
55F0589C159E058600A47983 /* MMRadialProgressView.m in Sources */,
DDBE93C017CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */,
55F0589D159E058600A47983 /* MMHud.m in Sources */,
55F0589E159E058600A47983 /* MMProgressHUDWindow.m in Sources */,
55F0589F159E058600A47983 /* MMProgressHUDViewController.m in Sources */,
55F0596315A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */,
55F0596815A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */,
DDBE93C517CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */,
55AC1A0615A602A500D64C1F /* MMProgressHUDOverlayView.m in Sources */,
46ACE86C17C50A610075C2A0 /* MMLinearProgressView.m in Sources */,
46F3F74116D1E76700E255A2 /* MMVectorImage.m in Sources */,
Expand All @@ -548,11 +564,13 @@
5527AF07159CD97A0037D67D /* MMHudTests.m in Sources */,
55F0592D159E39C400A47983 /* MMProgressHUD.m in Sources */,
55F0592E159E39CB00A47983 /* MMRadialProgressView.m in Sources */,
DDBE93BF17CA59FE00B78C77 /* MMProgressHUDDefines.m in Sources */,
55F0592F159E39CB00A47983 /* MMHud.m in Sources */,
55F05930159E39CB00A47983 /* MMProgressHUDWindow.m in Sources */,
55F05931159E39CB00A47983 /* MMProgressHUDViewController.m in Sources */,
55F0596215A2083C00A47983 /* MMProgressHUD+Animations.m in Sources */,
55F0596715A20BDD00A47983 /* MMProgressHUD+Class.m in Sources */,
DDBE93C417CA5BF300B78C77 /* MMProgressHUDDefines-Private.m in Sources */,
55AC1A0815A62B6900D64C1F /* MMProgressHUDOverlayView.m in Sources */,
46ACE86B17C50A580075C2A0 /* MMLinearProgressView.m in Sources */,
46F3F74016D1E76700E255A2 /* MMVectorImage.m in Sources */,
Expand Down
27 changes: 0 additions & 27 deletions Source/MMHud.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@
#import <UIKit/UIKit.h>
#import "MMProgressHUDDefines.h"

MMExtern CGFloat const MMProgressHUDAnimateInDurationLong;
MMExtern CGFloat const MMProgressHUDAnimateInDurationNormal;
MMExtern CGFloat const MMProgressHUDAnimateInDurationMedium;
MMExtern CGFloat const MMProgressHUDAnimateInDurationShort;
MMExtern CGFloat const MMProgressHUDAnimateInDurationVeryShort;

MMExtern CGFloat const MMProgressHUDAnimateOutDurationLong;
MMExtern CGFloat const MMProgressHUDAnimateOutDurationMedium;
MMExtern CGFloat const MMProgressHUDAnimateOutDurationShort;

typedef NS_ENUM(NSInteger, MMProgressHUDDisplayStyle) {
MMProgressHUDDisplayStylePlain = 0,
MMProgressHUDDisplayStyleBordered,
};

typedef NS_ENUM(NSInteger, MMProgressHUDProgressStyle) {
MMProgressHUDProgressStyleIndeterminate = 0,
MMProgressHUDProgressStyleRadial,
MMProgressHUDProgressStyleLinear,
} DEPRECATED_ATTRIBUTE;

typedef NS_ENUM(NSInteger, MMProgressHUDCompletionState) {
MMProgressHUDCompletionStateNone = 0,
MMProgressHUDCompletionStateError,
MMProgressHUDCompletionStateSuccess,
};

@class MMHud;

@protocol MMHudDelegate <NSObject>
Expand Down
36 changes: 2 additions & 34 deletions Source/MMHud.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,10 @@
#import <QuartzCore/QuartzCore.h>
#import "MMHud.h"
#import "MMProgressHUD.h"
#import "MMProgressView.h"
#import "MMProgressView-Protocol.h"
#import "MMRadialProgressView.h"

CGFloat const MMProgressHUDDefaultFontSize = 16.f;

CGFloat const MMProgressHUDMaximumWidth = 300.f;
CGFloat const MMProgressHUDMinimumWidth = 100.f;
CGFloat const MMProgressHUDContentPadding = 5.f;

CGFloat const MMProgressHUDAnimateInDurationLong = 1.5f;
CGFloat const MMProgressHUDAnimateInDurationMedium = 0.75f;
CGFloat const MMProgressHUDAnimateInDurationNormal = 0.35f;
CGFloat const MMProgressHUDAnimateInDurationShort = 0.25f;
CGFloat const MMProgressHUDAnimateInDurationVeryShort= 0.15f;

CGFloat const MMProgressHUDAnimateOutDurationLong = 0.75f;
CGFloat const MMProgressHUDAnimateOutDurationMedium = 0.55f;
CGFloat const MMProgressHUDAnimateOutDurationShort = 0.35f;

CGSize const MMProgressHUDDefaultContentAreaSize = { 100.f, 100.f };
CGSize const MMProgressHUDProgressContentAreaSize = { 40.f, 40.f };
CGSize const MMProgressHUDProgressMaximumAreaSize = {200.0f, 200.0f};


NSString * const MMProgressHUDFontNameBold = @"HelveticaNeue-Bold";
NSString * const MMProgressHUDFontNameNormal = @"HelveticaNeue-Light";

#ifdef DEBUG
#ifdef MM_HUD_FRAME_DEBUG
static const BOOL MMProgressHUDFrameDebugModeEnabled = YES;
#else
static const BOOL MMProgressHUDFrameDebugModeEnabled = NO;
#endif
#else
static const BOOL MMProgressHUDFrameDebugModeEnabled = NO;
#endif
#import "MMProgressHUDDefines-Private.h"

@interface MMHud()

Expand Down
2 changes: 1 addition & 1 deletion Source/MMLinearProgressView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "MMProgressView.h"
#import "MMProgressView-Protocol.h"

@interface MMLinearProgressView : UIView <MMProgressView>

Expand Down
2 changes: 2 additions & 0 deletions Source/MMProgressHUD+Animations.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import <QuartzCore/QuartzCore.h>
#import "MMProgressHUD+Animations.h"

#import "MMProgressHUDDefines-Private.h"

@interface MMProgressHUD ()

- (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor;
Expand Down
21 changes: 16 additions & 5 deletions Source/MMProgressHUD+Class.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
//

#import "MMProgressHUD.h"
#import "MMProgressHUDDefines-Private.h"

@interface MMProgressHUD()

- (CGPoint)_windowCenterForHUDAnchor:(CGPoint)anchor;
- (void)dismissWithCompletionState:(MMProgressHUDCompletionState)completionState
title:(NSString *)title
status:(NSString *)status
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

- (void)_updateHUDAnimated:(BOOL)animated
withCompletion:(void(^)(BOOL completed))completionBlock;

- (void)show;
- (void)dismiss;
- (void)dismissAfterDelay:(NSTimeInterval)delay;

@end

Expand Down Expand Up @@ -109,6 +111,11 @@ + (void)updateProgress:(CGFloat)progress {
}

//indeterminate status
+ (void)showWithTitle:(NSString *)title {
[MMProgressHUD showWithTitle:title
status:nil];
}

+ (void)showWithStatus:(NSString *)status {
[MMProgressHUD showWithTitle:nil
status:status];
Expand Down Expand Up @@ -222,7 +229,7 @@ + (void)showWithTitle:(NSString *)title
//dismissal
+ (void)dismissWithError:(NSString *)status
title:(NSString *)title
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateError
Expand Down Expand Up @@ -252,15 +259,15 @@ + (void)dismissWithError:(NSString *)status {
}

+ (void)dismissWithError:(NSString *)status
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
[MMProgressHUD dismissWithError:status
title:nil
afterDelay:delay];
}

+ (void)dismissWithSuccess:(NSString *)status
title:(NSString *)title
afterDelay:(float)delay {
afterDelay:(NSTimeInterval)delay {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismissWithCompletionState:MMProgressHUDCompletionStateSuccess
Expand Down Expand Up @@ -289,10 +296,14 @@ + (void)dismissWithSuccess:(NSString *)status {
title:nil];
}

+ (void)dismissAfterDelay:(NSTimeInterval)delay {
[[MMProgressHUD sharedHUD] dismissAfterDelay:delay];
}

+ (void)dismiss {
if ([NSThread isMainThread] == NO) {
dispatch_sync(dispatch_get_main_queue(), ^{
[[MMProgressHUD sharedHUD] dismiss];
[[MMProgressHUD sharedHUD] dismiss];
});
}
else {
Expand Down
78 changes: 30 additions & 48 deletions Source/MMProgressHUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,9 @@
#import <UIKit/UIKit.h>
#import "MMHud.h"

MMExtern NSString * const MMProgressHUDDefaultConfirmationMessage;

MMExtern NSString * const MMProgressHUDAnimationShow;
MMExtern NSString * const MMProgressHUDAnimationDismiss;
MMExtern NSString * const MMProgressHUDAnimationWindowFadeOut;
MMExtern NSString * const MMProgressHUDAnimationKeyShowAnimation;
MMExtern NSString * const MMProgressHUDAnimationKeyDismissAnimation;


MMExtern float const MMProgressHUDStandardDismissDelay;

@class MMProgressHUDWindow;
@class MMProgressHUDOverlayView;

typedef NS_ENUM(NSInteger, MMProgressHUDPresentationStyle) {
MMProgressHUDPresentationStyleDrop = 0, //default
MMProgressHUDPresentationStyleExpand,
MMProgressHUDPresentationStyleShrink,
MMProgressHUDPresentationStyleSwingLeft,
MMProgressHUDPresentationStyleSwingRight,
MMProgressHUDPresentationStyleBalloon,
MMProgressHUDPresentationStyleFade,
MMProgressHUDPresentationStyleNone
};

typedef NS_ENUM(NSInteger, MMProgressHUDWindowOverlayMode) {
MMProgressHUDWindowOverlayModeNone = -1,
MMProgressHUDWindowOverlayModeGradient = 0,
MMProgressHUDWindowOverlayModeLinear,
/*MMProgressHUDWindowOverlayModeBlur*/ //iOS 7 only
};

//iOS 7 only
//typedef NS_ENUM(NSInteger, MMProgressHUDOptions) {
// MMProgressHUDOptionGravityEnabled = 1 << 0,
// MMProgressHUDOptionGyroEnabled = 1 << 1,
//};

@interface MMProgressHUD : UIView

/** An enum to specify the style in which to display progress.
Expand Down Expand Up @@ -164,6 +129,27 @@ This message will be presented to the user when a cancelBlock is present after t
/** @name Presentation */
//-----------------------------------------------


/** Shows indeterminate HUD with specified title.
@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.
@param title Title to display.
*/
+ (void)showWithTitle:(NSString *)title;


/** Shows user-blocking HUD with only a status message.
Since the title of this HUD is nil, the status message font will become bold by default.
@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.
@param status Status message to display.
*/
+ (void)showWithStatus:(NSString *)status;


/** Shows indeterminate HUD with specified title and status.
When the title of the HUD is nil, the status message font will become bold by default.
Expand Down Expand Up @@ -301,23 +287,19 @@ This message will be presented to the user when a cancelBlock is present after t
status:(NSString *)status
images:(NSArray *)images;

/** Shows user-blocking HUD with only a status message.
Since the title of this HUD is nil, the status message font will become bold by default.
@warning All show methods are mutually exclusive of one another. Use the updateStatus: method to update the HUD's status while maintaining all previously set presentation attributes such as image, images, cancelBlock, title, or confirmationMessage. For example: calling showWithTitle:status: after calling showWithTitle:status:image: will wipe out the image specified in the latter call.
@param status Status message to display.
*/
+ (void)showWithStatus:(NSString *)status;

//-----------------------------------------------
/** @name Dismissal */
//-----------------------------------------------

/** Dismisses the shared HUD with the current presentationStyle and default delay. */
+ (void)dismiss;


/** Dismisses the shared HUD with the current presentationStyle and specified delay.
@param delay Delay to wait before animating the dismiss of the HUD.
*/
+ (void)dismissAfterDelay:(NSTimeInterval)delay;

#pragma mark - Dismiss with Error

/** Dismisses the shared HUD with the current presentationStyle in an error-state after a user-specified delay.
Expand All @@ -328,7 +310,7 @@ This message will be presented to the user when a cancelBlock is present after t
*/
+ (void)dismissWithError:(NSString *)message
title:(NSString *)title
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

/** Dismisses the shared HUD with the current presentationStyle in an error-state after a standard delay.
Expand All @@ -350,7 +332,7 @@ This message will be presented to the user when a cancelBlock is present after t
@param delay Delay to wait before animating the dismiss of the HUD.
*/
+ (void)dismissWithError:(NSString *)message
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

#pragma mark - Dismiss with Success
/** Dismisses the shared HUD with the current presentationStyle in a success-state after a user-specified delay.
Expand All @@ -361,7 +343,7 @@ This message will be presented to the user when a cancelBlock is present after t
*/
+ (void)dismissWithSuccess:(NSString *)message
title:(NSString *)title
afterDelay:(float)delay;
afterDelay:(NSTimeInterval)delay;

/** Dismisses the shared HUD with the current presentationStyle in a success-state.
Expand Down
Loading

0 comments on commit b8e4401

Please sign in to comment.