Permalink
Browse files

Styles and Profile both manage their own preferences now.

  • Loading branch information...
1 parent 3d446f0 commit 11547f87ea3265dbe1f073fa456b30e28b8c6f79 @jubishop committed May 4, 2009
Showing with 59 additions and 28 deletions.
  1. +3 −9 fbair.mxml
  2. +16 −7 fbair/gui/StylePrefs.as
  3. +40 −12 fbair/util/ProfileCache.as
View
@@ -94,11 +94,7 @@
// Load old data only if we didn't just autoupdate
// Between updates our data model might change...
else {
- Output.log("Loading cached data");
-
- // Load our profile data.
- var profileCache:Object = getPreference("profileCache");
- if (profileCache) ProfileCache.cache = profileCache;
+ Output.log("Loading nile/filter cached data");
// If we have cached renderer data, hit it up
var nileCache:Object = ApplicationBase.getPreference("nileCache");
@@ -217,11 +213,11 @@
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);
@@ -256,8 +252,6 @@
});
setPreference("nileCache", nileContainer.dataCache);
-
- setPreference("profileCache", ProfileCache.cache);
}
]]></mx:Script>
</app:ApplicationBase>
@@ -15,13 +15,15 @@
*/
// Global manager of style prefs.
package fbair.gui {
+ import fb.util.Output;
+
import flash.events.Event;
import flash.filesystem.File;
- import mx.events.FlexEvent;
-
+
import mx.core.Application;
+ import mx.events.FlexEvent;
import mx.styles.StyleManager;
- import fbair.util.StringUtil;
+
// We hold style prefs here of the user
public class StylePrefs {
// We use these constants to represent dynamic css resources
@@ -31,16 +33,19 @@ package fbair.gui {
public static const SIZE_SMALL:String =
"fbair/styles/bin/size_small.css.swf";
- [Bindable] public static var sizeStyle:String = '';
+ [Bindable] public static var sizeStyle:String;
+ // Initializing
private static var initialized:Boolean = initialize();
private static function initialize():Boolean {
- Application.application.addEventListener(FlexEvent.APPLICATION_COMPLETE,
+ Application.application.addEventListener(FlexEvent.INITIALIZE,
opening);
Application.application.addEventListener(Event.CLOSING,
closing);
return true;
}
+
+ // Load preferences
private static function opening(event:FlexEvent):void {
var styleData:Object = ApplicationBase.getPreference("styles");
@@ -51,9 +56,12 @@ package fbair.gui {
public static function setSizeStyle(to:String):void {
if (sizeStyle == to) return;
+ if (!to) to = SIZE_LARGE;
+
+ Output.log("Setting style size: " + to);
// Unload old style size
- if (!StringUtil.empty(sizeStyle)) {
+ if (sizeStyle) {
var resourcePath:String = File.applicationDirectory
.resolvePath(sizeStyle).url;
StyleManager.unloadStyleDeclarations(resourcePath, false);
@@ -66,9 +74,10 @@ package fbair.gui {
StyleManager.loadStyleDeclarations(resourcePath);
}
+ // Save preferences when done
private static function closing(event:Event):void {
ApplicationBase.setPreference("styles", {
- sizeStyle:StylePrefs.sizeStyle
+ sizeStyle:sizeStyle
});
}
}
@@ -14,15 +14,6 @@
limitations under the License.
*/
package fbair.util {
-
- import fb.FBAPI;
- import fb.FBEvent;
-
- import flash.events.Event;
- import flash.events.EventDispatcher;
-
- import mx.core.Application;
-
// This class holds a reference to all the data about
// any profile-id we've fetched.
//
@@ -50,11 +41,23 @@ package fbair.util {
// trace("My profile pic is at : " + event.data.pic_square);
// });
public class ProfileCache {
+ import fb.FBAPI;
+ import fb.FBEvent;
+ import fb.util.Output;
+
+ import fbair.util.FBUpdater;
+
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+
+ import mx.core.Application;
+ import mx.events.FlexEvent;
+
public static const PROFILE_FETCHED:String = "profileFetched";
// How long till our profile data is "old"
private static const MaxProfileAge:int = 86400; // One day
-
+
// Contains all the Profile objects already fetched.
// key => profileID
// value => {id, name, pic_square, url}
@@ -64,9 +67,29 @@ 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 {
+ if (!FBUpdater.firstRun()) {
+ Output.log("Loading profile cache");
+
+ var profileCache:Object = ApplicationBase.getPreference("profileCache");
+ if (profileCache) cache = profileCache;
+ }
+ }
+
// Simply tells us whether given profileID is already cached
public static function hasProfile(profileID:String):Boolean {
- return cache.hasOwnProperty(profileID) &&
+ return cache.hasOwnProperty(profileID) &&
(new Date().time / 1000) - cache[profileID].time < MaxProfileAge;
}
@@ -119,7 +142,7 @@ package fbair.util {
var uncached_ids:Array = new Array();
for (var uncached_request_id:String in uncached_requests)
uncached_ids.push(uncached_request_id);
-
+
// If we have some uncached, then request them from the server.
if (uncached_ids.length > 0) {
FBAPI.callMethod("fql.query", {
@@ -152,5 +175,10 @@ package fbair.util {
// Clear our list of queued requests now that we're done
queuedRequests = new Object();
}
+
+ // Save preferences at end
+ private static function closing(event:Event):void {
+ ApplicationBase.setPreference("profileCache", cache);
+ }
}
}

0 comments on commit 11547f8

Please sign in to comment.