Skip to content
Browse files

Switch to version 2 of foursquare API; UI changes; added nearby speci…

…als and where have i been features; fixed a million bugs and probably created some new ones
  • Loading branch information...
1 parent 9a05e0c commit e1495e9d257ec24e28b3c779b92978feadd4ac43 @zhephree zhephree committed
Showing with 11,209 additions and 0 deletions.
  1. +1 −0 1.2 log.txt
  2. BIN 1293560716_camera.psd
  3. +9 −0 2.0 log
  4. BIN 4sq-login-scene.psd
  5. +12 −0 Foursquare 20-54-06/.project
  6. +5 −0 Foursquare 20-54-06/app/assistants/stage-assistant.js
  7. +9 −0 Foursquare 20-54-06/appinfo.json
  8. +19 −0 Foursquare 20-54-06/index.html
  9. +5 −0 Foursquare 20-54-06/sources.json
  10. +1 −0 Foursquare 20-54-06/stylesheets/foursquare.css
  11. +2 −0 Foursquare-v1-api/.gitignore
  12. +12 −0 Foursquare-v1-api/.project
  13. BIN Foursquare-v1-api/SPLASH_boy_transparent.png
  14. +1 −0 Foursquare-v1-api/Untitled.html
  15. +59 −0 Foursquare-v1-api/app/assistants/about-assistant.js
  16. +117 −0 Foursquare-v1-api/app/assistants/add-tip-dialog-assistant.js
  17. +617 −0 Foursquare-v1-api/app/assistants/add-venue-assistant.js
  18. +76 −0 Foursquare-v1-api/app/assistants/add-venue-map-assistant.js
  19. +831 −0 Foursquare-v1-api/app/assistants/app-assistant (original).js
  20. +1,514 −0 Foursquare-v1-api/app/assistants/app-assistant-old.js
  21. +835 −0 Foursquare-v1-api/app/assistants/app-assistant.js
  22. +195 −0 Foursquare-v1-api/app/assistants/categories-assistant.js
  23. +105 −0 Foursquare-v1-api/app/assistants/check-in-dialog-assistant.js
  24. +681 −0 Foursquare-v1-api/app/assistants/checkin-assistant.js
  25. +389 −0 Foursquare-v1-api/app/assistants/checkin-result-assistant.js
  26. +130 −0 Foursquare-v1-api/app/assistants/contact-assistant.js
  27. +139 −0 Foursquare-v1-api/app/assistants/dashboard-assistant.js
  28. +98 −0 Foursquare-v1-api/app/assistants/do-checkin-dialog-assistant.js
  29. +109 −0 Foursquare-v1-api/app/assistants/do-shout-dialog-assistant.js
  30. +116 −0 Foursquare-v1-api/app/assistants/dupe-venue-assistant.js
  31. +131 −0 Foursquare-v1-api/app/assistants/flickr-auth-assistant.js
  32. +419 −0 Foursquare-v1-api/app/assistants/flickr-upload-assistant.js
  33. +71 −0 Foursquare-v1-api/app/assistants/friend-search-dialog-assistant.js
  34. +544 −0 Foursquare-v1-api/app/assistants/friends-list-assistant.js
  35. +356 −0 Foursquare-v1-api/app/assistants/friends-map-assistant.js
  36. +40 −0 Foursquare-v1-api/app/assistants/help-assistant.js
  37. +107 −0 Foursquare-v1-api/app/assistants/leaderboard-assistant.js
  38. +316 −0 Foursquare-v1-api/app/assistants/main-assistant.js
  39. +178 −0 Foursquare-v1-api/app/assistants/meta-list-assistant.js
  40. +470 −0 Foursquare-v1-api/app/assistants/nearby-tips-assistant.js
  41. +1,113 −0 Foursquare-v1-api/app/assistants/nearby-venues-assistant.js
  42. +313 −0 Foursquare-v1-api/app/assistants/nearby-venues-map-assistant.js
  43. +300 −0 Foursquare-v1-api/app/assistants/photos-assistant.js
  44. +526 −0 Foursquare-v1-api/app/assistants/preferences-assistant.js
  45. +238 −0 Foursquare-v1-api/app/assistants/recommend-assistant.js
