Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 266 lines (222 sloc) 9.48 kb
57f38e4 @jubishop Going live.
authored
1 <!--
2 Copyright Facebook Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 -->
16 <app:ApplicationBase xmlns:app="*"
17 xmlns:mx="http://www.adobe.com/2006/mxml"
18 xmlns:nile="fbair.nile.*"
19 xmlns:composer="fbair.composer.*"
20 xmlns:gui="fbair.gui.*"
21 xmlns:filters="fbair.gui.filters.*"
22 applicationComplete="applicationComplete(event)"
23 closing="closing(event)" >
24
25 <mx:Style source="fbair/styles/global.css" />
26 <mx:Style source="fbair/styles/composer.css" />
27 <mx:Style source="fbair/styles/nile.css" />
28 <mx:Style source="fbair/styles/renderers.css" />
29 <mx:Style source="fbair/styles/filters.css" />
30
31 <!-- We arrange elements in this fashion so that the appHeader is always
32 on top. Because Flex's layout order is directly linked to its depth.
33 the NileContainer binds its top offset to the appHeader's height
34 to simulate being part of the VBox while still be 'under' it's depth -->
35 <nile:NileContainer id="nileContainer"
36 width="100%"
37 height="100%"
38 top="{appHeader.height}" />
39
40 <!-- The appHeader contains elements that are always on top of the app -->
41 <mx:VBox id="appHeader"
42 width="100%" >
43 <gui:LoadingIndicator id="loader"
44 width="100%"
45 animateIn="false" />
46
47 <filters:FiltersBar id="filtersBar"
48 width="100%"
49 tabAdded="filterTabAdded(event)"
50 tabRemoved="filterTabRemoved(event)"
51 tabFocused="filterTabFocused(event)" />
52
53 <composer:Composer id="composer"
54 width="100%"
55 statusUpdated="statusUpdated(event)" />
56 </mx:VBox>
57
58 <mx:Script><![CDATA[
59 import fb.FBConnect;
60 import fb.FBEvent;
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
61 import fb.util.Output;
57f38e4 @jubishop Going live.
authored
62
63 import fbair.util.FBUpdater;
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
64 import fbair.util.Preferences;
57f38e4 @jubishop Going live.
authored
65 import fbair.util.ProfileCache;
66
67 import flash.events.Event;
68
69 import mx.core.Application;
70 import mx.core.Container;
71 import mx.events.FlexEvent;
72
73 // We don't request things multiple times, we just give up
74 private var requiredSession:Boolean = false;
75 private var requiredPermissions:Boolean = false;
76
77 // Called when our app is initialized...
78 // The first thing to do is authorize our application..
79 private function applicationComplete(event:FlexEvent):void {
57219f8 @jubishop Added comment explaining why Composer begins disabled.
authored
80 // Don't enable our composer until we're authorized
57f38e4 @jubishop Going live.
authored
81 composer.enabled = false;
82
83 // If we have stored session data, let's pull it in
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
84 var windowData:Object = Preferences.getPreference("window");
57f38e4 @jubishop Going live.
authored
85 if (windowData) {
86 nativeWindow.x = windowData.x;
87 nativeWindow.y = windowData.y;
88 nativeWindow.height = windowData.height;
89 }
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
90
91 // Trigger the load of anything else preferences wise
92 ProfileCache.opening();
57f38e4 @jubishop Going live.
authored
93
94 // If we just updated, let's delete our autoupdate file
95 if (FBUpdater.firstRun())
96 FBUpdater.deleteInstallationFile();
7418d80 @jubishop simpler.
authored
97 // Load FiltersBar and NileContainer here, since they need
98 // parental supervision to keep things in order...
57f38e4 @jubishop Going live.
authored
99 else {
11547f8 @jubishop Styles and Profile both manage their own preferences now.
authored
100 Output.log("Loading nile/filter cached data");
57f38e4 @jubishop Going live.
authored
101
102 // If we have cached renderer data, hit it up
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
103 var nileCache:Object = Preferences.getPreference("nileCache");
57f38e4 @jubishop Going live.
authored
104 if (nileCache) {
105 nileContainer.dataCache = nileCache;
106 nileContainer.updateMetadata();
107 }
108
109 // If we have tabs data, hit it up
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
110 var filtersData:Object = Preferences.getPreference("filters");
7418d80 @jubishop simpler.
authored
111 if (filtersData &&
112 filtersData.data &&
19f95f9 @jubishop Depot in place and used by NileRenderer. Needs a lot of work. Will bre...
authored
113 filtersData.data.length > 0) {
cabf65a @jubishop 1) Since we're always keeping niles in the display tree and just flippin...
authored
114 Output.assert(nileCache != null,
115 "We have a filter cache but not a nile cache?!");
116
57f38e4 @jubishop Going live.
authored
117 // Set nile stuff first to prepare for events
01e6fdb psych, that lives just fine as an Object
Lee Byron authored
118 var stream_filters:Object = new Object();
57f38e4 @jubishop Going live.
authored
119 for each (var tab:Object in filtersData.tabData)
01e6fdb psych, that lives just fine as an Object
Lee Byron authored
120 stream_filters[tab.filter_key] = true;
57f38e4 @jubishop Going live.
authored
121 nileContainer.loadInitialFilters(stream_filters);
122
123 // Now set filtersBar and we're off and running
124 filtersBar.focusHistory = filtersData.focusHistory;
125 filtersBar.tabData = filtersData.tabData;
126 filtersBar.data = filtersData.data;
127 filtersBar.currentTab = filtersData.currentTab;
128 }
129 }
cabf65a @jubishop 1) Since we're always keeping niles in the display tree and just flippin...
authored
130
57f38e4 @jubishop Going live.
authored
131 // We want to listen to changes to status or permissions,
132 // so let's add event listeners for both.
133 FBConnect.dispatcher.addEventListener(FBEvent.STATUS_CHANGED,
134 statusChanged);
135 FBConnect.dispatcher.addEventListener(FBEvent.PERMISSION_CHANGED,
136 permissionChanged);
137 FBConnect.dispatcher.addEventListener(FBEvent.ALERT,
138 applicationAlert);
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
139 FBConnect.dispatcher.addEventListener(FBEvent.ERROR,
140 applicationError);
141 FBConnect.dispatcher.addEventListener(FBEvent.RESOLVED,
142 applicationResolved);
57f38e4 @jubishop Going live.
authored
143
144 // Now we call this to init our application.
145 // Always call this only once, in the applicationComplete callback.
146 FBConnect.init('39f0aec9479177cddacef90da714b037');
147
148 // This function checks to see if we're already connected
149 statusChanged();
150 }
151
152 // Checks our status and requires Session if we're not connected.
153 private function statusChanged(event:FBEvent = null):void {
154 // If we're already connected then let's move on to extended permissions
155 if (FBConnect.status == FBConnect.Connected)
156 connected();
157 // If we already tried requiring session, then give up
158 else if (requiredSession)
159 close();
160 // If we're not connected then we need to call FBConnect.requireSession()
161 // This is the function you should call to authorize your app.
162 else if (FBConnect.status == FBConnect.NotLoggedIn) {
163 requiredSession = true;
164 requiredPermissions = false;
165 FBConnect.requireSession();
166 }
167 }
168
169 // Once connected we want to check on our permissions
170 private function connected():void {
171 permissionChanged();
172 }
173
174 // This function checks our permissions and calls requirePermission.
175 // FBConnect.requirePermission(permission_name) is the way to
176 // acquire extended permissions.
177 private function permissionChanged(event:FBEvent = null):void {
178 if (FBConnect.hasPermission("read_stream") &&
179 FBConnect.hasPermission("publish_stream"))
180 fullyAuthorized();
181 else if (requiredPermissions)
182 close();
183 else {
184 requiredSession = false;
185 requiredPermissions = true;
186 FBConnect.requirePermissions(["read_stream", "publish_stream"]);
187 }
188 }
189
190 // Now fully authorized, we'll display our content
191 // And begin polling.
192 // We'll also check for any updates to ourself
193 private function fullyAuthorized():void {
194 // Allow loader to display what we expect in the future
195 loader.loadStatus("Connecting to Facebook");
196
197 // Allow Composing
198 composer.enabled = true;
199
200 // Fetch filters
201 filtersBar.fetchFilters();
202
203 // Begin polling
204 nileContainer.beginPolling();
205
206 // Autoupdating ftw
207 FBUpdater.saveVersionToFile();
208 FBUpdater.checkForNewVersion();
209 }
210
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
211 // Global alerts
57f38e4 @jubishop Going live.
authored
212 private function applicationAlert(event:FBEvent):void {
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
213 loader.loadStatus(event.data);
57f38e4 @jubishop Going live.
authored
214 }
215
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
216 private function applicationError(event:FBEvent):void {
217 loader.errorStatus(event.data.text,
218 event.data.callback,
219 event.data.hide);
220 }
11547f8 @jubishop Styles and Profile both manage their own preferences now.
authored
221
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
222 private function applicationResolved(event:FBEvent):void {
223 loader.close();
224 }
11547f8 @jubishop Styles and Profile both manage their own preferences now.
authored
225
57f38e4 @jubishop Going live.
authored
226 // Called when the composer has added a status update!
227 private function statusUpdated(event:FBEvent):void {
228 nileContainer.addStatusMessage(event.data);
229 }
230
e412bd6 @jubishop Isolating fb/ so that it needs nothing in fbair/ for reusability.
authored
231 // Filter tab switching
57f38e4 @jubishop Going live.
authored
232 private function filterTabAdded(event:FBEvent):void {
233 nileContainer.filterAdded(event.data);
234 }
235
236 private function filterTabRemoved(event:FBEvent):void {
237 nileContainer.filterRemoved(event.data);
238 }
239
240 private function filterTabFocused(event:FBEvent):void {
241 nileContainer.filterSelected(event.data);
242 }
243
244 // Called when the app is ending and we want to save some data
245 private function closing(event:Event):void {
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
246 Preferences.setPreference("window", {
57f38e4 @jubishop Going live.
authored
247 x:nativeWindow.x,
248 y:nativeWindow.y,
249 height:nativeWindow.height
250 });
251
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
252 Preferences.setPreference("filters", {
57f38e4 @jubishop Going live.
authored
253 data:filtersBar.data,
254 tabData:filtersBar.tabData,
255 focusHistory:filtersBar.focusHistory,
256 currentTab:filtersBar.currentTab
257 });
258
a9a23bd @jubishop cleaner preferences. get profilecache loaded.
authored
259 Preferences.setPreference("nileCache", nileContainer.dataCache);
260
261 // External preference holders
262 ProfileCache.closing();
57f38e4 @jubishop Going live.
authored
263 }
264 ]]></mx:Script>
265 </app:ApplicationBase>
Something went wrong with that request. Please try again.