Browse files

Had to restructure everything. Better now.

  • Loading branch information...
1 parent 452dd17 commit 9f39da59ada4b2cfd391234b5d4874cc70d36fd8 @mikeymckay mikeymckay committed Jan 8, 2014
View
17 android_app/AndroidManifest.xml
@@ -29,6 +29,9 @@
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+
+
<application android:icon="@drawable/icon" android:label="@string/app_name"
@@ -42,6 +45,20 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
+
+ <!-- For background service -->
+ <service android:name="org.rti.pomegranate.MyService">
+ <intent-filter>
+ <action android:name="org.rti.pomegranate.MyService"/>
+ </intent-filter>
+ </service>
+
+ <receiver android:name="com.red_folder.phonegap.plugin.backgroundservice.BootReceiver">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED"></action>
+ </intent-filter>
+ </receiver>
+
</application>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
View
1 android_app/assets/www/index.html
@@ -77,6 +77,7 @@
<script type="text/javascript" src="js/lib/moment.min.js"></script>
<script type="text/javascript" src="js/lib/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/lib/bootbox.min.js"></script>
+ <script type="text/javascript" src="js/lib/backgroundService-2.9.0.js"></script>
<script type="text/javascript" src="js/pomegranate.js"></script>
</body>
View
13 android_app/assets/www/js/pomegranate.coffee
@@ -145,6 +145,17 @@ P.config =
P.boot = ->
+ # Run in background
+ console.log "Starting service"
+
+ cordova.define 'cordova/plugin/myService', (require,exports,module) ->
+ CreateBackgroundService('org.rti.pomegranate.MyService', require, exports, module)
+
+ (cordova.require('cordova/plugin/myService')).startService( (r) -> console.log "Started #{JSON.stringify r}", (r) -> console.log "Failed to start #{JSON.stringify r}")
+ console.log "Service started"
+
+
+
P.sender = cordova.require('cordova/plugin/smssendingplugin')
P.sender.isSupported (supported) ->
@@ -175,8 +186,6 @@ P.boot = ->
console.log "Trying to load config from database"
P.db.get 'config',
(error,doc) ->
- U.log JSON.stringify doc
- U.log doc?
if doc?
console.log "Found a config: #{JSON.stringify doc}"
P.config = doc
View
12 android_app/assets/www/js/pomegranate.js
@@ -173,6 +173,16 @@ P.config = {
P.boot = function() {
var e;
+ console.log("Starting service");
+ cordova.define('cordova/plugin/myService', function(require, exports, module) {
+ return CreateBackgroundService('org.rti.pomegranate.MyService', require, exports, module);
+ });
+ (cordova.require('cordova/plugin/myService')).startService(function(r) {
+ return console.log("Started " + (JSON.stringify(r)), function(r) {
+ return console.log("Failed to start " + (JSON.stringify(r)));
+ });
+ });
+ console.log("Service started");
P.sender = cordova.require('cordova/plugin/smssendingplugin');
P.sender.isSupported(function(supported) {
if (!supported) {
@@ -211,8 +221,6 @@ P.boot = function() {
$.extend(P.db, _db);
console.log("Trying to load config from database");
return P.db.get('config', function(error, doc) {
- U.log(JSON.stringify(doc));
- U.log(doc != null);
if (doc != null) {
console.log("Found a config: " + (JSON.stringify(doc)));
P.config = doc;
View
1 android_app/res/xml/config.xml
@@ -75,5 +75,6 @@
<plugins>
<plugin name="SmsSendingPlugin" value="org.apache.cordova.plugin.SmsSendingPlugin" />
<plugin name="ReadSms" value="net.webootu.cordova.plugin.ReadSms" />
+ <plugin name="BackgroundServicePlugin" value="com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin"/>
</plugins>
</widget>
View
5 cloud_app/_attachments/index.html
@@ -6,8 +6,11 @@
<div id='header'>
<h1>Pomegranate <a id='reference_url' href=''></a></h1><div id='menu'></div>
</div>
- <div id='content'></div>
<div id='send'></div>
+ <div id='sent'></div>
+ <div id='received'></div>
+ <div id='configure'></div>
+ <div id='selectProject'></div>
<div id='group-manager'></div>
View
125 cloud_app/_attachments/router.coffee
@@ -1,57 +1,50 @@
class Router extends Backbone.Router
+
+ initialize: ->
+ @menuItems = "send,sent,received,configure,selectProject".split(/,/)
+ @sendView = new SendView
+ @receivedView = new ReceivedView
+ @sentView = new SentView
+ @configureView = new ConfigureView
+ @selectProjectView = new SelectProjectView
+
routes:
- ":project/send" : "send"
- ":project/received" : "received"
- ":project/sent" : "sent"
- ":project" : "menu"
- ":project/configure" : "configure"
- "" : "selectProject"
-
- configure: (project) ->
- @menu(project)
- configureView = new ConfigureView
- configureView.project = project
- configureView.render()
-
- selectProject: ->
- $("#menu").html ""
- $("#content").html "
- Enter your project name:
- <input onChange='document.location=\"#\"+$(event.target).val()\' type='text'></input>
- "
- menu: (project) ->
- $("#content").html ""
+ ":project/:action" : "action"
+ ":project" : "action"
+ "" : "action"
+
+ updateProject: (project) ->
+ if @project?
+ $.couch.db(@project).changes().stop()
+
+ @project = project
+
+ $.couch.db(@project).changes().onChange =>
+ @sendView.render()
+ @receivedView.render()
+
$("#menu").html "
#{
- (for option in "send,sent,received,configure".split(/,/)
- "<a role='button' href='##{project}/#{option}'>#{option}</a>"
+ (for item in @menuItems
+ "<a role='button' href='##{@project}/#{item}'>#{item}</a>"
).join("")
}
- <a role='button' href='#'>select project</a>
"
- send: (project) ->
- @menu(project)
- sendView = new SendView
- sendView.project = project
- sendView.render()
-
- groupManager = new GroupManager
- groupManager.render()
-
- received: (project) ->
- @menu(project)
- receivedView = new ReceivedView
- receivedView.project = project
- receivedView.render()
-
- sent: (project) ->
- @menu(project)
- sentView = new SentView
- sentView.project = project
- sentView.render()
-
-
+ @navigate "#{@project}", true
+
+ action: (project,action) ->
+ console.log project
+ console.log action
+ if project? and not @project?
+ @updateProject(project)
+ action = 'selectProject' unless project
+ action = 'send' unless action
+ console.log action
+ this["#{action}View"].project = project
+ this["#{action}View"].render()
+ $("##{item}").hide() for item in @menuItems
+ $("##{action}").show()
class Person extends Backbone.Model
url: "person"
@@ -304,9 +297,25 @@ class Message extends Backbone.Model
url: "message"
+class SelectProjectView extends Backbone.View
+
+ el: "#selectProject"
+
+ events:
+ "change input#projectName" : "updateProject"
+
+ updateProject: ->
+ Pomegranate.router.updateProject($("#projectName").val())
+
+ render: ->
+ @$el.html "
+ Enter your project name:
+ <input id='projectName' type='text'></input>
+ "
+
class ConfigureView extends Backbone.View
- el: "#content"
+ el: "#configure"
events:
"click #save_google_form_url" : "save"
@@ -318,7 +327,7 @@ class ConfigureView extends Backbone.View
}
render: ->
- $("#content").html "
+ @$el.html "
URL for #{@project} live google form:
<ol>
@@ -333,19 +342,15 @@ class ConfigureView extends Backbone.View
class SentView extends Backbone.View
- el: "#content"
+ el: "#sent"
events:
"click .send" : "send"
render: ->
- # Rerender if something changes
- $.couch.db(@project).changes().onChange =>
- @render()
-
columns = "Time, To, Message".split(/,/)
- $("#content").html "
+ @$el.html "
<h2>Sent Messages</h2>
<table id='sentMessages'>
<thead>
@@ -394,19 +399,16 @@ class SentView extends Backbone.View
class ReceivedView extends Backbone.View
- el: "#content"
+ el: "#received"
events:
"click .send" : "send"
render: =>
- # Rerender if something changes
- $.couch.db(@project).changes().onChange =>
- @render()
columns = "Time, From, Message".split(/,/)
- $("#content").html "
+ @$el.html "
<h2>Received Messages</h2>
<table id='receivedMessages'>
<thead>
@@ -452,7 +454,7 @@ class ReceivedView extends Backbone.View
class SendView extends Backbone.View
- el: "#content"
+ el: "#send"
events:
"click .send" : "send"
@@ -466,7 +468,6 @@ class SendView extends Backbone.View
clearNumbers : -> @$el.find("#numbers").val(''); @countNumbers()
render: ->
- console.log @project
@$el.html "
<div>
@@ -503,6 +504,8 @@ class SendView extends Backbone.View
message: $("#text").val()
to: number
}
+
+ Pomegranate.router.navigate "#{@project}/sent", true
countNumbers: ->
value = $("#numbers").val()
View
2 cloud_app/_attachments/version
@@ -1 +1 @@
-4b45305
+452dd17

0 comments on commit 9f39da5

Please sign in to comment.