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

Proposed by Victor Thompson
Status: Merged
Approved by: Andrew Hayzen
Approved revision: 49
Merged at revision: 48
Proposed branch: lp:~vthompson/ubuntu-weather-app/reboot-manage-current-location
Merge into: lp:ubuntu-weather-app
Diff against target: 95 lines (+37/-6)
3 files modified
app/components/CurrentLocation.qml (+24/-2)
app/ubuntu-weather-app.qml (+13/-1)
app/ui/LocationsPage.qml (+0/-3)
To merge this branch: bzr merge lp:~vthompson/ubuntu-weather-app/reboot-manage-current-location
Reviewer Review Type Date Requested Status
Andrew Hayzen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+260648@code.launchpad.net

Commit message

* Manage current location

Description of the change

Manage current location as the first entry in the Locations List. An additional MP will need to be made to deal with preventing reordering of the first item and preventing the deletion of the first item.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Two inline code comments while I play about with the app.

review: Needs Fixing
Revision history for this message
Victor Thompson (vthompson) wrote :

See inline responses.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

These steps sort of re-enforce/add to/prove the issue of the second inline comment.

1) Start the app wait for location lock
2) Add a custom new location
3) Swipe remove detected location
4) Restart the app
5) Wait for location lock, oh the custom location has been overwritten!

So either we need a way in the model to know if the first location was auto detected or prevent the detected location to be removed. (Note the former is probably required to satisfy data migration anyway?)

Revision history for this message
Victor Thompson (vthompson) wrote :

As stated in the description, we'll need additional work to prevent reordering and prevent deletion/overwriting of the user's first location.

48. By Victor Thompson

Remove redundant refresh, force is needed.

Revision history for this message
Victor Thompson (vthompson) wrote :

I modified the redundant refresh to just do a single refresh with the force flag as true. The force is necessary because the location is possibly changing. Without it the data does not update.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
49. By Victor Thompson

Merge of trunk

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

LGTM, thanks for the extra changes :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/components/CurrentLocation.qml'
2--- app/components/CurrentLocation.qml 2015-05-20 00:01:46 +0000
3+++ app/components/CurrentLocation.qml 2015-06-05 23:10:47 +0000
4@@ -20,6 +20,7 @@
5 import QtPositioning 5.2
6 import QtQuick 2.3
7 import Ubuntu.Components 1.1
8+import "../data/WeatherApi.js" as WeatherApi
9
10
11 Item {
12@@ -27,6 +28,26 @@
13
14 property string string: "Undefined"
15
16+ function searchForLocation(lat, lon) {
17+ WeatherApi.sendRequest({
18+ action: "searchByPoint",
19+ params: {
20+ coords: {
21+ lat: lat,
22+ lon: lon
23+ }
24+ }
25+ }, searchResponseHandler)
26+ }
27+
28+ function searchResponseHandler(msgObject) {
29+ if (!msgObject.error) {
30+ console.log("Loc to add:", JSON.stringify(msgObject.result.locations[0]))
31+ storage.updateCurrentLocation(msgObject.result.locations[0])
32+ }
33+ }
34+
35+
36 PositionSource {
37 id: currentPosition
38 updateInterval: 1000
39@@ -54,8 +75,9 @@
40 onCountChanged: {
41 // Update the currentLocation if one is found and it does not match the stored location
42 if (count > 0 && currentLocation.string !== geocodeModel.get(0).address.city) {
43- currentLocation.string = geocodeModel.get(0).address.city
44- refreshData(false, true)
45+ var loc = geocodeModel.get(0)
46+ currentLocation.string = loc.address.city
47+ searchForLocation(loc.coordinate.latitude, loc.coordinate.longitude)
48 }
49 }
50 }
51
52=== modified file 'app/ubuntu-weather-app.qml'
53--- app/ubuntu-weather-app.qml 2015-05-19 01:14:08 +0000
54+++ app/ubuntu-weather-app.qml 2015-06-05 23:10:47 +0000
55@@ -167,13 +167,25 @@
56 Data.Storage {
57 id: storage
58
59+ // Add or replace the current locaiton to the storage and refresh the
60+ // locationList
61+ function updateCurrentLocation(location) {
62+ if (locationsList == null || locationsList.length == 0) {
63+ storage.insertLocation({location: location});
64+ } else {
65+ storage.updateLocation(locationsList[0].db.id, {location: location});
66+ }
67+
68+ refreshData(false, true);
69+ }
70+
71 // Add the location to the storage and refresh the locationList
72 // Return true if a location is added
73 function addLocation(location) {
74 var exists = checkLocationExists(location)
75
76 if(!exists) {
77- if(location.dbId === undefined || location.dbId=== 0) {
78+ if(location.dbId === undefined || location.dbId === 0) {
79 storage.insertLocation({location: location});
80 }
81 refreshData();
82
83=== modified file 'app/ui/LocationsPage.qml'
84--- app/ui/LocationsPage.qml 2015-05-20 00:08:32 +0000
85+++ app/ui/LocationsPage.qml 2015-06-05 23:10:47 +0000
86@@ -139,9 +139,6 @@
87 var loc = {}, data = {},
88 tempUnits = settings.tempScale === "°C" ? "metric" : "imperial";
89
90- // TODO: Manage the current location as an entry in the locationsList.
91- locationsModel.append({ "name": currentLocation.string, "temp": "0", "icon": "weather-clear-symbolic" })
92-
93 for (var i=0; i < weatherApp.locationsList.length; i++) {
94 data = weatherApp.locationsList[i];
95 loc = {

Subscribers

People subscribed via source and target branches

to all changes: