Permalink
Browse files

Initial Revision

  • Loading branch information...
0 parents commit 0ecffb0cc414360de20b5ee6677218813684ddba @rs committed Oct 3, 2010
Showing with 115 additions and 0 deletions.
  1. +20 −0 LICENSE
  2. +22 −0 SDNetworkActivityIndicator.h
  3. +73 −0 SDNetworkActivityIndicator.m
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Olivier Poitrey <rs@dailymotion.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is furnished
+to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
@@ -0,0 +1,22 @@
+/*
+ * This file is part of the SDNetworkActivityIndicator package.
+ * (c) Olivier Poitrey <rs@dailymotion.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+#import <Foundation/Foundation.h>
+
+@interface SDNetworkActivityIndicator : NSObject
+{
+ @private
+ NSUInteger counter;
+}
+
++ (id)sharedActivityIndicator;
+- (void)startActivity;
+- (void)stopActivity;
+- (void)stopAllActivity;
+
+@end
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the SDNetworkActivityIndicator package.
+ * (c) Olivier Poitrey <rs@dailymotion.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+#import "SDNetworkActivityIndicator.h"
+
+static SDNetworkActivityIndicator *instance;
+
+@implementation SDNetworkActivityIndicator
+
++ (id)sharedActivityIndicator
+{
+ if (instance == nil)
+ {
+ @synchronized(instance)
+ {
+ if (instance == nil)
+ {
+ instance = [[SDNetworkActivityIndicator alloc] init];
+ }
+ }
+ }
+
+ return instance;
+}
+
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ counter = 0;
+ }
+
+ return self;
+}
+
+- (void)startActivity
+{
+ @synchronized(self)
+ {
+ if (counter == 0)
+ {
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
+ }
+ counter++;
+ }
+}
+
+- (void)stopActivity
+{
+ @synchronized(self)
+ {
+ if (counter > 0 && --counter == 0)
+ {
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+ }
+ }
+}
+
+- (void)stopAllActivity
+{
+ @synchronized(self)
+ {
+ counter = 0;
+ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
+ }
+}
+
+@end

0 comments on commit 0ecffb0

Please sign in to comment.