Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 103 additions & 38 deletions Resources/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Ti.App.Properties.setBool('map_initialized', false);

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
Ti.API.debug('including the app helpers and windows');

Ti.include(
'march-hare/march-hare.js',
Expand All @@ -18,12 +17,11 @@ Ti.include(

var reportsInitialized = false;

var win = MarchHare.ui.createMapWindow();

win.open();
var tabGroup;
var mapTab;

if (Ti.Platform.osname == 'android') {
var win = Ti.UI.currentWindow;
var win = MarchHare.ui.createMapWindow();
var activity = Ti.Android.currentActivity;

activity.onCreateOptionsMenu = function(e){
Expand All @@ -39,25 +37,77 @@ if (Ti.Platform.osname == 'android') {
settingsWin.open({});
});
};
win.open();
}
/*
else {
// TODO: create iOS options menu
// iOS code might look something like this: where iconWin is an actuall
// icon? I am not sure how menus are done in iOS
var rightButton = Ti.UI.createButton({
systemButton: Ti.UI.iPhone.SystemButton.REFRESH
});
iconWin.rightNavButton = rightButton;
rightButton.addEventListener('click', function () {
Ti.fireEvent('codestrong:update_data');
});
// Create a tab group
tabGroup = Titanium.UI.createTabGroup();

// Create Main tab
var mapWin = MarchHare.ui.createMapWindow();
mapTab = Titanium.UI.createTab({
title: 'Map',
icon: '/img/KS_nav_map.png',
window: mapWin
});

// Create reports win/tab
var reportsWin = MarchHare.ui.createReportsWindow();
var reportsTab = Titanium.UI.createTab({
title: 'Reports',
icon: '/img/KS_nav_ui.png',
window: reportsWin
});

// Add tabs
tabGroup.addTab(mapTab);
tabGroup.addTab(reportsTab);

tabGroup.setActiveTab(mapTab);
tabGroup.open();

// There is a situation where the windows here can be created before the
// incident database is populated. When there are updates to the db then
// we need to recreate these windows because they are not created dynamically
// like they are in the modal windows for android
Ti.App.addEventListener('categoriesDownloaded', function() {
// Create settings win/tab
var settingsWin = MarchHare.ui.createSettingsWindow();
var settingsTab = Titanium.UI.createTab({
title: 'Settings',
icon: '/img/KS_nav_views.png',
window: settingsWin
});
tabGroup.addTab(settingsTab);
});

Ti.App.addEventListener('filterReports', function() {
tabGroup.removeTab(reportsTab);
reportsWin = MarchHare.ui.createReportsWindow();
reportsTab = Titanium.UI.createTab({
title: 'Reports',
icon: '/img/KS_nav_ui.png',
window: reportsWin
});
tabGroup.addTab(reportsTab);
});

Ti.App.addEventListener('newIncidents', function() {
tabGroup.removeTab(reportsTab);
reportsWin = MarchHare.ui.createReportsWindow();
reportsTab = Titanium.UI.createTab({
title: 'Reports',
icon: '/img/KS_nav_ui.png',
window: reportsWin
});
tabGroup.addTab(reportsTab);
});
}
*/

// Set the handler for whe the action midpoint is recieved
// In testing this event does not get recieved until after the settings are
// sent to the map view
// TODO: Does this create a memory leak?
Ti.App.addEventListener('geolocationDownloaded', function() {
updatedActionMidPoint();
});
Expand All @@ -67,12 +117,15 @@ Ti.App.addEventListener('geolocationDownloaded', function() {
// TODO: test with these settings off
if (DEV) {
Ti.App.Properties.setString('lastpoll', '1970-01-01');
MarchHare.database.flushCategories();
MarchHare.database.flushIncidentCategories();
MarchHare.database.flushIncidents();
MarchHare.database.flushIncidentCategories();
MarchHare.database.flushCategories();
Ti.App.Properties.setInt('poll', MarchHare.settings.poll.default_value);
}

// Force a lookup of all categories everytime the application starts
MarchHare.database.initializeCategories();
MarchHare.database.initializeIncidents();
MarchHare.database.initializeMidPoint();

// TODO: in testing I have noticed that this completes before the MapWindow is
Expand All @@ -91,7 +144,7 @@ Ti.App.addEventListener('readyForReports', function() {
// recieve this event. Which means we have a race condition. The effects
// of this should be investigated.
Ti.App.addEventListener('actionDomainChanged', function() {
Ti.API.debug('actionDomainChanged event recieved, updating system');
Ti.API.log('actionDomainChanged event recieved, updating system');
Ti.App.Properties.setString('lastpoll', '1970-01-01');
MarchHare.database.flushIncidents();
MarchHare.database.flushIncidentCategories();
Expand All @@ -103,9 +156,9 @@ Ti.App.addEventListener('actionDomainChanged', function() {

var pollInterval;
Ti.App.addEventListener('mapInitialized', function() {
Ti.API.debug('mapInitialized event recieved');
Ti.API.log('mapInitialized event recieved');
Ti.App.Properties.setBool('map_initialized', true);
Ti.API.debug('polling for new reports every '+
Ti.API.log('polling for new reports every '+
Ti.App.Properties.getInt('poll', MarchHare.settings.poll.default_value)*1000 +
' seconds');
pollInterval = setInterval(pollForReports,
Expand All @@ -114,7 +167,7 @@ Ti.App.addEventListener('mapInitialized', function() {
});

Ti.App.addEventListener('pollIntervalChanged', function() {
Ti.API.debug('pollIntervalChanged event recieved, updating poll interval');
Ti.API.log('pollIntervalChanged event recieved, updating poll interval');
clearInterval(pollInterval);
pollInterval = setInterval(pollForReports,
Ti.App.Properties.getString('poll', MarchHare.settings.poll.default_value)
Expand All @@ -137,14 +190,14 @@ if (Ti.App.Properties.getBool('gpsFollow',
}

Ti.App.addEventListener('gpsFollowChanged', function() {
Ti.API.debug('gpsFollowChanged ('+
Ti.API.log('gpsFollowChanged ('+
Ti.App.Properties.getBool('gpsFollow', 'NOT SET')+
') event recieved, updating location polling');
if (Ti.App.Properties.getBool('gpsFollow',
MarchHare.settings.gpsFollow.default_value)) {
Titanium.Geolocation.addEventListener('location', updateGeoLocationHandler);
} else {
Ti.API.debug('gpsFollowChanged event recieved, clearing gps interval');
Ti.API.log('gpsFollowChanged event recieved, clearing gps interval');

// This handles the privacy concern of a user turning off gpsFollow on
// their device then getting their phone confiscated and the saved location
Expand All @@ -159,7 +212,7 @@ Ti.App.addEventListener('gpsFollowChanged', function() {
});

function updateGeoLocationHandler(location) {
Ti.API.debug('app.js::updateGeoLocationHandler() location: '+
Ti.API.log('app.js::updateGeoLocationHandler() location: '+
JSON.stringify(location));

// Titanium.Geolocation.location: http://bit.ly/GG6qri
Expand Down Expand Up @@ -188,7 +241,7 @@ function updateGeoLocation() {
});

if( Titanium.Geolocation.locationServicesEnabled === false ) {
Ti.API.debug('app.js::updateGeoLocation() device has GPS turned off.');
Ti.API.log('app.js::updateGeoLocation() device has GPS turned off.');
alert.message = 'Your device has GPS turned off. Please turn it on.';
alert.show();
setTimeout(function() {
Expand All @@ -207,7 +260,7 @@ function updateGeoLocation() {
return;
}

Ti.API.debug('app.js::updateGeoLocation location: '+
Ti.API.log('app.js::updateGeoLocation location: '+
JSON.stringify(location.coords));
// TODO: saving geo location on the device could be
// a privacy concern. Can we get around this? For
Expand All @@ -231,7 +284,7 @@ function pollForReports() {
var url = 'http://'+
Ti.App.Properties.getString('action_domain',
MarchHare.settings.action_domain.default_value)+
'/api/?task=decayimage&by=sincedate&date='+lastpoll;
'/api/?task=decayimage&by=sincedate&limit=100&date='+lastpoll;

// TODO: start an indicator
var t = setInterval(function() {
Expand Down Expand Up @@ -308,30 +361,30 @@ function handleServerResponse(response) {

// if we already found a newIncident we dont have to keep checking
if (!newIncidents) {
// Loop across the assigned categories to see if it is one we are i
// Loop across the assigned categories to see if it is one we are
// interested in
for (j in jNewIncidents.payload.incidents[i].categories) {
if (jNewIncidents.payload.incidents[i].categories[j].category.id in categories) {
if ( categories.indexOf(parseInt(jNewIncidents.payload.incidents[i].categories[j].category.id)) != -1) {
newIncidents = true;
}
break;
}
}
}
}
}

if (newIncidents || !initialized) {
Ti.API.debug('pollReports: firing updateReports event, map_initialized: '+
Ti.API.log('pollReports: firing updateReports event, map_initialized: '+
initialized +', newIncidents: '+ newIncidents);
updatedReportsAction();

} else {
Ti.API.debug('pollReports: not updating because we did not recieve any new reports');
Ti.API.log('pollReports: not updating because we did not recieve any new reports');
}

// Create a notification if we recieved new incidents
if (newIncidents && Ti.App.Properties.getBool('vibrate', false)) {
Ti.API.debug('pollReports: triggering an alert');
Titanium.Media.vibrate();
// Let other interested parties do what they want with newIncidents
if (newIncidents) {
Ti.App.fireEvent('newIncidents');
}

if (!error) {
Expand All @@ -340,9 +393,21 @@ function handleServerResponse(response) {
}

Ti.App.addEventListener('filterReports', function() {
Ti.API.log('filterReports event recieved');
updatedReportsAction();
});

Ti.App.addEventListener('newIncidents', function() {
notifyUser();
});

function notifyUser() {
if (Ti.App.Properties.getBool('vibrate', false)) {
Ti.API.log('Vibrating the phone');
Titanium.Media.vibrate();
}
}

function updatedReportsAction() {
result = MarchHare.database.getIncidentsJSON({});

Expand Down
Binary file added Resources/img/KS_nav_map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/img/KS_nav_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/img/KS_nav_views.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions Resources/js/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
(typeof(location.lat) === 'undefined') ||
(typeof(location.lon) === 'undefined')
) {
Ti.API.debug('handleUpdateGeolocation did not recieve location info');
Ti.API.error('handleUpdateGeolocation did not recieve location info');
return;
}

// check to see if it is different then the values we already have
if ( (latitude != location.lat) || (longitude != location.lon) ) {
Ti.API.debug('handleUpdateGeolocation updating the "Current Location" layer');
Ti.API.info('handleUpdateGeolocation updating the "Current Location" layer');
var oldLayer = map.getLayersByName('Current Location');
for (var i = 0; i < oldLayer.length; i++)
{
Expand Down
Loading