Permalink
Browse files

cleaner preferences. get profilecache loaded.

  • Loading branch information...
1 parent 7d83c17 commit a9a23bd3e7a335bb29c88a54cb76662145724799 @jubishop committed May 19, 2009
Showing with 64 additions and 42 deletions.
  1. +1 −17 ApplicationBase.as
  2. +14 −8 fbair.mxml
  3. +4 −2 fbair/gui/StylePrefs.as
  4. +41 −0 fbair/util/Preferences.as
  5. +4 −15 fbair/util/ProfileCache.as
View
@@ -14,14 +14,12 @@
limitations under the License.
*/
package {
- import fb.util.Output;
import fb.util.FlexUtil;
+ import fb.util.Output;
- import flash.data.EncryptedLocalStore;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
- import flash.utils.ByteArray;
import mx.core.WindowedApplication;
@@ -50,19 +48,5 @@ package {
if (event.commandKey && event.keyCode == Keyboard.D)
Output.logDump();
}
-
- // We manage locally stored preferences with these functions
- public static function getPreference(prefName:String):Object {
- var bytes:ByteArray = EncryptedLocalStore.getItem(prefName);
- if (!bytes) return null;
- return bytes.readObject();
- }
-
- public static function setPreference(prefName:String,
- prefObject:Object):void {
- var bytes:ByteArray = new ByteArray();
- bytes.writeObject(prefObject);
- EncryptedLocalStore.setItem(prefName, bytes);
- }
}
}
View
@@ -58,10 +58,10 @@
<mx:Script><![CDATA[
import fb.FBConnect;
import fb.FBEvent;
+ import fb.util.Output;
- import fbair.gui.StylePrefs;
import fbair.util.FBUpdater;
- import fb.util.Output;
+ import fbair.util.Preferences;
import fbair.util.ProfileCache;
import flash.events.Event;
@@ -81,12 +81,15 @@
composer.enabled = false;
// If we have stored session data, let's pull it in
- var windowData:Object = getPreference("window");
+ 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())
@@ -97,14 +100,14 @@
Output.log("Loading nile/filter cached data");
// If we have cached renderer data, hit it up
- var nileCache:Object = ApplicationBase.getPreference("nileCache");
+ var nileCache:Object = Preferences.getPreference("nileCache");
if (nileCache) {
nileContainer.dataCache = nileCache;
nileContainer.updateMetadata();
}
// If we have tabs data, hit it up
- var filtersData:Object = ApplicationBase.getPreference("filters");
+ var filtersData:Object = Preferences.getPreference("filters");
if (filtersData && filtersData.data &&
filtersData.data.length > 0) {
Output.assert(nileCache != null,
@@ -239,20 +242,23 @@
// Called when the app is ending and we want to save some data
private function closing(event:Event):void {
- setPreference("window", {
+ Preferences.setPreference("window", {
x:nativeWindow.x,
y:nativeWindow.y,
height:nativeWindow.height
});
- setPreference("filters", {
+ Preferences.setPreference("filters", {
data:filtersBar.data,
tabData:filtersBar.tabData,
focusHistory:filtersBar.focusHistory,
currentTab:filtersBar.currentTab
});
- setPreference("nileCache", nileContainer.dataCache);
+ Preferences.setPreference("nileCache", nileContainer.dataCache);
+
+ // External preference holders
+ ProfileCache.closing();
}
]]></mx:Script>
</app:ApplicationBase>
View
@@ -17,6 +17,8 @@
package fbair.gui {
import fb.util.Output;
+ import fbair.util.Preferences;
+
import flash.events.Event;
import flash.filesystem.File;
@@ -47,7 +49,7 @@ package fbair.gui {
// Load preferences
private static function opening(event:FlexEvent):void {
- var styleData:Object = ApplicationBase.getPreference("styles");
+ var styleData:Object = Preferences.getPreference("styles");
// Set size
if (styleData) setSizeStyle(styleData.sizeStyle);
@@ -76,7 +78,7 @@ package fbair.gui {
// Save preferences when done
private static function closing(event:Event):void {
- ApplicationBase.setPreference("styles", {
+ Preferences.setPreference("styles", {
sizeStyle:sizeStyle
});
}
View
@@ -0,0 +1,41 @@
+/*
+ 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.
+ */
+package fbair.util {
+ import flash.data.EncryptedLocalStore;
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.utils.ByteArray;
+
+ public class Preferences {
+ public static const LOAD:String = "loadPreferences";
+ public static const UNLOAD:String = "unloadPreferences";
+
+ public static var dispatcher:EventDispatcher = new EventDispatcher();
+
+ public static function getPreference(prefName:String):Object {
+ var bytes:ByteArray = EncryptedLocalStore.getItem(prefName);
+ if (!bytes) return null;
+ return bytes.readObject();
+ }
+
+ public static function setPreference(prefName:String,
+ prefObject:Object):void {
+ var bytes:ByteArray = new ByteArray();
+ bytes.writeObject(prefObject);
+ EncryptedLocalStore.setItem(prefName, bytes);
+ }
+ }
+}
View
@@ -24,7 +24,6 @@ package fbair.util {
import flash.events.EventDispatcher;
import mx.core.Application;
- import mx.events.FlexEvent;
// This class holds a reference to all the data about
// any profile-id we've fetched.
@@ -67,22 +66,12 @@ package fbair.util {
// So that we can batch-request them at end of frame
private static var queuedRequests:Object = new Object;
- // Initializing
- private static var initialized:Boolean = initialize();
- private static function initialize():Boolean {
- Application.application.addEventListener(FlexEvent.INITIALIZE,
- opening);
- Application.application.addEventListener(Event.CLOSING,
- closing);
- return true;
- }
-
// Laod preferences
- private static function opening(event:FlexEvent):void {
+ public static function opening():void {
if (!FBUpdater.firstRun()) {
Output.log("Loading profile cache");
- var profileCache:Object = ApplicationBase.getPreference("profileCache");
+ var profileCache:Object = Preferences.getPreference("profileCache");
if (profileCache) cache = profileCache;
}
}
@@ -177,8 +166,8 @@ package fbair.util {
}
// Save preferences at end
- private static function closing(event:Event):void {
- ApplicationBase.setPreference("profileCache", cache);
+ public static function closing():void {
+ Preferences.setPreference("profileCache", cache);
}
}
}

0 comments on commit a9a23bd

Please sign in to comment.