← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~vthompson/ubuntu-weather-app/reboot-manage-current-location into lp:ubuntu-weather-app/reboot

 

Victor Thompson has proposed merging lp:~vthompson/ubuntu-weather-app/reboot-manage-current-location into lp:ubuntu-weather-app/reboot.

Commit message:
* Manage current location

Requested reviews:
  Ubuntu Weather Developers (ubuntu-weather-dev)

For more details, see:
https://code.launchpad.net/~vthompson/ubuntu-weather-app/reboot-manage-current-location/+merge/260648

Manage current location
-- 
Your team Ubuntu Weather Developers is requested to review the proposed merge of lp:~vthompson/ubuntu-weather-app/reboot-manage-current-location into lp:ubuntu-weather-app/reboot.
=== modified file 'app/components/CurrentLocation.qml'
--- app/components/CurrentLocation.qml	2015-05-20 00:01:46 +0000
+++ app/components/CurrentLocation.qml	2015-05-31 21:36:25 +0000
@@ -20,6 +20,7 @@
 import QtPositioning 5.2
 import QtQuick 2.3
 import Ubuntu.Components 1.1
+import "../data/WeatherApi.js" as WeatherApi
 
 
 Item {
@@ -27,6 +28,27 @@
 
     property string string: "Undefined"
 
+    function searchForLocation(lat, lon) {
+        WeatherApi.sendRequest({
+                                   action: "searchByPoint",
+                                   params: {
+                                       coords: {
+                                           lat: lat,
+                                           lon: lon
+                                       }
+                                   }
+                               }, searchResponseHandler)
+    }
+
+    function searchResponseHandler(msgObject) {
+        if (!msgObject.error) {
+            console.log("Loc to add:", JSON.stringify(msgObject.result.locations[0]))
+            storage.updateCurrentLocation(msgObject.result.locations[0])
+            refreshData(false, true)
+        }
+    }
+
+
     PositionSource {
         id: currentPosition
         updateInterval: 1000
@@ -54,8 +76,9 @@
         onCountChanged: {
             // Update the currentLocation if one is found and it does not match the stored location
             if (count > 0 && currentLocation.string !== geocodeModel.get(0).address.city) {
-                currentLocation.string = geocodeModel.get(0).address.city
-                refreshData(false, true)
+                var loc = geocodeModel.get(0)
+                currentLocation.string = loc.address.city
+                searchForLocation(loc.coordinate.latitude, loc.coordinate.longitude)
             }
         }
     }

=== modified file 'app/ubuntu-weather-app.qml'
--- app/ubuntu-weather-app.qml	2015-05-19 01:14:08 +0000
+++ app/ubuntu-weather-app.qml	2015-05-31 21:36:25 +0000
@@ -167,13 +167,25 @@
     Data.Storage {
         id: storage
 
+        // Add or replace the current locaiton to the storage and refresh the
+        // locationList
+        function updateCurrentLocation(location) {
+            if (locationsList == null || locationsList.length == 0) {
+                storage.insertLocation({location: location});
+            } else {
+                storage.updateLocation(locationsList[0].db.id, {location: location});
+            }
+
+            refreshData();
+        }
+
         // Add the location to the storage and refresh the locationList
         // Return true if a location is added
         function addLocation(location) {
             var exists = checkLocationExists(location)
 
             if(!exists) {
-                if(location.dbId === undefined || location.dbId=== 0) {
+                if(location.dbId === undefined || location.dbId === 0) {
                     storage.insertLocation({location: location});
                 }
                 refreshData();

=== modified file 'app/ui/LocationsPage.qml'
--- app/ui/LocationsPage.qml	2015-05-20 00:08:32 +0000
+++ app/ui/LocationsPage.qml	2015-05-31 21:36:25 +0000
@@ -139,9 +139,6 @@
         var loc = {}, data = {},
             tempUnits = settings.tempScale === "°C" ? "metric" : "imperial";
 
-        // TODO: Manage the current location as an entry in the locationsList.
-        locationsModel.append({ "name": currentLocation.string, "temp": "0", "icon": "weather-clear-symbolic" })
-
         for (var i=0; i < weatherApp.locationsList.length; i++) {
             data = weatherApp.locationsList[i];
             loc = {


Follow ups