Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: samples/github/ios/github/MainController.mm

Issue 2035023003: Remove service-compiler related code. (Closed) Base URL: git@github.com:dartino/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samples/github/ios/github/MainController.h ('k') | samples/github/ios/github/dart-logo.png » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file.
4
5 #import "MainController.h"
6 #import "CommitListPresenter.h"
7
8 #import "ImmiSamples/DrawerPresenter.h"
9 #import "ImmiSamples/LoginPresenter.h"
10 #import "ImmiSamples/MenuPresenter.h"
11 #import "ImmiSamples/SlidingWindowPresenter.h"
12
13 #import "github_mock.h"
14
15 @interface AnyNodePresenter : NSObject <ViewPresenter, NodePresenter>
16 @property CommitListPresenter* commitListPresenter;
17 @property LoginPresenter* loginPresenter;
18 @property MenuPresenter* menuPresenter;
19 @property id<ViewPresenter> currentPresenter;
20 - (id)init:(UIStoryboard*)storyboard;
21 @end
22
23 @interface LeftPresenter : NSObject <ViewPresenter, NodePresenter>
24 @property MenuPresenter* presenter;
25 - (id)init:(UIStoryboard*)storyboard;
26 @end
27
28 @interface MainController () <NodePresenter, DrawerPresenter>
29 @property ImmiRoot* immiRoot;
30 @property DrawerPresenter* drawerPresenter;
31 @property AnyNodePresenter* centerPresenter;
32 @property AnyNodePresenter* leftPresenter;
33 @property AnyNodePresenter* rightPresenter;
34 @end
35
36 @implementation AnyNodePresenter
37
38 - (id)init:(UIStoryboard*)storyboard {
39 self.commitListPresenter =
40 [storyboard instantiateViewControllerWithIdentifier:@"CommitListPresenter"];
41 self.loginPresenter =
42 [storyboard instantiateViewControllerWithIdentifier:@"LoginPresenter"];
43 self.menuPresenter =
44 [storyboard instantiateViewControllerWithIdentifier:@"MenuPresenter"];
45 return self;
46 }
47
48 - (void)presentNode:(Node*)node {
49 if ([node is:SlidingWindowNode.class]) {
50 self.currentPresenter = self.commitListPresenter;
51 [self.commitListPresenter
52 presentSlidingWindow:[node as:SlidingWindowNode.class]];
53 } else if ([node is:LoginNode.class]) {
54 self.currentPresenter = self.loginPresenter;
55 [self.loginPresenter presentLogin:[node as:LoginNode.class]];
56 } else if ([node is:MenuNode.class]) {
57 self.currentPresenter = self.menuPresenter;
58 [self.menuPresenter presentMenu:[node as:MenuNode.class]];
59 } else {
60 abort();
61 }
62 }
63
64 - (void)patchNode:(NodePatch*)patch {
65 if ([patch is:SlidingWindowPatch.class]) {
66 SlidingWindowPatch* p = [patch as:SlidingWindowPatch.class];
67 [p applyTo:self.commitListPresenter];
68 } else if ([patch is:LoginPatch.class]) {
69 LoginPatch* p = [patch as:LoginPatch.class];
70 [p applyTo:self.loginPresenter];
71 } else if ([patch is:MenuPatch.class]) {
72 MenuPatch* p = [patch as:MenuPatch.class];
73 [p applyTo:self.menuPresenter];
74 } else {
75 abort();
76 }
77 }
78
79 - (UIViewController*)viewController {
80 return [self.currentPresenter viewController];
81 }
82
83 @end
84
85 @implementation MainController
86
87 - (void)viewDidLoad {
88 [super viewDidLoad];
89
90 // Ensure that the github mock server is running.
91 // TODO(zerny): Dynamically configure the http port.
92 GithubMockServer::start(8321);
93
94 UIStoryboard* storyboard =
95 [UIStoryboard storyboardWithName:@"Main" bundle:nil];
96
97 self.centerPresenter = [[AnyNodePresenter alloc] init:storyboard];
98 self.leftPresenter = [[AnyNodePresenter alloc] init:storyboard];
99 self.rightPresenter = nil;
100
101 // Create a drawer presenter do to the interpretation work.
102 self.drawerPresenter =
103 [[DrawerPresenter alloc] initWithCenterPresenter:self.centerPresenter
104 leftPresenter:self.leftPresenter
105 rightPresenter:self.rightPresenter];
106
107 // Create the IMMI service.
108 ImmiService* immi = [[ImmiService alloc] init];
109
110 // Register a root presenter for the DrawerPresenter root.
111 self.immiRoot = [immi registerPresenter:self forName:@"DrawerPresenter"];
112
113 // Render the initial graph.
114 [self.immiRoot refresh];
115
116 // Setup some drawer properties.
117 self.shouldStretchDrawer = NO;
118
119 self.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
120
121 self.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningDrawerView |
122 MMCloseDrawerGestureModePanningCenterView |
123 MMCloseDrawerGestureModeTapCenterView;
124
125 // Monitor when the side panes close.
126 [self setDrawerVisualStateBlock:^(MMDrawerController* mySelf,
127 MMDrawerSide drawerSide,
128 CGFloat percentVisible) {
129 MainController* mainController = (MainController*)mySelf;
130 if (percentVisible == 0.0 && mainController.openSide == drawerSide) {
131 [mainController setVisibility:drawerSide visible:false];
132 }
133 }];
134 }
135
136 - (void)presentNode:(Node*)node {
137 [self presentDrawer:[node as:DrawerNode.class]];
138 }
139
140 - (void)patchNode:(NodePatch*)patch {
141 [self patchDrawer:[patch as:DrawerPatch.class]];
142 }
143
144 - (void)presentDrawer:(DrawerNode*)node {
145 [self.drawerPresenter presentDrawer:node];
146 [self performSelectorOnMainThread:@selector(presentOnMainThread:)
147 withObject:node
148 waitUntilDone:NO];
149 }
150
151 - (void)presentOnMainThread:(DrawerNode*)node {
152 self.centerViewController =
153 [self.drawerPresenter.centerPresenter viewController];
154 [self.drawerPresenter addDrawerButtons:self.centerViewController
155 leftTitle:@"menu"];
156 self.leftDrawerViewController =
157 [self.drawerPresenter.leftPresenter viewController];
158 self.rightDrawerViewController =
159 [self.drawerPresenter.rightPresenter viewController];
160 }
161
162 - (void)patchDrawer:(DrawerPatch*)patch {
163 [self.drawerPresenter patchDrawer:patch];
164 [self performSelectorOnMainThread:@selector(patchOnMainThread:)
165 withObject:patch
166 waitUntilDone:NO];
167 }
168
169 - (void)patchOnMainThread:(DrawerPatch*)patch {
170 if (patch.center.changed) {
171 self.centerViewController =
172 [self.drawerPresenter.centerPresenter viewController];
173 if (patch.center.replaced) {
174 [self.drawerPresenter addDrawerButtons:self.centerViewController];
175 }
176 }
177 if (patch.left.changed) {
178 self.leftDrawerViewController =
179 [self.drawerPresenter.leftPresenter viewController];
180 }
181 if (patch.right.changed) {
182 self.rightDrawerViewController =
183 [self.drawerPresenter.rightPresenter viewController];
184 }
185 if (patch.leftVisible.changed && patch.leftVisible.current) {
186 [self openPane:MMDrawerSideLeft];
187 } else if (patch.rightVisible.changed && patch.rightVisible.current) {
188 [self openPane:MMDrawerSideRight];
189 } else if (patch.leftVisible.changed || patch.rightVisible.changed) {
190 [self closeDrawerAnimated:YES completion:nil];
191 }
192 }
193
194 - (void)openPane:(MMDrawerSide)side {
195 if (self.openSide == side) return;
196 [self openDrawerSide:side animated:YES completion:nil];
197 }
198
199 - (void)prepareToPresentDrawer:(MMDrawerSide)drawer animated:(BOOL)animated {
200 [super prepareToPresentDrawer:drawer animated:animated];
201 [self setVisibility:drawer visible:true];
202 }
203
204 - (void)setVisibility:(MMDrawerSide)side visible:(bool)visible {
205 if (side == MMDrawerSideLeft) {
206 self.drawerPresenter.leftVisible = visible;
207 } else if (side == MMDrawerSideRight) {
208 self.drawerPresenter.rightVisible = visible;
209 }
210 }
211
212 @end
OLDNEW
« no previous file with comments | « samples/github/ios/github/MainController.h ('k') | samples/github/ios/github/dart-logo.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698