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