Sorry, we could not display the entire diff because too many files (500) changed.
View
1 1.2 log.txt
@@ -0,0 +1 @@
+search now does livesearch as you type; fixed display bug in nearby venues list; fixed a bug that incorrectly said you unlocked a mayor special if you checked into another venue that you actually were the mayor of; fixed a bug that showed the search field if you tapped the gesture area or swiped back; added forward swipe gesture to refresh nearby venues and friends' checkins a la Bad Kitty; can now attach videos to check-ins and shouts; extended log-in timeout to 15 seconds instead of 10; supports setting ringtone from Free Music Ringtones app; added ability to launch venues from a url or venue ID by passing them as launchParams; added character counter below shout and checkin text fields; photohost list on shout and checkin now remember last host selected; User twitter profiles can be opened in Bad Kitty, TweetMe, or web browser; fixed a bug where after adding a tip, venue info items would repopulate; GPS accuracy slider preference now correctly shows its setting when initially launching preference dialog; GPS accuracy slider preference now shows value while slider and not just when sliding is finished; fixed a bug that would prevent login if you changed your password; twitter links that g to web browser now open in mobile.twitter.com (nicer) instead of m.twitter.com; tapping a nearby special now opens that venue's detail scene; app reports stats to Metrix; created AJAX wrapper functions that trap server errors and siplay messages accordingly; if user unchecks Show Your Friends checkbox, app now unselects Share with Twitter and Facebook; changed wording on Duplicate Venue error to be less confusing; fixed double special bug; fixed live search to not do 3 http requests when pressing enter; tips and todos are now tabbed instead of being in one list; when adding a venue, you can now search Google for the address; friend requests are now displayed in the navigation menu; added preference to opt-out of metrix statistics sending; tapping the foursquare logo scrolls the scene back to the top; added preference to let dashbopard notifications autoclose after a user-defined amount of time; fixed 0m Accuracy GPS bug; removed old buttons from nav header; restored tappability to Better Accuracy Refresh button; back gesture now moves though Category picker tree; LiveSearch is now after 2 characters and the delay is shorter; when swiping back during a photoupload on a checkin or shout, a warning asks if you'd like to cancel the upload and checkin or shout; banner notification when upload starts now refers to Media instead of Photo; User Info scenes now use commandmenu buttons instead of tabs; created templates for Who's Here list of users and looks nicer and cleaner; venue detail commands are now command buttons and not tabs; tips on venue detail now shows time created; tips on venue detail is cleaned up; seraching google now fills in venue phone number when addign a venue; resolved 0m accuracy bug; better pinch and squeeze zoom on maps; when adding a new venue, users can adjust the lat, long of the venue by tapping on a google map; tapping icons on friend and venue maps actualy shows info window; empty tips and todos lists now let the suer know that there aren't any items; empty tips on venue detail now alerts user in a friendlier way; added icon next to friend requests in navmenu; fixed a bug on Pixi where tapping a badge on another suer's profile, the tooltip would be udner the commandmenu and unreadable; badges look like stickers; when editing a venue, dialog inputs previous category and icon; tapping refresh button after performing a venue search now simply reloads nearby venues instead of grabbing new location; loading hsitory or friends on user profile now scrolls back to the top of the scene;
View
BIN 1293560716_camera.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
9 2.0 log
@@ -0,0 +1,9 @@
+foursquare "2.0" changelog
+tapping a tag in venue detail scene pops the scene and performs a search for the tag;
+added venue search support in Just Type;
+add JT Quick Action to send a shout;
+removed unused images from package;
+rewrote most of the AppAssistant for speed;
+removed lots of comments and useless code;
+VenueDetail: shows badge showing number of tips and people checked-in on command menu;
+User-facing references to TweetPhoto changed to Plixi;
View
BIN 4sq-login-scene.psd
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 Foursquare 20-54-06/.project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Foursquare</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.palm.pdt.nature</nature>
+ </natures>
+</projectDescription>
View
5 Foursquare 20-54-06/app/assistants/stage-assistant.js
@@ -0,0 +1,5 @@
+function StageAssistant() {
+}
+
+StageAssistant.prototype.setup = function() {
+}
View
9 Foursquare 20-54-06/appinfo.json
@@ -0,0 +1,9 @@
+{
+ "id": "com.zhephree.foursquare",
+ "version": "1.0.0",
+ "vendor": "Zhephree",
+ "type": "web",
+ "main": "index.html",
+ "title": "Foursquare",
+ "icon": "icon.png"
+}
View
19 Foursquare 20-54-06/index.html
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+<head>
+ <title>Foursquare</title>
+ <script src="/usr/palm/frameworks/mojo/mojo.js" type="text/javascript" x-mojo-version="1" />
+
+ <!-- application stylesheet should come in after the one loaded by the framework -->
+ <link href="stylesheets/foursquare.css" media="screen" rel="stylesheet" type="text/css" />
+</head>
+<body>
+ <h2>This text verifies your application is running.</h2>
+ <p>
+ To create a fully functional Palm application create a scene and remove this text from index.html.
+ See the documentation on Palm Applications for more information on creating applications and scenes.
+ </p>
+</body>
+</html>
View
5 Foursquare 20-54-06/sources.json
@@ -0,0 +1,5 @@
+[
+ {
+ "source": "app\/assistants\/stage-assistant.js"
+ }
+]
View
1 Foursquare 20-54-06/stylesheets/foursquare.css
@@ -0,0 +1 @@
+/* Put Application specific CSS here. */
View
2 Foursquare-v1-api/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+*.ipk
View
12 Foursquare-v1-api/.project
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Foursquare</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ </buildSpec>
+ <natures>
+ <nature>com.palm.pdt.nature</nature>
+ </natures>
+</projectDescription>
View
BIN Foursquare-v1-api/SPLASH_boy_transparent.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1 Foursquare-v1-api/Untitled.html
@@ -0,0 +1 @@
+<span style="color: #1f1f1f; font-size: 10pt; -webkit-border-image: url(images/menu-badge.png) 0 10 0 10 round !important; border-width: 10px;">3</span>
View
59 Foursquare-v1-api/app/assistants/about-assistant.js
@@ -0,0 +1,59 @@
+function AboutAssistant() {
+ if(_globals.debugMode){
+ this.debugTaps=0;
+ }else{
+ this.debugTaps=0;
+ }
+}
+
+AboutAssistant.prototype.setup = function() {
+ this.controller.get("about-header").innerHTML="ABOUT FOURSQUARE v"+Mojo.appInfo.version;
+// this.controller.get("about-main").style.background="#1e1e1e url(images/darker-bg.png) repeat left top";
+ //zBar.hideToolbar();
+ this.controller.document.getElementsByTagName("body")[0].style.background="url(../images/grey-bg.png) top left";
+ NavMenu.setup(this,{buttons:'empty'});
+
+ this.handleDebugTapBound=this.handleDebugTap.bind(this);
+ Mojo.Event.listen(this.controller.get("legal-head"),Mojo.Event.hold,this.handleDebugTapBound);
+
+
+ if(_globals.debugMode){this.controller.get("legal-head").innerHTML+="debug";}
+}
+AboutAssistant.prototype.getUA = function(event) {
+ var request = new Ajax.Request("http://zhephree.com/foursquare/ua.php", {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:auth,"User-Agent":"tetsing user agent"},
+ onSuccess: this.yay.bind(this)
+ });
+
+}
+
+AboutAssistant.prototype.handleDebugTap = function(event){
+ var str="debug";
+ if(!_globals.debugMode){
+ _globals.debugMode=true;
+ Mojo.Controller.getAppController().showBanner("Debug Mode enabled!", {source: 'notification'});
+ }else{
+ _globals.debugMode=false;
+ Mojo.Controller.getAppController().showBanner("Debug Mode disabled!", {source: 'notification'});
+ }
+};
+
+AboutAssistant.prototype.yay = function(event) {
+ logthis(event.responseText);
+}
+AboutAssistant.prototype.activate = function(event) {
+}
+
+
+AboutAssistant.prototype.deactivate = function(event) {
+}
+
+AboutAssistant.prototype.cleanup = function(event) {
+ /* this function should do any cleanup needed before the scene is destroyed as
+ a result of being popped off the scene stack */
+ // zBar.showToolbar();
+ Mojo.Event.stopListening(this.controller.get("legal-head"),Mojo.Event.tap,this.handeDebugTapBound);
+
+}
View
117 Foursquare-v1-api/app/assistants/add-tip-dialog-assistant.js
@@ -0,0 +1,117 @@
+function AddTipDialogAssistant(sceneAssistant,a,vid,t) {
+ this.sceneAssistant = sceneAssistant;
+ this.auth=a;
+ this.vid=vid;
+ this.type=t;
+}
+AddTipDialogAssistant.prototype.setup = function(widget) {
+ this.widget = widget;
+
+ // Setup button and event handler
+ this.sceneAssistant.controller.setupWidget("tipokButton",
+ this.attributes = {type : Mojo.Widget.activityButton},
+ this.OKButtonModel = {
+ buttonLabel: "Add",
+ disabled: false
+ }
+ );
+ this.tipokTappedBound=this.tipokTapped.bindAsEventListener(this);
+
+ this.sceneAssistant.controller.setupWidget("cancelButton",
+ this.cancelattributes = {},
+ this.CancelButtonModel = {
+ buttonLabel: "Nevermind",
+ disabled: false
+ }
+ );
+
+ this.cancelTappedBound=this.cancelTapped.bindAsEventListener(this);
+
+ this.tipKeyPressBound=this.tipKeyPress.bindAsEventListener(this);
+
+
+ Mojo.Event.listen(this.sceneAssistant.controller.get('tipokButton'), Mojo.Event.tap, this.tipokTappedBound);
+ Mojo.Event.listen(this.sceneAssistant.controller.get('cancelButton'), Mojo.Event.tap, this.cancelTappedBound);
+ Mojo.Event.listen(this.sceneAssistant.controller.document, "keyup", this.tipKeyPressBound);
+
+ if(this.type=="tip"){
+ var hint="Try the surf-n-turf!";
+ }else{
+ var hint="Add a note (optional)";
+ }
+
+ this.sceneAssistant.controller.setupWidget('newtip', this.tipAttributes = {hintText:hint,multiline:true,focus:true},
+ this.tipModel = {value:'', disabled:false});
+ var t=(this.type=="todo")? "To-do": this.type;
+ this.sceneAssistant.controller.get("addtip-title").innerHTML="Add a "+t;
+}
+
+AddTipDialogAssistant.prototype.activate = function() {
+ this.sceneAssistant.controller.get('newtip').mojo.focus();
+}
+
+AddTipDialogAssistant.prototype.tipKeyPress = function(event) {
+logthis("keypress");
+ try{
+ var charsLeft=200-this.sceneAssistant.controller.get("newtip").mojo.getValue().length;
+
+ this.sceneAssistant.controller.get("charCount").innerHTML=charsLeft;
+ if(charsLeft<0){
+ if(!this.sceneAssistant.controller.get("charCount").hasClassName("negative")){
+ this.sceneAssistant.controller.get("charCount").addClassName("negative");
+ }
+ }else{
+ if(this.sceneAssistant.controller.get("charCount").hasClassName("negative")){
+ this.sceneAssistant.controller.get("charCount").removeClassName("negative");
+ }
+ }
+ }catch(e){
+
+ }
+};
+
+
+AddTipDialogAssistant.prototype.tipokTapped = function() {
+logthis("oktapped");
+ var params={
+ vid: this.vid,
+ type: this.type
+ };
+
+ if(this.tipModel.value==''){
+ params.text='I want to visit this place.';
+ }else{
+ params.text=this.tipModel.value;
+ }
+
+ foursquarePost(this.sceneAssistant,{
+ endpoint: 'addtip.json',
+ requiresAuth: true,
+ parameters: params,
+ onSuccess: this.tipSuccess.bind(this),
+ onFailure: this.tipFailed.bind(this)
+
+ });
+}
+
+AddTipDialogAssistant.prototype.tipSuccess = function() {
+ Mojo.Controller.getAppController().showBanner("Successfully added your "+this.type+"!", {source: 'notification'});
+ //this.sceneAssistant.controller.get("okButton").mojo.deactivate();
+ this.sceneAssistant.getVenueInfo();
+ this.widget.mojo.close();
+}
+
+AddTipDialogAssistant.prototype.tipFailed = function() {
+ Mojo.Controller.getAppController().showBanner("Error adding your "+this.type, {source: 'notification'});
+
+}
+AddTipDialogAssistant.prototype.cancelTapped = function() {
+ this.widget.mojo.close();
+}
+
+AddTipDialogAssistant.prototype.cleanup = function() {
+ Mojo.Event.stopListening(this.sceneAssistant.controller.get('tipokButton'), Mojo.Event.tap, this.tipokTappedBound);
+ Mojo.Event.stopListening(this.sceneAssistant.controller.get('cancelButton'), Mojo.Event.tap, this.cancelTappedBound);
+ Mojo.Event.stopListening(this.sceneAssistant.controller.document, "keyup", this.tipKeyPressBound);
+
+}
View
617 Foursquare-v1-api/app/assistants/add-venue-assistant.js
@@ -0,0 +1,617 @@
+function AddVenueAssistant(a,ed,v,vn) {
+ this.auth=a;
+ this.editing=ed;
+ this.venue=v;
+ if(vn!="" && vn!=undefined){
+ this.fakeVenue=vn;
+ this.venueless=true;
+ }else{
+ this.fakeVenue='';
+ this.venueless=false;
+ }
+
+ if(ed) {
+ this.bl="Save";
+ this.lat=this.venue.geolat;
+ this.long=this.venue.geolong;
+ }else{
+ this.bl="Add";
+ this.lat=_globals.lat;
+ this.long=_globals.long;
+ }
+ this.refresh=true;
+ _globals.curmap=this;
+
+ this.categoryName="";
+ this.categoryIcon="";
+ if(ed){
+ if(this.venue.primarycategory.id){
+ for(var i =0; i<_globals.categories.length; i++){
+ if(_globals.categories[i].id==this.venue.primarycategory.id){
+ this.categoryName=_globals.categories[i].nodename;
+ this.categoryIcon=_globals.categories[i].iconurl;
+ break;
+ }
+ for(var s=0;s<_globals.categories[i].categories.length;s++){
+ if(_globals.categories[i].categories[s].id==this.venue.primarycategory.id){
+ this.categoryName=_globals.categories[i].categories[s].nodename;
+ this.categoryIcon=_globals.categories[i].categories[s].iconurl;
+ break;
+ }
+
+ if(_globals.categories[i].categories[s].categories != undefined){
+ for(var t=0; t<_globals.categories[i].categories[s].categories.length; t++){
+ if(_globals.categories[i].categories[s].categories[t].id==this.venue.primarycategory.id){
+ this.categoryName=_globals.categories[i].categories[t].nodename;
+ this.categoryIcon=_globals.categories[i].categories[t].iconurl;
+ break;
+ }
+ }
+ }
+ }
+ }
+ _globals.selectedCat=this.venue.primarycategory.id;
+ }
+ }
+
+
+
+}
+
+AddVenueAssistant.prototype.setup = function(widget) {
+ this.widget = widget;
+
+ NavMenu.setup(this,{buttons:'empty'});
+
+ this.categoryTappedBound=this.categoryTapped.bindAsEventListener(this);
+ this.okTappedBound=this.okTapped.bindAsEventListener(this);
+ this.cancelTappedBound=this.cancelTapped.bindAsEventListener(this);
+ this.toggleMapBound=this.toggleMap.bindAsEventListener(this);
+ this.searchTappedBound=this.searchTapped.bindAsEventListener(this);
+
+
+ this.controller.setupWidget("okButton",
+ this.attributes = {type : Mojo.Widget.activityButton},
+ this.OKButtonModel = {
+ buttonLabel: this.bl,
+ disabled: false
+ }
+ );
+
+
+ this.controller.setupWidget("cancelButton",
+ this.attributes = {},
+ this.CancelButtonModel = {
+ buttonLabel: "Nevermind",
+ disabled: false
+ }
+ );
+
+
+ this.controller.setupWidget("searchGoogle",
+ this.attributes = {type : Mojo.Widget.activityButton},
+ this.SearchButtonModel = {
+ buttonLabel: 'Search Google',
+ disabled: false
+ }
+ );
+
+ this.controller.setupWidget("mapDrawer",
+ this.attributes = {
+ modelProperty: 'open',
+ unstyled: false
+ },
+ this.model = {
+ open: false
+ }
+ );
+ this.controller.setupWidget("toggleMapButton",
+ this.attributes = {},
+ this.CancelButtonModel = {
+ buttonLabel: "Edit Map Position",
+ disabled: false
+ }
+ );
+
+ Mojo.Event.listen(this.controller.get('okButton'), Mojo.Event.tap, this.okTappedBound);
+ Mojo.Event.listen(this.controller.get('setCategory'), Mojo.Event.tap, this.categoryTappedBound);
+ Mojo.Event.listen(this.controller.get('cancelButton'), Mojo.Event.tap, this.cancelTappedBound);
+ Mojo.Event.listen(this.controller.get('map'), Mojo.Event.tap, this.toggleMapBound);
+ Mojo.Event.listen(this.controller.get('searchGoogle'), Mojo.Event.tap, this.searchTappedBound);
+
+ logthis("setup buttons");
+
+
+ this.controller.setupWidget('venue-name', this.nameAttributes = {hintText:'Type here to Google Search',multiline:false,focus:true},
+ this.nameModel = {value:this.fakeVenue, disabled:false});
+ this.controller.setupWidget('venue-address', this.addressAttributes = {hintText:'',multiline:false,focus:false},
+ this.addressModel = {value:'', disabled:false});
+ this.controller.setupWidget('venue-crossstreet', this.crossstreetAttributes = {hintText:'',multiline:false,focus:false},
+ this.crossstreetModel = {value:'', disabled:false});
+ this.controller.setupWidget('venue-city', this.cityAttributes = {hintText:'',multiline:false,focus:false},
+ this.cityModel = {value:'', disabled:false});
+ this.controller.setupWidget('venue-zip', this.zipAttributes = {hintText:'',multiline:false,focus:false,modifierState:Mojo.Widget.numLock},
+ this.zipModel = {value:'', disabled:false});
+ this.controller.setupWidget('venue-phone', this.phoneAttributes = {hintText:'',multiline:false,focus:false,modifierState:Mojo.Widget.numLock},
+ this.phoneModel = {value:'', disabled:false});
+ this.controller.setupWidget('venue-twitter', this.twitterAttributes = {hintText:'',multiline:false,focus:false},
+ this.twitterModel = {value:'', disabled:false});
+
+
+ this.catsmainAttributes={choices:[{label:'',value:'-1'}]};
+ this.catsmainModel={value:'-1'};
+ for (var c=0;c<_globals.categories.length;c++) {
+ this.catsmainAttributes.choices.push({label:_globals.categories[c].nodename,value:c});
+ }
+
+
+ this.controller.setupWidget("venue-state",
+ this.stateattributes = {
+ choices: [
+ {label: " ", value: ""},
+ {label: "AL", value: "AL"},
+ {label: "AK", value: "AK"},
+ {label: "AR", value: "AR"},
+ {label: "AZ", value: "AZ"},
+ {label: "CA", value: "CA"},
+ {label: "CO", value: "CO"},
+ {label: "CT", value: "CT"},
+ {label: "DC", value: "DC"},
+ {label: "DE", value: "DE"},
+ {label: "FL", value: "FL"},
+ {label: "GA", value: "GA"},
+ {label: "HI", value: "HI"},
+ {label: "IA", value: "IA"},
+ {label: "ID", value: "ID"},
+ {label: "IL", value: "IL"},
+ {label: "IN", value: "IN"},
+ {label: "KS", value: "KS"},
+ {label: "KY", value: "KY"},
+ {label: "LA", value: "LA"},
+ {label: "MA", value: "MA"},
+ {label: "MD", value: "MD"},
+ {label: "ME", value: "ME"},
+ {label: "MI", value: "MI"},
+ {label: "MN", value: "MN"},
+ {label: "MO", value: "MO"},
+ {label: "MS", value: "MS"},
+ {label: "MT", value: "MT"},
+ {label: "NC", value: "NC"},
+ {label: "ND", value: "ND"},
+ {label: "NE", value: "NE"},
+ {label: "NH", value: "NH"},
+ {label: "NJ", value: "NJ"},
+ {label: "NM", value: "NM"},
+ {label: "NV", value: "NV"},
+ {label: "NY", value: "NY"},
+ {label: "OH", value: "OH"},
+ {label: "OK", value: "OK"},
+ {label: "OR", value: "OR"},
+ {label: "PA", value: "PA"},
+ {label: "RI", value: "RI"},
+ {label: "SC", value: "SC"},
+ {label: "SD", value: "SD"},
+ {label: "TN", value: "TN"},
+ {label: "TX", value: "TX"},
+ {label: "UT", value: "UT"},
+ {label: "VA", value: "VA"},
+ {label: "VT", value: "VT"},
+ {label: "WA", value: "WA"},
+ {label: "WI", value: "WI"},
+ {label: "WV", value: "WV"},
+ {label: "WY", value: "WY"}
+ ]},
+
+ this.statemodel = {
+ value: "",
+ disabled: false
+ }
+ );
+
+}
+
+AddVenueAssistant.prototype.scrollTest = function(a,b,c,d,e){
+ Mojo.Log.error("state="+Object.toJSON(this.controller.get('mojo-scene-add-venue-scene-scroller').mojo.getScrollPosition()));
+
+ var ss=this.controller.get('mojo-scene-add-venue-scene-scroller').mojo.getScrollPosition();
+
+ if(ss.top < -132){
+ this.controller.get("map_canvas").show();
+ this.controller.get("map-info-banner").show();
+ }else{
+ this.controller.get("map_canvas").hide();
+ this.controller.get("map-info-banner").hide();
+ }
+};
+
+AddVenueAssistant.prototype.toggleMap = function(event) {
+ this.controller.stageController.pushScene({name: "add-venue-map",disableSceneScroller: true},this.lat,this.long,this);
+};
+
+AddVenueAssistant.prototype.initMap = function(event) {
+ var myOptions = {
+ zoom: 15,
+ center: new google.maps.LatLng(this.lat, this.long),
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
+ draggable: true,
+ mapTypeControl: false,
+ navigationControl: false
+ }
+ this.map = new google.maps.Map(this.controller.get("map_canvas"), myOptions);
+
+ this.setMarkers(this.map);
+}
+
+AddVenueAssistant.prototype.setMarkers = function(map){
+ this.cmarker = new google.maps.Marker({
+ position: new google.maps.LatLng(this.lat,this.long),
+ map: map,
+ draggable: true
+ });
+ google.maps.event.addListener(this.map, 'click',
+ function(e) {
+ logthis("map clicked");
+
+ var pos=e.latLng;
+
+ this.cmarker.setPosition(pos);
+
+ this.lat=pos.lat();
+ this.long=pos.lng();
+
+ this.map.panTo(pos);
+ }.bind(this)
+ );
+
+
+ //this.controller.stageController.activeScene().disableSceneScroller = true;
+};
+
+AddVenueAssistant.prototype.activate = function() {
+ logthis("addvenue: activated");
+ logthis("av lat="+this.lat+", long="+this.long);
+
+ this.controller.get("map").src="http://maps.google.com/maps/api/staticmap?mobile=true&zoom=15&size=320x150&sensor=false&markers=color:blue|"+this.lat+","+this.long+"&key=ABQIAAAAfKBxdZJp1ib9EdLiKILvVxT50hbykH-f32yPesIURumAK58x-xSabNSSctTSap-7tI2Dm8GumOSqyA";
+
+ this.controller.get('venue-name').mojo.focus();
+
+ //if we're proposing an edit to a venue, populate the fields
+ if(this.editing && this.refresh) {
+ this.nameModel.value=this.venue.name;
+ this.controller.modelChanged(this.nameModel);
+
+ this.addressModel.value=this.venue.address;
+ this.controller.modelChanged(this.addressModel);
+
+ this.crossstreetModel.value=this.venue.crossstreet;
+ this.controller.modelChanged(this.crossstreetModel);
+
+ this.cityModel.value=this.venue.city;
+ this.controller.modelChanged(this.cityModel);
+
+ this.zipModel.value=this.venue.zip;
+ this.controller.modelChanged(this.zipModel);
+
+ this.phoneModel.value=this.venue.phone;
+ this.controller.modelChanged(this.phoneModel);
+
+ this.twitterModel.value=this.venue.twitter;
+ this.controller.modelChanged(this.twitterModel);
+
+ this.statemodel.value=this.venue.state;
+ this.controller.modelChanged(this.statemodel);
+
+ this.controller.get("selectedCat").update('<img src="'+this.categoryIcon+'" align="top"/> '+this.categoryName);
+
+
+ this.controller.get("addvenue-header").innerHTML="SUGGEST AN EDIT";
+ this.refresh=false;
+
+
+ }else{
+ logthis("trying to get addy...lat="+_globals.lat+", long="+_globals.long);
+ //try and get the reverse location...
+ this.controller.serviceRequest('palm://com.palm.location', {
+ method: "getReverseLocation",
+ parameters: {latitude: this.lat, longitude:this.long},
+ onSuccess: this.gotLocation.bind(this),
+ onFailure: this.failedLocation.bind(this)
+ });
+
+ }
+}
+
+function trim(stringToTrim) {
+ return stringToTrim.replace(/^\s+|\s+$/g,"");
+}
+
+AddVenueAssistant.prototype.aboutToActivate = function(callback) {
+ callback.defer();
+};
+AddVenueAssistant.prototype.gotLocation = function(event) {
+ //example response: 123 Abc Street ; Your Town, ST 12345 ; USA
+ //we're worried about the middle line, so we get to do some fun parsing.
+ //no, seriously, parsing's the most fun part of programming.
+ //i wish this whole app was just parsing text. boresquare, some would call it.
+ if (event.address){
+ var addylines=event.address.split(";");
+ if(addylines.length>1) {
+ var loca=addylines[1].split(", ");
+ var city=trim(loca[0]);
+ var country=trim(addylines[2]);
+ if(country!="USA"){this.controller.get("venue-state").hide();}
+
+ var statezip=loca[1].split(" ");
+ var state=trim(statezip[0]);
+ var zip=trim(statezip[1]);
+ if(zip.indexOf("A")){zip=zip.replace("A","");}
+
+ this.cityModel.value=city;
+ this.controller.modelChanged(this.cityModel);
+
+ this.zipModel.value=zip;
+ this.controller.modelChanged(this.zipModel);
+
+ this.statemodel.value=state;
+ this.controller.modelChanged(this.statemodel);
+
+ }
+ }
+}
+AddVenueAssistant.prototype.failedLocation = function(event) {
+ //don't worry about it. make them manually enter the info in.
+ logthis("error getting addy: "+event.errorCode);
+}
+
+AddVenueAssistant.prototype.okTapped = function() {
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+
+ if(!this.editing) {
+ pcat=_globals.selectedCat;
+ var url = 'https://api.foursquare.com/v1/addvenue.json';
+ var ep="addvenue.json";
+ var params={
+ name: this.nameModel.value,
+ address: this.addressModel.value,
+ crossstreet: this.crossstreetModel.value,
+ city: this.cityModel.value,
+ state: this.statemodel.value,
+ zip: this.zipModel.value,
+ geolat: _globals.lat,
+ geolong: _globals.long,
+ phone: this.phoneModel.value,
+ twitter: this.twitterModel.value,
+ primarycategoryid: pcat
+ };
+ }else{
+ pcat=_globals.selectedCat;
+ var url = 'https://api.foursquare.com/v1/venue/proposeedit.json';
+ var ep="venue/proposeedit.json";
+ var params={
+ name: this.nameModel.value,
+ address: this.addressModel.value,
+ crossstreet: this.crossstreetModel.value,
+ city: this.cityModel.value,
+ state: this.statemodel.value,
+ zip: this.zipModel.value,
+ cityid: credentials.cityid,
+ phone: this.phoneModel.value,
+ twitter: this.twitterModel.value,
+ geolat: _globals.lat,
+ geolong: _globals.long,
+ vid: this.venue.id,
+ primarycategoryid: pcat
+ };
+ }
+ foursquarePost(this,{
+ endpoint: ep,
+ requiresAuth: true,
+ parameters: params,
+ onSuccess: this.venueSuccess.bind(this),
+ onFailure: this.venueFailed.bind(this),
+ ignoreErrors: true
+
+ });
+}
+
+AddVenueAssistant.prototype.venueSuccess = function(response) {
+ this.controller.get("okButton").mojo.deactivate();
+ logthis(response.responseText);
+
+ if(response.responseJSON.venue != undefined && !this.editing) {
+ Mojo.Controller.getAppController().showBanner("Venue saved to Foursquare!", {source: 'notification'});
+
+ var vid=response.responseJSON.venue.id;
+ var vname=response.responseJSON.venue.name;
+
+ this.controller.stageController.popScene("add-venue");
+
+ this.controller.stageController.pushScene({name: "venuedetail", transition: Mojo.Transition.crossFade, disableSceneScroller: true},response.responseJSON.venue,_globals.username,_globals.password,_globals.uid);
+
+ }
+
+ if(response.responseJSON.error != undefined){
+ switch(response.responseJSON.error){
+ case "Possible Duplicate Venue":
+ var vname=this.nameModel.value;
+ var dialog = this.controller.showDialog({
+ template: 'listtemplates/dupeVenue',
+ assistant: new DupeVenueAssistant(this,vname)
+ });
+
+ break;
+ default:
+ this.controller.showAlertDialog({
+ onChoose: function(value) {},
+ title: $L("Uh-oh!"),
+ message: $L(response.responseJSON.error),
+ choices:[
+ {label:$L('OK'), value:"OK", type:'primary'}
+ ]
+ });
+ break;
+ }
+ }
+
+ if(this.editing && response.responseJSON.error == undefined){
+ this.controller.showAlertDialog({
+ onChoose: function(value) {
+ this.controller.stageController.popScene("add-venue");
+ }.bind(this),
+ title: $L("Edit Received"),
+ message: $L("Venue edits are sent to a queue for Super Users to approve, so your proposed changes will not be immediately seen. If a Super User approves your proposal, the changes will be incorporated."),
+ choices:[
+ {label:$L('OK'), value:"OK", type:'primary'}
+ ]
+ });
+
+ }
+
+
+}
+
+
+
+
+AddVenueAssistant.prototype.searchTapped = function(event) {
+
+ if(this.nameModel.value.length>0){
+ var url = 'http://ajax.googleapis.com/ajax/services/search/local';
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'force',
+ parameters: {
+ v: '1.0',
+ q: encodeURIComponent(this.nameModel.value),
+ rsz: 'small',
+ near: _globals.lat+","+_globals.long
+ },
+ onSuccess: this.googleSuccess.bind(this),
+ onFailure: this.googleFailed.bind(this)
+ });
+ }else{
+ this.controller.get("searchGoogle").mojo.deactivate();
+ Mojo.Controller.getAppController().showBanner("Enter a venue name to search", {source: 'notification'});
+ }
+};
+
+AddVenueAssistant.prototype.googleSuccess = function(r){
+ //logthis("google ok");
+ //logthis(Object.toJSON(r.responseJSON));
+ this.controller.get("searchGoogle").mojo.deactivate();
+ var data=r.responseJSON.responseData;
+ if(data){
+ if(data.results){
+ if(data.results.length>0){
+ var vr=data.results[0];
+ logthis(vr.titleNoFormatting);
+ this.addressModel.value=vr.streetAddress;
+ this.controller.modelChanged(this.addressModel);
+ this.cityModel.value=vr.city;
+ this.controller.modelChanged(this.cityModel);
+ this.statemodel.value=vr.region;
+ this.controller.modelChanged(this.statemodel);
+ this.nameModel.value=vr.titleNoFormatting;
+ this.controller.modelChanged(this.nameModel);
+
+ if(vr.phoneNumbers!=undefined){
+ this.phoneModel.value=vr.phoneNumbers[0].number.replace("(","").replace(")","").replace(" ","").replace("-","");
+ this.controller.modelChanged(this.phoneModel);
+ }
+ }
+ }
+ }
+}
+AddVenueAssistant.prototype.googleFailed = function(r){
+ this.controller.get("searchGoogle").mojo.deactivate();
+ Mojo.Controller.getAppController().showBanner("Error searching Google", {source: 'notification'});
+ logthis("google fail");
+ logthis(Object.toJSON(r.responseJSON));
+
+}
+
+AddVenueAssistant.prototype.venueFailed = function(response) {
+ logthis(response.responseText);
+ if(response.responseJSON.error != undefined){
+ switch(response.responseJSON.error){
+ case "Possible Duplicate Venue":
+ var vname=this.nameModel.value;
+ var dialog = this.controller.showDialog({
+ template: 'listtemplates/dupeVenue',
+ assistant: new DupeVenueAssistant(this,vname)
+ });
+
+ break;
+ default:
+ this.controller.showAlertDialog({
+ onChoose: function(value) {},
+ title: $L("Uh-oh!"),
+ message: $L(response.responseJSON.error),
+ choices:[
+ {label:$L('OK'), value:"OK", type:'primary'}
+ ]
+ });
+ break;
+ }
+ }else{
+ Mojo.Controller.getAppController().showBanner("Error saving your venue.", {source: 'notification'});
+ }
+}
+AddVenueAssistant.prototype.cancelTapped = function() {
+ this.controller.stageController.popScene("add-venue");
+}
+
+AddVenueAssistant.prototype.cleanup = function(event) {
+ Mojo.Event.stopListening(this.controller.get('okButton'), Mojo.Event.tap, this.okTappedBound);
+ Mojo.Event.stopListening(this.controller.get('setCategory'), Mojo.Event.tap, this.categoryTappedBound);
+ Mojo.Event.stopListening(this.controller.get('cancelButton'), Mojo.Event.tap, this.cancelTappedBound);
+ Mojo.Event.stopListening(this.controller.get('map'), Mojo.Event.tap, this.toggleMapBound);
+ Mojo.Event.stopListening(this.controller.get('searchGoogle'), Mojo.Event.tap, this.searchTappedBound);
+}
+
+AddVenueAssistant.prototype.loadSubCat = function(event) {
+ var i = this.catsmainModel.value;
+ this.maincat=i;
+ var subcats=_globals.categories[i].categories;
+ this.catssub1Attributes.choices=[{label:"",value:"-1"}];
+ for(var s=0;s<subcats.length;s++) {
+ this.catssub1Attributes.choices.push({label:subcats[s].nodename,value:subcats[s].id});
+ }
+ this.controller.modelChanged(this.catssub1Model);
+ this.controller.get("subcat1").show();
+}
+
+AddVenueAssistant.prototype.loadSubSubCat = function(event) {
+ var v = event.value;
+ var eff;
+ for(var f=0;f<_globals.categories[this.maincat].categories.length;f++){
+ if(_globals.categories[this.catsmainModel.value].categories[f].id==v){
+ eff=f;
+ }
+ }
+ var subcats=_globals.categories[this.catsmainModel.value].categories[eff].categories;
+
+
+
+ if(subcats) {
+ this.catssub2Attributes.choices=[{label:"",value:"-1"}];
+ for(var s=0;s<subcats.length;s++) {
+ this.catssub2Attributes.choices.push({label:subcats[s].nodename,value:subcats[s].id});
+ }
+ this.controller.modelChanged(this.catssub2Model);
+ this.controller.get("subcat2").show();
+ }else{
+ this.catssub2Attributes.choices=[{label:"",value:"-1"}];
+ this.controller.modelChanged(this.catssub2Model);
+ this.controller.get("subcat2").hide();
+ }
+}
+
+AddVenueAssistant.prototype.categoryTapped = function(event){
+ //generate items list
+ this.refresh=false;
+ logthis("catlength="+_globals.categories.length);
+ this.controller.stageController.pushScene("categories",this);
+
+}
View
76 Foursquare-v1-api/app/assistants/add-venue-map-assistant.js
@@ -0,0 +1,76 @@
+function AddVenueMapAssistant(lat,long,av) {
+ this.lat=lat;
+ this.long=long;
+ this.addVenueScene=av;
+ _globals.curmap=this;
+
+ logthis("lat="+this.lat+", long="+this.long);
+}
+
+AddVenueMapAssistant.prototype.setup = function() {
+ var script = document.createElement("script");
+ script.src = "http://maps.google.com/maps/api/js?sensor=true&key=ABQIAAAAfKBxdZJp1ib9EdLiKILvVxTDKxkGVU7_DJQo4uQ9UVD-uuNX9xRhyapmRm_kPta_TaiHDSkmvypxPQ&callback=mapLoaded";
+ script.type = "text/javascript";
+ document.getElementsByTagName("head")[0].appendChild(script);
+};
+AddVenueMapAssistant.prototype.initMap = function(event) {
+ var myOptions = {
+ zoom: 15,
+ center: new google.maps.LatLng(this.lat, this.long),
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
+ draggable: true,
+ mapTypeControl: false,
+ navigationControl: false
+ }
+ this.map = new google.maps.Map(this.controller.get("map_canvas"), myOptions);
+
+ this.setMarkers(this.map);
+}
+AddVenueMapAssistant.prototype.aboutToActivate = function(callback) {
+ callback.defer();
+};
+
+AddVenueMapAssistant.prototype.setMarkers = function(map){
+ this.cmarker = new google.maps.Marker({
+ position: new google.maps.LatLng(this.lat,this.long),
+ map: map,
+ draggable: true
+ });
+ google.maps.event.addListener(this.map, 'click',
+ function(e) {
+ logthis("map clicked yes");
+ var pos=e.latLng;
+
+ this.cmarker.setPosition(pos);
+ logthis("clicked coords: lat="+pos.lat()+", long="+pos.lng());
+
+ this.lat=pos.lat();
+ this.long=pos.lng();
+
+ this.map.panTo(pos);
+ }.bind(this)
+ );
+
+
+ //this.controller.stageController.activeScene().disableSceneScroller = true;
+};
+
+AddVenueMapAssistant.prototype.activate = function(event) {
+ /* put in event handlers here that should only be in effect when this scene is active. For
+ example, key handlers that are observing the document */
+};
+
+AddVenueMapAssistant.prototype.deactivate = function(event) {
+ /* remove any event handlers you added in activate and do any other cleanup that should happen before
+ this scene is popped or another scene is pushed on top */
+};
+
+AddVenueMapAssistant.prototype.cleanup = function(event) {
+ logthis("cleaning up");
+ logthis("lat="+this.lat+", long="+this.long);
+ this.addVenueScene.lat=this.lat;
+ this.addVenueScene.long=this.long;
+
+ this.addVenueScene.controller.get("map").src="http://maps.google.com/maps/api/staticmap?mobile=true&zoom=15&size=320x150&sensor=false&markers=color:blue|"+this.lat+","+this.long+"&key=ABQIAAAAfKBxdZJp1ib9EdLiKILvVxT50hbykH-f32yPesIURumAK58x-xSabNSSctTSap-7tI2Dm8GumOSqyA";
+ logthis("finished cleaning up");
+};
View
831 Foursquare-v1-api/app/assistants/app-assistant (original).js
@@ -0,0 +1,831 @@
+function AppAssistant() {
+
+}
+
+AppAssistant.prototype.setup = function() {
+ this.sendstats=new Mojo.Model.Cookie("sendstats");
+ var un=this.sendstats.get();
+ _globals.sendstats=(un)? un.sendstats: "true";
+ if(_globals.sendstats=="true"){fsq.Metrix.postDeviceData(true);logthis("sent Metrix stats");}
+
+ var cardStageController = this.controller.getStageController("mainStage");
+ var dashboardStageController = this.controller.getStageController("fsqDash");
+
+ _globals.appController=this.controller;
+
+
+ // Set up first timeout alarm
+ this.setWakeup();
+
+
+ _globals.GPS = new Location(_globals.gotLocation);
+ _globals.GPS.start();
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+};
+
+/********HANDLE NOTIFICATIONS****************/
+AppAssistant.prototype.setWakeup = function() {
+ this.cookieData=new Mojo.Model.Cookie("notifications");
+ var notifdata=this.cookieData.get();
+ if(notifdata){
+ var notifs=(notifdata.notifs=="1")? '1': '0';
+ _globals.notifs=notifs;
+ }
+
+
+
+ if (_globals.notifs == "1") {
+ try{
+ this.wakeupRequest = new Mojo.Service.Request("palm://com.palm.power/timeout", {
+ method: "set",
+ parameters: {
+ "key": "com.foursquare.foursquare.update",
+ "in": _globals.interval,
+ "wakeup": true,
+ "uri": "palm://com.palm.applicationManager/open",
+ "params": {
+ "id": Mojo.appInfo.id,
+ "params": {"action": "feedUpdate"}
+ }
+ },
+ onSuccess: function(response) {
+ _globals.wakeupTaskId = Object.toJSON(response.taskId);
+ },
+ onFailure: function(response) {
+ logthis("Alarm Set Failure "+
+ response.returnValue+" "+ response.errorText);
+ }
+ });
+ }catch (e) {
+ logthis('AppAssistant.clearSystemTimeout(): ' + e);
+ }
+ logthis("Set Update Timeout");
+ }
+};
+
+
+
+/***********HANDLE LAUNCH**************/
+AppAssistant.prototype.handleLaunch = function (launchParams) {
+ logthis("ReLaunch");
+ logthis("launchParams: "+Object.toJSON(launchParams));
+
+ var cardStageController = this.controller.getStageController("mainStage");
+ var appController = Mojo.Controller.getAppController();
+
+ if(!cardStageController){
+ _globals.cardstage=false;
+ }else{
+ _globals.cardstage=true;
+ }
+
+ var dashStageController = this.controller.getStageController("dashboard");
+
+ foursquareGet(this,{
+ endpoint: 'categories.json',
+ requiresAuth: false,
+ parameters: {},
+ onSuccess: _globals.categorySuccess.bind(this),
+ onFailure: _globals.categoryFailed.bind(this)
+ });
+ this.getHistory();
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+ if(credentials){
+ _globals.auth=credentials.auth;
+ _globals.uid=credentials.uid;
+ _globals.swf=credentials.swf || "1";
+ }
+ this.username=credentials.username;
+ _globals.auth=credentials.auth;
+
+
+ if (!launchParams) {
+ // FIRST LAUNCH
+ // Look for an existing main stage by name.
+ //grab categories in the background...
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("mainstage doesn't exist; first run");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /* foursquareGet(this,{
+ endpoint: 'user.json',
+ parameters: {},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ }); */
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+
+ this.loadScene('main');
+ }
+ }
+ else {
+ logthis("com.foursquare.foursquare -- Wakeup Call", launchParams.action);
+
+ switch (launchParams.action) {
+ case "search": //JUST TYPE
+ logthis("search request");
+ _globals.fromSearch=true;
+ _globals.jtQuery=launchParams.query;
+
+
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("search: Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("mainstage doesn't exist; search request");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /* foursquareGet({
+ endpoint: 'user.json',
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ });*/
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+ this.loadScene('main');
+
+ }
+
+ break;
+
+ case "shout": //JUST TYPE
+ logthis("shout request");
+ _globals.showShout=true;
+ _globals.jtShout=launchParams.text;
+
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("loading shit");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ //logthis("here");
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /*foursquareGet({
+ endpoint: 'user.json',
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ });*/
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+ this.loadScene('main');
+
+ }
+
+ break;
+
+ // UPDATE FEEDS
+ case "feedUpdate" :
+ //turn off GPS:
+ _globals.GPS.stop();
+ // Set next wakeup alarm
+ this.setWakeup();
+
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+ if(credentials){
+ _globals.auth=credentials.auth;
+ _globals.uid=credentials.uid;
+ _globals.swf=credentials.swf || "1";
+ }
+ this.username=credentials.username;
+ _globals.auth=credentials.auth;
+
+
+ // Update the feed list
+ foursquareGet(this,{
+ enpoint: 'checkins.json',
+ requiresAuth: true,
+ parameters: {geolat:_globals.lat,
+ geolong:_globals.long,
+ geohacc:_globals.hacc,
+ geovacc:_globals.vacc,
+ geoalt:_globals.altitude},
+ onSuccess: this.feedSuccess.bind(this),
+ onFailure: this.feedFailed.bind(this)
+ });
+ break;
+
+ // NOTIFICATION
+ case "notification" :
+ _globals.GPS = new Location(_globals.gotLocation);
+ _globals.GPS.start();
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+ if(credentials){
+ _globals.auth=credentials.auth;
+ _globals.uid=credentials.uid;
+ _globals.swf=credentials.swf || "1";
+ }
+
+ _globals.loadPrefs();
+
+ //also grab user settings in bg
+ /* foursquareGet({
+ endpoint: 'user.json',
+ onSuccess: this.userSuccess.bind(this),
+ onFailure: this.userFailed.bind(this),
+ requiresAuth: true
+ });*/
+
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+
+ if (cardStageController) {
+
+ // If it exists, find the appropriate story list and activate it.
+ _globals.onVenues=true;
+ cardStageController.swapScene({name: "friends-list",
+ transition: Mojo.Transition.crossFade},
+ _globals.thisauth,
+ _globals.userData,
+ _globals.username,
+ _globals.password,
+ _globals.uid,
+ _globals.lat,
+ _globals.long,
+ this);
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up a new main stage,
+ // push the feedList scene and then the appropriate story list
+ var pushMainScene2 = function(stageController) {
+ stageController.swapScene({name: "friends-list",
+ transition: Mojo.Transition.crossFade},
+ _globals.auth,
+ _globals.userData,
+ _globals.username,
+ _globals.password,
+ _globals.uid,
+ _globals.lat,
+ _globals.long,
+ this);
+ };
+ var stageArguments2 = {name: "mainStage", lightweight: true};
+ this.controller.createStageWithCallback(stageArguments2, pushMainScene2.bind(this), "card");
+ }
+ break;
+
+ case "saveAlertFile":
+ var appController = Mojo.Controller.getAppController();
+ var fn=launchParams.alertFile;
+ var fname=launchParams.alertName;
+
+ this.cookieData=new Mojo.Model.Cookie("alert");
+ this.cookieData.put(
+ {"type":'ringtone',"ringtone":fname,"file":fn}
+ )
+ _globals.alerttype='ringtone';
+ if(!_globals.cardstage){
+ Mojo.Controller.getAppController().showBanner("Set notification ringtone!", {source: 'notification'});
+ logthis("nope");
+ appController.createStageWithCallback({name: "mainStage", lightweight: true}, function(){
+ //Mojo.Controller.getAppController().removeAllBanners();
+ Mojo.Controller.getAppController().closeAllStages();
+ }.bind(this), "card");
+ }
+
+ break;
+
+ case "url":
+ var shorturl=launchParams.url;
+ var appController = Mojo.Controller.getAppController();
+
+ if(shorturl.indexOf("foursquare.com/venue")>-1){
+ var s=shorturl.indexOf("venue/")+6;
+ var vid=shorturl.substr(s);
+ appController.launch("com.foursquare.foursquare",{action: 'venue',venue: vid},
+ function(){logthis("launched");}.bind(this),
+ function(){logthis("launch failed");}.bind(this)
+ );
+ }else if(shorturl.indexOf("4sq.com")>-1){
+ var url="http://api.bit.ly/v3/expand?shortUrl="+encodeURIComponent(shorturl)+"&login=sirgeoph&apiKey=R_6c499814739b04b067e6df774addba3b&format=json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ onSuccess: function(r){
+ var longurl=r.responseJSON.data.expand[0].long_url;
+
+ if(longurl.indexOf("foursquare.com/venue")>-1){
+ var s=longurl.indexOf("venue/")+6;
+ var vid=longurl.substr(s);
+ appController.launch("com.foursquare.foursquare",{action: 'venue',venue: vid},
+ function(){logthis("launched");}.bind(this),
+ function(){logthis("launch failed");}.bind(this)
+ );
+ }else{
+ appController.open({target: longurl},function(){
+ _globals.GPS.stop();
+ if(!_globals.cardstage){
+ logthis("nope");
+ appController.createStageWithCallback({name: "mainStage", lightweight: true}, function(){
+ logthis("created");
+ Mojo.Controller.getAppController().closeAllStages();
+ }.bind(this), "card");
+ }
+ }.bind(this));
+ }
+ }.bind(this),
+ onFailure: function(r){
+ logthis("fail: "+Object.toJSON(r.responseJSON));
+ }.bind(this)
+ });
+ }else{
+ appController.open({target: shorturl},function(){
+ _globals.GPS.stop();
+ if(!_globals.cardstage){
+ logthis("nope");
+ appController.createStageWithCallback({name: "mainStage", lightweight: true}, function(){
+ logthis("created");
+ Mojo.Controller.getAppController().closeAllStages();
+ }.bind(this), "card");
+ }
+ }.bind(this));
+
+ }
+
+
+
+ break;
+ case "user":
+ case "venue":
+ //_globals.cmmodel.items.toggleCmd="do-Friends";
+ if (cardStageController) {
+
+ // If it exists, find the appropriate story list and activate it.
+ //cardStageController.popScenesTo("feedList");
+ _globals.onVenues=true;
+ if(launchParams.action=="venue"){
+ cardStageController.pushScene({name: "venuedetail",
+ transition: Mojo.Transition.crossFade},{id:launchParams.venue},
+ _globals.username,
+ _globals.password,
+ _globals.uid,
+ false,
+ undefined,
+ undefined,
+ this,
+ false,
+ true);
+ }else if(launchParams.action=="user"){
+ cardStageController.pushScene({name: "user-info", transition: Mojo.Transition.crossFade},
+ {id:launchParams.user},_globals.username,_globals.password,_globals.uid,false,undefined,undefined,this,false,true);
+ }
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up a new main stage,
+ // push the feedList scene and then the appropriate story list
+ var pushMainScene2 = function(stageController) {
+ _globals.GPS = new Location(_globals.gotLocation);
+ _globals.GPS.start();
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ _globals.loadPrefs();
+
+
+ var url = "https://api.foursquare.com/v1/categories.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'force',
+ onSuccess: _globals.categorySuccess.bind(this),
+ onFailure: _globals.categoryFailed.bind(this)
+ });
+
+
+ //also grab user settings in bg
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+ _globals.cmmodel = {
+ visible: true,
+ items: [{
+ items: [
+ {},
+ { iconPath: "images/venue_button.png", command: "do-Venues"},
+ { iconPath: "images/friends_button.png", command: "do-Friends"},
+ { iconPath: "images/todo_button.png", command: "do-Tips"},
+ { iconPath: "images/user_info.png", command: "do-Badges"},
+ { iconPath: 'images/leader_button.png', command: 'do-Leaderboard'},
+ {}
+ ],
+ toggleCmd: "do-Venues",
+ checkEnabled: true
+ }]
+ };
+ //stageController.pushScene("feedList", this.feeds);
+ //stageController.pushScene("storyList", this.feeds.list, launchParams.index);
+ if(launchParams.action=="venue"){
+ stageController.pushScene({name: "venuedetail", transition: Mojo.Transition.crossFade},{id:launchParams.venue},_globals.username,_globals.password,_globals.uid,false,undefined,undefined,this,false,true);
+ }else if(launchParams.action=="user"){
+ stageController.pushScene({name: "venuedetail", transition: Mojo.Transition.crossFade},{id:launchParams.user},_globals.username,_globals.password,_globals.uid,false,undefined,undefined,this,false,true);
+
+ }
+ };
+ var stageArguments2 = {name: "mainStage", lightweight: true};
+ this.controller.createStageWithCallback(stageArguments2, pushMainScene2.bind(this), "card");
+ }
+ break;
+ case "leaderboard":
+
+ break;
+ }
+ }
+};
+
+
+AppAssistant.prototype.loadScene = function(scene) {
+ var pushMainScene = function(stageController) {
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+
+
+ if (_globals.loadPrefs()){
+ zBar.stageController=stageController;
+ stageController.pushScene(scene,true,credentials);
+ }else{
+ zBar.stageController=stageController;
+ stageController.pushScene(scene,false);
+ }
+
+ };
+ var stageArguments = {name: "mainStage", lightweight: true,splashBackgroundName:Mojo.appPath+'images/splash.png'};
+ this.controller.createStageWithCallback(stageArguments,
+ pushMainScene.bind(this), "card");
+
+};
+
+AppAssistant.prototype.feedFailed = function(r) {
+ logthis("failed: "+r.responseText);
+}
+
+
+
+AppAssistant.prototype.feedSuccess = function(r) {
+ this.r=r;
+ //see if we've got a stored list of old checkins
+ _globals.db.get("feed",function(d){
+ //found an old feed
+ if(d) {var f=d.checkins;}
+ if(!f){
+
+ var f=[];
+ }
+ this.doFeedData(f,this.r);
+ }.bind(this),function(d){
+ //no feed found
+ this.doFeedData([],this.r);
+ }.bind(this));
+}
+
+
+AppAssistant.prototype.doFeedData = function(data,r){
+ var oldfeed=(data)? data: [];
+
+ //setup array to hold actually new checkins
+ var newitems=[];
+
+ //run through array of newly downloaded checkins
+ var newfeed=r.responseJSON.checkins;
+ if(newfeed){
+ if(oldfeed.length>0){
+ for(var f=0;f<newfeed.length;f++) {
+ var inarray=false;
+ for(var of=0;of<oldfeed.length;of++){
+ if(oldfeed[of].id==newfeed[f].id){
+ Mojo.Log.error("checkin for %i is old (ping=%i)",newfeed[f].user.firstname,newfeed[f].ping);
+ Mojo.Log.error("old id=%i, new id=%i",oldfeed[of].id,newfeed[f].id);
+
+ inarray=true;
+ break;
+ }else{
+ }
+ }
+ if(!inarray && newfeed[f].ping && (newfeed[f].venue || newfeed[f].shout)){
+ newitems.push(newfeed[f]);
+ inarray=false;
+ } //if the checkin is really new, add it to the newitems array
+ else{
+ }
+ }
+ }else{
+ newitems=newfeed;
+ }
+
+ //store the new feed in a cookie
+ /*this.cookieData=new Mojo.Model.Cookie("feed");
+ this.cookieData.put({
+ feed: newfeed
+ });*/
+ this.newitems=newitems;
+ _globals.db.add("feed",r.responseJSON,function(r){logthis("add OK");this.doDashboard();}.bind(this),function(r){logthis("add FAIL");this.doDashboard();}.bind(this));
+ }
+}
+
+
+AppAssistant.prototype.doDashboard = function(){
+
+ var newitems=this.newitems;
+ if(newitems && newitems.length>0){
+ try{
+ var appController = Mojo.Controller.getAppController();
+ }catch(e){
+ logthis(Object.toJSON(e));
+ }
+ var stageController = appController.getStageController("mainStage");
+ var dashboardStageController = appController.getStageProxy("fsqDash");
+
+
+
+
+ //handle sound settings
+ this.cookieData=new Mojo.Model.Cookie("alert");
+ var credentials=this.cookieData.get();
+ var alerts=(credentials)? credentials: {type:"bounce",ringtone:"",file:""};
+
+ var sound={};
+ switch(alerts.type){
+ case "system_sound":
+ sound.soundClass="notifications";
+ break;
+ case "ringtone":
+ sound.soundClass="notifications";
+ sound.soundFile=alerts.file;
+ sound.soundDuration=5000;
+ break;
+ case "vibrate":
+ sound.soundClass="vibrate";
+ break;
+ case "bounce":
+ sound.soundClass="notifications";
+ sound.soundFile="bounce.mp3";
+ logthis("path="+sound.soundFile);
+ sound.soundDuration=1500;
+ break;
+ }
+
+ if(stageController){
+ if(!stageController.isActiveAndHasScenes()){
+ var s=(newitems.length==1)? "":"s";
+ sound.messageText=newitems.length+" New Check-in"+s;
+
+ appController.showBanner(sound, {action: "notification"});
+ if(!dashboardStageController) {
+ var pushDashboard = function(stageController){
+ stageController.pushScene("dashboard", newitems);
+ };
+ appController.createStageWithCallback({name: "fsqDash", lightweight: true}, pushDashboard, "dashboard");
+ }else {
+ dashboardStageController.delegateToSceneAssistant("updateDashboard",newitems);
+ }
+ }
+ }else{
+ var s=(newitems.length==1)? "":"s";
+ sound.messageText=newitems.length+" New Check-in"+s;
+
+ appController.showBanner(sound, {action: "notification"});
+ if(!dashboardStageController) {
+ var pushDashboard = function(stageController){
+ stageController.pushScene("dashboard", newitems);
+ };
+ appController.createStageWithCallback({name: "fsqDash", lightweight: true}, pushDashboard, "dashboard");
+ }else {
+ dashboardStageController.delegateToSceneAssistant("updateDashboard",newitems);
+ }
+
+ }
+ }
+ else{
+ }
+}
+
+
+
+
+
+
+
+
+AppAssistant.prototype.getHistory = function(r) {
+ this.r=r;
+ //see if we've got a stored list of old checkins
+ _globals.rdb.get("venues",function(d){
+ //found an history list
+ if(d) {var f=d;}
+ if(!f){
+
+ var f=[];
+ }
+ _globals.rec.venues=f;
+
+ this.cookieData=new Mojo.Model.Cookie("lastHID");
+ var credentials=this.cookieData.get();
+ _globals.lastHID=(credentials)? credentials.lastHID: '0';
+
+ this.loadHistory(_globals.lastHID);
+ }.bind(this),function(d){
+ //no feed found
+ _globals.rec.venues=[];
+
+ this.cookieData=new Mojo.Model.Cookie("lastHID");
+ var credentials=this.cookieData.get();
+ _globals.lastHID=(credentials)? credentials.lastHID: '0';
+
+ this.loadHistory(_globals.lastHID);
+ }.bind(this));
+}
+
+AppAssistant.prototype.loadHistory = function(hid){
+ if(hid==0){
+ var params={l: 250};
+ }else{
+ var params={sinceid: hid};
+ }
+/* var url = "http://api.foursquare.com/v1/history.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ parameters: params,
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: this.historySuccess.bind(this),
+ onFailure: this.historyFailed.bind(this)
+ });*/
+
+
+
+}
+
+AppAssistant.prototype.historySuccess = function(r) {
+ var j=r.responseJSON;
+ if(j.checkins != undefined){
+ //check if venues in array are already visited in the past
+ for(var c=0;c<j.checkins.length;c++){
+ if(c==0){
+ var lhid=j.checkins[c].id;
+ }
+ if(j.checkins[c].venue != undefined){
+ var venue=j.checkins[c].venue;
+ if(venue.primarycategory!=undefined){
+ var inarray=false;
+ for(var v=0;v<_globals.rec.venues.length;v++){
+ if(_globals.rec.venues[v].id==venue.id){
+ inarray=true;
+ }
+ }
+ if(!inarray){
+ _globals.rec.venues.push(venue);
+ }
+ }
+ }
+ }
+
+ //save new venue array
+ _globals.rdb.add("venues",_globals.rec.venues,function(r){logthis("add v OK");}.bind(this),function(r){logthis("add v FAIL");}.bind(this));
+ this.cookieData=new Mojo.Model.Cookie("lastHID");
+ this.cookieData.put({
+ lastHID: lhid
+ });
+
+
+ //now loop through new array of venues and calculate top 5 categories
+ _globals.topCategories=[];
+ for(var v=0;v<_globals.rec.venues.length;v++){
+ var pc=_globals.rec.venues[v].primarycategory;
+ if(pc!=undefined){
+ var catid=-1;
+ var foundid=false;
+
+ for(var d=0;d<_globals.topCategories.length;d++){
+ if(_globals.topCategories[d].id==pc.id){
+ catid=d;
+ foundid=true;
+ //break;
+ }
+ }
+
+ if(foundid){
+ _globals.topCategories[catid].count=_globals.topCategories[catid].count+1;
+ }else{
+ var itm={
+ id: pc.id,
+ name: pc.nodename,
+ path: pc.fullpathname,
+ count: 1
+ };
+ _globals.topCategories.push(itm);
+ }
+ }
+ }
+
+ //categories are now in an array.
+ //sort by count, descending
+ _globals.topCategories.sort(_globals.categorySort);
+
+ }
+}
+
+
+
+AppAssistant.prototype.historyFailed = function(r) {
+ logthis("hfail="+Object.toJSON(r));
+}
+
View
1,514 Foursquare-v1-api/app/assistants/app-assistant-old.js
1,514 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
835 Foursquare-v1-api/app/assistants/app-assistant.js
@@ -0,0 +1,835 @@
+function AppAssistant() {
+
+}
+
+AppAssistant.prototype.setup = function() {
+ this.sendstats=new Mojo.Model.Cookie("sendstats");
+ var un=this.sendstats.get();
+ _globals.sendstats=(un)? un.sendstats: "true";
+ if(_globals.sendstats=="true"){fsq.Metrix.postDeviceData(true);logthis("sent Metrix stats");}
+
+ var cardStageController = this.controller.getStageController("mainStage");
+ var dashboardStageController = this.controller.getStageController("fsqDash");
+
+ _globals.appController=this.controller;
+
+
+ // Set up first timeout alarm
+ this.setWakeup();
+
+
+};
+
+/********HANDLE NOTIFICATIONS****************/
+AppAssistant.prototype.setWakeup = function() {
+ this.cookieData=new Mojo.Model.Cookie("notifications");
+ var notifdata=this.cookieData.get();
+ if(notifdata){
+ var notifs=(notifdata.notifs=="1")? '1': '0';
+ _globals.notifs=notifs;
+ }
+
+
+
+ if (_globals.notifs == "1") {
+ try{
+ this.wakeupRequest = new Mojo.Service.Request("palm://com.palm.power/timeout", {
+ method: "set",
+ parameters: {
+ "key": "com.foursquare.foursquare.update",
+ "in": _globals.interval,
+ "wakeup": true,
+ "uri": "palm://com.palm.applicationManager/open",
+ "params": {
+ "id": Mojo.appInfo.id,
+ "params": {"action": "feedUpdate"}
+ }
+ },
+ onSuccess: function(response) {
+ _globals.wakeupTaskId = Object.toJSON(response.taskId);
+ },
+ onFailure: function(response) {
+ logthis("Alarm Set Failure "+
+ response.returnValue+" "+ response.errorText);
+ }
+ });
+ }catch (e) {
+ logthis('AppAssistant.clearSystemTimeout(): ' + e);
+ }
+ logthis("Set Update Timeout");
+ }
+};
+
+
+
+/***********HANDLE LAUNCH**************/
+AppAssistant.prototype.handleLaunch = function (launchParams) {
+ logthis("ReLaunch");
+ logthis("launchParams: "+Object.toJSON(launchParams));
+
+ var cardStageController = this.controller.getStageController("mainStage");
+ var appController = Mojo.Controller.getAppController();
+
+ if(!cardStageController){
+ _globals.cardstage=false;
+ }else{
+ _globals.cardstage=true;
+ }
+
+ var dashStageController = this.controller.getStageController("dashboard");
+
+ foursquareGet(this,{
+ endpoint: 'categories.json',
+ requiresAuth: false,
+ parameters: {},
+ onSuccess: _globals.categorySuccess.bind(this),
+ onFailure: _globals.categoryFailed.bind(this)
+ });
+
+ this.getHistory();
+
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+
+ if(credentials){
+
+ _globals.auth=credentials.auth;
+ _globals.uid=credentials.uid;
+ _globals.swf=credentials.swf || "1";
+ }else{
+
+ credentials={username:'',auth:''};
+ }
+
+ this.username=credentials.username;
+ _globals.auth=credentials.auth;
+
+
+ if (!launchParams) {
+ // FIRST LAUNCH
+ // Look for an existing main stage by name.
+ //grab categories in the background...
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("mainstage doesn't exist; first run");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /* foursquareGet(this,{
+ endpoint: 'user.json',
+ parameters: {},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ }); */
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+
+ this.loadScene('main');
+ }
+ }
+ else {
+ logthis("com.foursquare.foursquare -- Wakeup Call", launchParams.action);
+
+ switch (launchParams.action) {
+ case "search": //JUST TYPE
+ logthis("search request");
+ _globals.fromSearch=true;
+ _globals.jtQuery=launchParams.query;
+
+
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("search: Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("mainstage doesn't exist; search request");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /* foursquareGet({
+ endpoint: 'user.json',
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ });*/
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+ this.loadScene('main');
+
+ }
+
+ break;
+
+ case "shout": //JUST TYPE
+ logthis("shout request");
+ _globals.showShout=true;
+ _globals.jtShout=launchParams.text;
+
+ if (cardStageController) {
+ // If it exists, just bring it to the front by focusing its window.
+ logthis("Main Stage Exists");
+ cardStageController.activate();
+ } else {
+
+ // Create a callback function to set up the new main stage
+ // once it is done loading. It is passed the new stage controller
+ // as the first parameter.
+ logthis("loading shit");
+ var now=(new Date().getTime());
+ _globals.gpsStart=now;
+ //logthis("here");
+ _globals.nearbyVenues=undefined;
+ _globals.reloadVenues=true;
+ _globals.userData={};
+ _globals.firstLoad=false; //////////////
+ _globals.gpsokay=true;
+ _globals.retryingGPS=false;
+
+ /*foursquareGet({
+ endpoint: 'user.json',
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this),
+ requiresAuth: true
+ });*/
+ var url = "https://api.foursquare.com/v1/user.json";
+ var request = new Ajax.Request(url, {
+ method: 'get',
+ evalJSON: 'true',
+ requestHeaders: {Authorization:_globals.auth},
+ onSuccess: _globals.userSuccess.bind(this),
+ onFailure: _globals.userFailed.bind(this)
+ });
+
+
+ this.loadScene('main');
+
+ }
+
+ break;
+
+ // UPDATE FEEDS
+ case "feedUpdate" :
+ //turn off GPS:
+ _globals.GPS.stop();
+ // Set next wakeup alarm
+ this.setWakeup();
+
+ this.cookieData=new Mojo.Model.Cookie("credentials");
+ var credentials=this.cookieData.get();
+ if(credentials){
+ _globals.auth=credentials.auth;
+ _globals.uid=credentials.uid;
+ _globals.swf=credentials.swf || "1";
+ }
+ this.username=credentials.username;
+ _globals.auth=credentials.auth;
+
+
+ // Update the feed list
+ foursquareGet(this,{
+ endpoint: 'checkins.json',
+ requiresAuth