Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

... Making things meaningful: Part II

  • Loading branch information...
commit 40cad4752831be4aaee6aeaf5a0307cbff026351 1 parent 88faa5c
@Tumunu authored
View
10 Classes/Controllers/NavViewController.h
@@ -1,5 +1,5 @@
//
-// RootNavViewController.h
+// NavViewController.h
// iPortal
//
// Created by Cleave Pokotea on 14/05/09.
@@ -7,7 +7,7 @@
//
#import <UIKit/UIKit.h>
-#import "PortalViews.h"
+#import "PortalViewsMediator.h"
#import "PortalFeeds.h"
@@ -19,13 +19,13 @@
@end
-@interface RootNavViewController : UIViewController
+@interface NavViewController : UIViewController
{
UIImageView *backgroundImage;
CustomAlertViewController *customAlertViewController;
PortalFeeds *portalFeeds;
- PortalViews *portalViews;
+ PortalViewsMediator *PortalViewsMediator;
id<RootNavDelegate> delegate;
}
@@ -33,7 +33,7 @@
@property (nonatomic, retain) UIImageView *backgroundImage;
@property (nonatomic, retain) CustomAlertViewController *customAlertViewController;
@property (nonatomic, retain) PortalFeeds *portalFeeds;
-@property (nonatomic, retain) PortalViews *portalViews;
+@property (nonatomic, retain) PortalViewsMediator *PortalViewsMediator;
@property (nonatomic, assign) id <RootNavDelegate> delegate;
- (id)initWithFeed:(PortalFeeds *)portalFeeds;
View
20 Classes/Controllers/NavViewController.m
@@ -1,5 +1,5 @@
//
-// RootNavViewController.m
+// NavViewController.m
// iPortal
//
// Created by Cleave Pokotea on 14/05/09.
@@ -8,17 +8,17 @@
#import <QuartzCore/QuartzCore.h>
#import "iPortalAppDelegate.h"
-#import "RootNavViewController.h"
+#import "NavViewController.h"
#import "PortalFeeds.h"
-#import "PortalViews.h"
+#import "PortalViewsMediator.h"
-@implementation RootNavViewController
+@implementation NavViewController
@synthesize backgroundImage;
@synthesize customAlertViewController;
@synthesize portalFeeds;
-@synthesize portalViews;
+@synthesize PortalViewsMediator;
@synthesize delegate;
@@ -32,7 +32,7 @@ - (void)dealloc
}
[portalFeeds release];
- [portalViews release];
+ [PortalViewsMediator release];
[super dealloc];
}
@@ -57,7 +57,7 @@ - (void)viewDidLoad
[self setBackgroundImage];
[super viewDidLoad];
- portalViews = [[PortalViews alloc] init];
+ PortalViewsMediator = [[PortalViewsMediator alloc] init];
// Should also be placed elsewhere but pfft...
if(![portalFeeds checkIsDataSourceAvailable])
@@ -81,7 +81,7 @@ - (IBAction)showNews
[iPortalAppDelegate playEffect:kEffectButton];
[self.delegate rootNavHide];
- [portalViews switchView:[[self view] superview] whatView:kNews withFeed:[portalFeeds.localNewsFeed copy]];
+ [PortalViewsMediator switchView:[[self view] superview] whatView:kNews withFeed:[portalFeeds.localNewsFeed copy]];
}
- (IBAction)showVideo
@@ -90,7 +90,7 @@ - (IBAction)showVideo
[iPortalAppDelegate playEffect:kEffectButton];
[self.delegate rootNavHide];
- [portalViews switchView:[[self view] superview] whatView:kVideo withFeed:[portalFeeds.localVideoFeed copy]];
+ [PortalViewsMediator switchView:[[self view] superview] whatView:kVideo withFeed:[portalFeeds.localVideoFeed copy]];
}
- (IBAction)showAudio
@@ -99,7 +99,7 @@ - (IBAction)showAudio
[iPortalAppDelegate playEffect:kEffectButton];
[self.delegate rootNavHide];
- [portalViews switchView:[[self view] superview] whatView:kAudio withFeed:[portalFeeds.localAudioFeed copy]];
+ [PortalViewsMediator switchView:[[self view] superview] whatView:kAudio withFeed:[portalFeeds.localAudioFeed copy]];
}
#pragma mark -
View
23 Classes/Controllers/PortalViewsMediator.h
@@ -1,5 +1,5 @@
//
-// PortalViews.h
+// PortalViewsMediator.h
// iPortal
//
// Created by Cleave Pokotea on 9/09/11.
@@ -7,11 +7,13 @@
//
#import <Foundation/Foundation.h>
+#import "RootViewController.h"
#import "NewsViewController.h"
#import "VideoViewController.h"
#import "AudioViewController.h"
#import "CustomAlertViewController.h"
+
enum ViewType
{
kNews=0,
@@ -20,18 +22,29 @@ enum ViewType
kNumViewTypes
};
-@interface PortalViews : NSObject
+
+@interface PortalViewsMediator : NSObject
{
+ @private
+ RootViewController *rootViewController;
NewsViewController *newsViewController;
VideoViewController *videoViewController;
AudioViewController *audioViewController;
+
+ UIViewController *currentViewController;
}
-@property (nonatomic, retain)NewsViewController *newsViewController;
-@property (nonatomic, retain)VideoViewController *videoViewController;
-@property (nonatomic, retain)AudioViewController *audioViewController;
+
+@property (nonatomic, readonly)RootViewController *rootViewController;
+@property (nonatomic, readonly)NewsViewController *newsViewController;
+@property (nonatomic, readonly)VideoViewController *videoViewController;
+@property (nonatomic, readonly)AudioViewController *audioViewController;
+@property (nonatomic, readonly)UIViewController *currentViewController;
- (void)switchView:(UIView *)currentView whatView:(int)nextView withFeed:(NSArray *)feed;
+// Necessary evil
++ (PortalViewsMediator *)sharedInstance;
+
@end
View
89 Classes/Controllers/PortalViewsMediator.m
@@ -1,5 +1,5 @@
//
-// PortalViews.m
+// PortalViewsMediator.m
// iPortal
//
// Created by Cleave Pokotea on 9/09/11.
@@ -7,30 +7,36 @@
//
#import <QuartzCore/QuartzCore.h>
-#import "PortalViews.h"
+#import "PortalViewsMediator.h"
-@implementation PortalViews
+@interface PortalViewsMediator ()
+- (void)initialize;
+@end
+
+
+@implementation PortalViewsMediator
-- (id)init
-{
- if ((self = [super init]) != NULL)
- {
- // Yes I know this shouldn't be here
- newsViewController = [[NewsViewController alloc] init];
- videoViewController = [[VideoViewController alloc] init];
- audioViewController = [[AudioViewController alloc] init];
- }
- return(self);
-}
-- (void)dealloc
+@synthesize rootViewController;
+@synthesize newsViewController;
+@synthesize videoViewController;
+@synthesize audioViewController;
+@synthesize currentViewController;
+
+static PortalViewsMediator *sharedMediator = nil;
+
+- (void)initialize
{
- [newsViewController release];
- [videoViewController release];
- [audioViewController release];
+ rootViewController = [[rootViewController alloc] init];
+ newsViewController = [[NewsViewController alloc] init];
+ videoViewController = [[VideoViewController alloc] init];
+ audioViewController = [[AudioViewController alloc] init];
+ currentViewController = rootViewController;
}
+
+
/*
Switch View
@@ -43,13 +49,13 @@ - (void)switchView:(UIView *)currentView whatView:(int)nextView withFeed:(NSArra
switch(nextView)
{
- case 1:
+ case kNews:
[currentView insertSubview:[newsViewController view] atIndex:1];
break;
- case 2:
+ case kVideo:
[currentView insertSubview:[videoViewController view] atIndex:1];
break;
- case 3:
+ case kAudio:
[currentView insertSubview:[audioViewController view] atIndex:1];
break;
}
@@ -83,4 +89,45 @@ - (void)showAlert
self.customAlertViewController.view.alpha = 1.0;
[UIView commitAnimations];
}
+
+
++ (PortalViewsMediator *)sharedInstance
+{
+ if (sharedMediator == nil)
+ {
+ sharedInstance = [[super allocWithZone:NULL] init];
+ [sharedMediator initialize];
+ }
+
+ return sharedMediator;
+}
+
++ (id) allocWithZone:(NSZone *)zone
+{
+ return [[self sharedInstance] retain];
+}
+
+- (id) copyWithZone:(NSZone*)zone
+{
+ return self;
+}
+
+- (id) retain
+{
+ return self;
+}
+
+- (NSUInteger) retainCount
+{
+ return NSUIntegerMax;
+}
+
+- (void) release
+{}
+
+- (id) autorelease
+{
+ return self;
+}
+
@end
Please sign in to comment.
Something went wrong with that request. Please try again.