Browse Source

@added view for alert

halphass 7 years ago
parent
commit
b9dfcb9727
4 changed files with 100 additions and 6 deletions
  1. 17 3
      plugins/android.json
  2. 34 0
      plugins/fetch.json
  3. 15 0
      www/index.html
  4. 34 3
      www/js/main.js

+ 17 - 3
plugins/android.json

@@ -7,15 +7,29 @@
         "files": {}
     },
     "installed_plugins": {
-        "cordova-plugin-whitelist": {
+        "cordova-plugin-network-information": {
             "PACKAGE_NAME": "xm24.digitigrafo.it"
         },
-        "cordova-plugin-network-information": {
+        "cordova-plugin-whitelist": {
             "PACKAGE_NAME": "xm24.digitigrafo.it"
         },
         "cordova-sqlite-storage": {
             "PACKAGE_NAME": "xm24.digitigrafo.it"
+        },
+        "phonegap-plugin-push": {
+            "SENDER_ID": "667898382143",
+            "PACKAGE_NAME": "xm24.digitigrafo.it"
+        },
+        "cordova-plugin-media": {
+            "PACKAGE_NAME": "xm24.digitigrafo.it"
         }
     },
-    "dependent_plugins": {}
+    "dependent_plugins": {
+        "cordova-plugin-compat": {
+            "PACKAGE_NAME": "xm24.digitigrafo.it"
+        },
+        "cordova-plugin-file": {
+            "PACKAGE_NAME": "xm24.digitigrafo.it"
+        }
+    }
 }

+ 34 - 0
plugins/fetch.json

@@ -15,6 +15,16 @@
         "is_top_level": true,
         "variables": {}
     },
+    "phonegap-plugin-push": {
+        "source": {
+            "type": "registry",
+            "id": "phonegap-plugin-push@1.9.4"
+        },
+        "is_top_level": true,
+        "variables": {
+            "SENDER_ID": "667898382143"
+        }
+    },
     "cordova-sqlite-storage": {
         "source": {
             "type": "registry",
@@ -22,5 +32,29 @@
         },
         "is_top_level": true,
         "variables": {}
+    },
+    "cordova-plugin-media": {
+        "source": {
+            "type": "registry",
+            "id": "cordova-plugin-media@3.0.0"
+        },
+        "is_top_level": true,
+        "variables": {}
+    },
+    "cordova-plugin-file": {
+        "source": {
+            "type": "registry",
+            "id": "cordova-plugin-file"
+        },
+        "is_top_level": false,
+        "variables": {}
+    },
+    "cordova-plugin-compat": {
+        "source": {
+            "type": "registry",
+            "id": "cordova-plugin-compat"
+        },
+        "is_top_level": false,
+        "variables": {}
     }
 }

+ 15 - 0
www/index.html

@@ -375,6 +375,21 @@
         <!--chiude content -->
     </div>
     <!-- chiude pagina -->
+    <div data-role="page" id="alert" data-prev="index" data-next="" data-dom-cache="true" data-theme="a" class="ui-page">
+
+        <div role="main" class="ui-content">
+
+            <div class="ui-body" style="text-align: center">
+                <p><img src="image/xm-logo.png" class="rwd" /></p>
+                <h1 class="introlettera" id="alert-title"></h1>
+                <h2 id="alert-message"></h2>
+                <button onclick="spengimi()" id="spegni-musica">Ferma Musica</button>
+            </div>
+            <!-- chiude body-->
+        </div>
+        <!--chiude content -->
+    </div>
+    <!-- chiude pagina -->
 </body>
 
 </html>

+ 34 - 3
www/js/main.js

@@ -832,6 +832,11 @@ function checkAndReset() {
 
 
 var my_media = {};
+function spengimi() {
+    my_media.stop();
+    $("#alert-title").hide();
+    
+}
 function onDeviceReadyPush() {
     var push = PushNotification.init({
         android: {
@@ -848,15 +853,43 @@ function onDeviceReadyPush() {
         windows: {}
     });
 
+    /*
+     * registra l'id univoco dell'installazione su xm.bus.pm
+     */
     push.on('registration', function(registration) {
-        // console.log(JSON.stringify(registration));
+        console.log(JSON.stringify(registration));
         var url = "https://xm.bus.pm/api/d/c?device=" + registration.registrationId;
         $.get(url, function( data ) {
             console.log(JSON.stringify(data));
         });
     });
 
+    /*
+     * gestisce la notifica ricevuta
+     */
     push.on('notification', function(data) {
+        // console.log(JSON.stringify(data));
+        // alert(JSON.stringify(data));
+        /*
+         {
+             "title": "ciaooo",
+             "message": "ciaone",
+             "additionalData": {
+             "google.message_id": "0:1489146072171053%91acc10daee52ff4",
+                 "coldstart": false,
+                 "collapse_key": "ciaooo",
+                 "foreground": true
+             }
+         }
+         */
+
+        $("body").pagecontainer("change", "#alert");
+        $("#alert-title").html(data.title);
+        $("#alert-message").html(data.message);
+
+        /*
+         * suona l'allarme
+         */
         my_media = new Media("/android_asset/www/media/alarm.wav",
             // success callback
             function () {
@@ -868,8 +901,6 @@ function onDeviceReadyPush() {
             }
         );
         my_media.play();
-        console.log(JSON.stringify(data));
-        alert(JSON.stringify(data));
     });
 
     push.on('error', function(e) {