Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Bug Fixes and Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
imZack committed Aug 27, 2014
1 parent 6f8928d commit 90dee3a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 46 deletions.
4 changes: 2 additions & 2 deletions appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"shortName": "Uber Now",
"uuid": "6042f1f3-b387-45f4-a288-e0db3cc15e68",
"versionCode": 3,
"versionLabel": "1.3",
"versionCode": 4,
"versionLabel": "1.4",
"watchapp": {
"watchface": false
}
Expand Down
77 changes: 33 additions & 44 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var ajax = require('ajax');
var Vibe = require('ui/vibe');

// Variables
var config_url = "";
var isUpdating = false;
var main_window = new UI.Window();
var info_text = new UI.Text({
position: new Vector2(0, 50),
size: new Vector2(144, 30),
font: 'gothic-24-bold',
text: 'Uber Now',
textAlign: 'center'
position: new Vector2(0, 50),
size: new Vector2(144, 30),
font: 'gothic-24-bold',
text: 'Uber Now',
textAlign: 'center'
});

var anykey_text = new UI.Text({
Expand All @@ -35,6 +35,7 @@ function locationError(err) {
console.warn('location error (' + err.code + '): ' + err.message);
info_text.text('Can\'t get location.');
info_text.font('gothic-18-bold');
isUpdating = false;
}

function showUber(times) {
Expand All @@ -45,73 +46,61 @@ function showUber(times) {
return;
}

var items = [];
times.forEach(function(product) {
var items = [];
times.forEach(function(product) {
product.surge_multiplier = product.surge_multiplier || 1;
var title = product.display_name;
if (product.surge_multiplier !== 1) {
title += ' *' + Number(product.surge_multiplier).toFixed(2);
}
var item = {
title: title,
subtitle: 'pick up time: ' +
var item = {
title: title,
subtitle: 'pick up time: ' +
Math.ceil(product.estimate / 60) + ' mins',
product_id: product.product_id
};
items.push(item);
});

var menu = new UI.Menu({
sections: [{
items: items
}]
});

menu.on('select', function(e) {
console.log(JSON.stringify(e.item));
var url = 'uber://?action=setPickup&product_id=' + e.item.product_id +
'&pickup=my_location';
config_url = url;
console.log(config_url);
};
items.push(item);
});

menu.on('click', 'back', function() {
console.log('menu back');
window.navigator.geolocation.watchPosition(locationSuccess,
locationError, locationOptions);
var menu = new UI.Menu({
sections: [{
items: items
}]
});

menu.show();
menu.show();
}

function fetchUber(coords) {
var params = 'latitude=' + coords.latitude +
'&longitude=' + coords.longitude;
ajax({ url: 'http://pebble-uber.yulun.me/?' + params, type: 'json' },
function(data) {
var params = 'latitude=' + coords.latitude +
'&longitude=' + coords.longitude +
'&pebble=1';
ajax({ url: 'http://pebble-uber.yulun.me/?' + params, type: 'json' },
function(data) {
info_text.text('Uber Now');
info_text.font('gothic-24-bold');
Vibe.vibrate('double');
showUber(data.times);
},
showUber(data.times);
isUpdating = false;
},
function() {
info_text.text('Connection Error');
info_text.font('gothic-18-bold');
isUpdating = false;
}
);
}

function update() {
if (isUpdating) return;
isUpdating = true;
info_text.text('Updating...');
info_text.font('gothic-24-bold');
window.navigator.geolocation.watchPosition(locationSuccess,
locationError, locationOptions);
window.navigator.geolocation.getCurrentPosition(locationSuccess,
locationError,
locationOptions);
}

Pebble.addEventListener("showConfiguration", function() {
Pebble.openURL(config_url);
});

main_window.on('click', 'up', update);
main_window.on('click', 'down', update);
main_window.on('click', 'select', update);
Expand Down

0 comments on commit 90dee3a

Please sign in to comment.