Merge lp:~martin-borho/ubuntu-weather-app/reboot-real-weather-data into lp:ubuntu-weather-app

Proposed by Martin Borho
Status: Merged
Approved by: Victor Thompson
Approved revision: no longer in the source branch.
Merged at revision: 7
Proposed branch: lp:~martin-borho/ubuntu-weather-app/reboot-real-weather-data
Merge into: lp:ubuntu-weather-app
Diff against target: 323 lines (+169/-47)
4 files modified
app/components/HomeGraphic.qml (+3/-1)
app/ubuntu-weather-app.qml (+84/-11)
app/ui/HomePage.qml (+81/-30)
po/com.ubuntu.weather.pot (+1/-5)
To merge this branch: bzr merge lp:~martin-borho/ubuntu-weather-app/reboot-real-weather-data
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Andrew Hayzen Needs Information
Review via email: mp+249002@code.launchpad.net

Commit message

Filled static prototype components with real weather data.

Description of the change

Filled static prototype components with real weather data.

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

FAILED: Continuous integration, rev:7
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~martin-borho/ubuntu-weather-app/reboot-real-weather-data/+merge/249002/+edit-commit-message

http://91.189.93.70:8080/job/ubuntu-weather-app-reboot-ci/9/
Executed test runs:
    SUCCESS: http://91.189.93.70:8080/job/ubuntu-weather-app-reboot-vivid-amd64-ci/9

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/ubuntu-weather-app-reboot-ci/9/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :
review: Needs Information
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Just realised we already have Storage.qml, we can make the migration to the
settings api in a future mp.
On 7 Feb 2015 20:20, "Andrew Hayzen" <email address hidden> wrote:

> Review: Needs Information
>
> Looking good so far, could we use Settings {} API instead of a dictionary?
>
> https://developer.ubuntu.com/api/qml/sdk-14.10/Qt.labs.settings.Settings/
>
> http://bazaar.launchpad.net/~music-app-dev/music-app/remix/view/head:/Player.qml#L52
> --
>
> https://code.launchpad.net/~martin-borho/ubuntu-weather-app/reboot-real-weather-data/+merge/249002
> You are reviewing the proposed merge of
> lp:~martin-borho/ubuntu-weather-app/reboot-real-weather-data into
> lp:ubuntu-weather-app/reboot.
>

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

I have 2 inline comments that could use fixing.

review: Needs Fixing
Revision history for this message
Martin Borho (martin-borho) wrote :

Both errors have been fixed!

Btw: We should use string typed properties consistently for any weather-data related QML properties in the ui, because there can be some mismatch between JS and QML types (null, false or "" etc).

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
Victor Thompson (vthompson) wrote :

Looks good, thanks! One small thing, in all the screens I've seen in the spec for the Today view, the large orange current temperature just has the degrees symbol and not the units (F or C)

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
Victor Thompson (vthompson) wrote :

lgtm!

review: Approve
7. By Martin Borho

Filled static prototype components with real weather data.

Approved by Victor Thompson, Ubuntu Phone Apps Jenkins Bot.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/components/HomeGraphic.qml'
2--- app/components/HomeGraphic.qml 2015-02-03 21:26:09 +0000
3+++ app/components/HomeGraphic.qml 2015-02-08 19:33:50 +0000
4@@ -23,6 +23,8 @@
5 height: units.gu(32)
6 width: parent.width
7
8+ property alias icon: iconLabel.text
9+
10 // TODO: will be on 'rails' (horizontal listview?) to reveal hourly forecast
11 Image {
12 anchors {
13@@ -36,10 +38,10 @@
14 color: "#F00"
15
16 Label {
17+ id: iconLabel
18 anchors {
19 centerIn: parent
20 }
21- text: "IMAGE HERE!"
22 }
23 }
24 }
25
26=== modified file 'app/ubuntu-weather-app.qml'
27--- app/ubuntu-weather-app.qml 2015-02-06 15:35:49 +0000
28+++ app/ubuntu-weather-app.qml 2015-02-08 19:33:50 +0000
29@@ -41,20 +41,64 @@
30 useDeprecatedToolbar: false
31 anchorToKeyboard: true
32
33+ /*
34+ List of locations and their data, accessible through index
35+ */
36+ property var locationsList: []
37+
38+ /*
39+ Index of Location before a refresh, to go back after
40+ */
41+ property int indexAtRefresh: -1
42+
43+ /*
44+ Set default values for settings here
45+ */
46+ property var settings: {
47+ "units": Qt.locale().measurementSystem === Locale.MetricSystem ? "metric" : "imperial",
48+ "wind_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "kmh" : "mph",
49+ "precip_units": Qt.locale().measurementSystem === Locale.MetricSystem ? "mm" : "in",
50+ "service": "weatherchannel"
51+ }
52+
53+ /*
54+ Scale symbols and labels.
55+ */
56+ property string tempScale
57+ property string speedScale
58+ property string precipScale
59+ property string tempUnits
60+ property string windUnits
61+ property string precipUnits
62+
63+ /*
64+ After reading the settings from storage and updating the default
65+ settings with the user selected ones, (re)load pages!
66+ */
67 Component.onCompleted: {
68- storage.getLocations(function(locations) {
69- WeatherApi.sendRequest({
70- action: "updateData",
71- params: {
72- locations:locations,
73- force:false,
74- service: "weatherchannel",
75- api_key: Key.twcKey
76- }
77- }, responseDataHandler)
78+ storage.getSettings(function(storedSettings) {
79+ for(var settingName in storedSettings) {
80+ settings[settingName] = storedSettings[settingName];
81+ }
82+ setScalesAndLabels();
83+ refreshData();
84 })
85 }
86
87+ function setScalesAndLabels() {
88+ // set scales
89+ tempScale = String("°") + ((settings["units"] === "imperial") ? "F" : "C")
90+ speedScale = ((settings["wind_units"] === "mph") ? "mph" : "km/h")
91+ precipScale = ((settings["precip_units"] === "in") ? "in" : "mm")
92+ tempUnits = ((settings["units"] === 'imperial') ? 'imperial' : 'metric')
93+ windUnits = ((settings["wind_units"] === 'mph') ? 'imperial' : 'metric')
94+ precipUnits = ((settings["precip_units"] === 'in') ? 'imperial' : 'metric')
95+ }
96+
97+ /*
98+ Handle response data from data backend. Checks if a location
99+ was updated and has to be stored again.
100+ */
101 function responseDataHandler(messageObject) {
102 if(!messageObject.error) {
103 if(messageObject.action === "updateData") {
104@@ -65,7 +109,7 @@
105 }
106 });
107 //print(JSON.stringify(messageObject.result));
108- //buildTabs(messageObject.result);
109+ fillPages(messageObject.result);
110 }
111 } else {
112 console.log(messageObject.error.msg+" / "+messageObject.error.request.url)
113@@ -73,6 +117,35 @@
114 }
115 }
116
117+ /* Fill the location pages with their data. */
118+ function fillPages(locations) {
119+ locationsList = locations;
120+ // refactor this when Location are in a ListView!
121+ homePage.renderData();
122+ }
123+
124+ /*
125+ Refresh data, either directly from storage or by checking against
126+ API instead.
127+ */
128+ function refreshData(from_storage, force_refresh) {
129+ if(from_storage === true && force_refresh !== true) {
130+ storage.getLocations(fillPages);
131+ } else {
132+ storage.getLocations(function(locations) {
133+ WeatherApi.sendRequest({
134+ action: "updateData",
135+ params: {
136+ locations:locations,
137+ force:force_refresh,
138+ service:settings["service"],
139+ api_key: Key.twcKey
140+ }
141+ }, responseDataHandler)
142+ });
143+ }
144+ }
145+
146 Data.Storage {
147 id: storage
148 }
149
150=== modified file 'app/ui/HomePage.qml'
151--- app/ui/HomePage.qml 2015-02-03 21:26:09 +0000
152+++ app/ui/HomePage.qml 2015-02-08 19:33:50 +0000
153@@ -24,14 +24,85 @@
154
155 Page {
156 // Set to null otherwise the header is shown (but blank) over the top of the listview
157+ id: locationPage
158 flickable: null
159
160+ /*
161+ Data properties
162+ */
163+ property string name;
164+ property string conditionText
165+ property string currentTemp
166+ property string todayMaxTemp
167+ property string todayMinTemp
168+ property string iconName
169+
170+ // TODO map iconnames to source image names
171+ property var iconMap: {
172+ "moon": "moon.svg"
173+ // etc pp
174+ }
175+
176+ /*
177+ Format date object by given format.
178+ */
179+ function formatTimestamp(dateData, format) {
180+ var date = new Date(dateData.year, dateData.month, dateData.date, dateData.hours, dateData.minutes)
181+ return Qt.formatDate(date, i18n.tr(format))
182+ }
183+
184+ /*
185+ Extracts values from the location weather data and puts them into the appropriate components
186+ to display them.
187+
188+ Attention: Data access happens through "weatherApp.locationList[]" by index, since complex
189+ data in models will lead to type problems.
190+ */
191+ function renderData() {
192+ var index = Math.floor(Math.random()*weatherApp.locationsList.length), // TODO get this value from ListView.currentIndex later!
193+ data = weatherApp.locationsList[index],
194+ current = data.data[0].current,
195+ forecasts = data.data,
196+ forecastsLength = forecasts.length,
197+ today = forecasts[0],
198+ tempUnits = weatherApp.tempUnits,
199+ tempScale = weatherApp.tempScale;
200+
201+ // set general location data
202+ name = data.location.name;
203+
204+ // set current temps and condition
205+ iconName = (current.icon) ? current.icon : ""
206+ conditionText = (current.condition.main) ? current.condition.main : current.condition; // difference TWC/OWM
207+ todayMaxTemp = (today[tempUnits].tempMax) ? Math.round(today[tempUnits].tempMax).toString() + tempScale: "";
208+ todayMinTemp = Math.round(today[tempUnits].tempMin).toString() + tempScale;
209+ currentTemp = Math.round(current[tempUnits].temp).toString() + String("°");
210+
211+ // reset days list
212+ mainPageWeekdayListView.model.clear()
213+
214+ // set daily forecasts
215+ if(forecastsLength > 0) {
216+ for(var x=1;x<forecastsLength;x++) {
217+ // print(JSON.stringify(forecasts[x][units]))
218+ var dayData = {
219+ day: formatTimestamp(forecasts[x].date, 'dddd'),
220+ low: Math.round(forecasts[x][tempUnits].tempMin).toString() + tempScale,
221+ high: (forecasts[x][tempUnits].tempMax !== undefined) ? Math.round(forecasts[x][tempUnits].tempMax).toString() + tempScale : "",
222+ image: (forecasts[x].icon !== undefined && iconMap[forecasts[x].icon] !== undefined) ? iconMap[forecasts[x].icon] + tempScale : ""
223+ }
224+ mainPageWeekdayListView.model.append(dayData);
225+ }
226+ }
227+ }
228+
229 ListView {
230 id: mainPageWeekdayListView
231 anchors {
232 fill: parent
233 margins: units.gu(2)
234 }
235+
236 header: Column {
237 anchors {
238 left: parent.left
239@@ -40,50 +111,30 @@
240 spacing: units.gu(1)
241
242 HeaderRow {
243- locationName: "Hackney" // TODO: non static
244+ locationName: locationPage.name
245 }
246
247 HomeGraphic {
248-
249+ icon: locationPage.iconName
250 }
251
252 HomeTempInfo {
253- description: i18n.tr("Rainy & windy") // TODO: non static
254- high: "13°C"
255- low: "10°C"
256- now: "13°" // TODO: non static
257+ description: locationPage.conditionText
258+ high: locationPage.todayMaxTemp
259+ low: locationPage.todayMinTemp
260+ now: locationPage.currentTemp
261 }
262
263 ListItem.ThinDivider {
264
265 }
266 }
267- model: ListModel { // TODO: non static
268- ListElement {
269- day: "Saturday"
270- low: 12
271- high: 15
272- }
273- ListElement {
274- day: "Sunday"
275- low: 14
276- high: 18
277- }
278- ListElement {
279- day: "Monday"
280- low: 10
281- high: 11
282- }
283- ListElement {
284- day: "Tuesday"
285- low: -7
286- high: 0
287- }
288- }
289+ model: ListModel {}
290+
291 delegate: DayDelegate {
292 day: model.day
293- high: model.high + "°C" // TODO: non static
294- low: model.low + "°C"
295+ high: model.high
296+ low: model.low
297 }
298 }
299 }
300
301=== modified file 'po/com.ubuntu.weather.pot'
302--- po/com.ubuntu.weather.pot 2015-02-03 21:26:09 +0000
303+++ po/com.ubuntu.weather.pot 2015-02-08 19:33:50 +0000
304@@ -8,7 +8,7 @@
305 msgstr ""
306 "Project-Id-Version: ubuntu-weather-app\n"
307 "Report-Msgid-Bugs-To: \n"
308-"POT-Creation-Date: 2015-02-03 21:25+0000\n"
309+"POT-Creation-Date: 2015-02-07 18:30+0100\n"
310 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
311 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
312 "Language-Team: LANGUAGE <LL@li.org>\n"
313@@ -21,10 +21,6 @@
314 msgid "Today"
315 msgstr ""
316
317-#: ../app/ui/HomePage.qml:51
318-msgid "Rainy & windy"
319-msgstr ""
320-
321 #: ubuntu-weather-app.desktop.in.in.h:1
322 msgid "Weather"
323 msgstr ""

Subscribers

People subscribed via source and target branches

to all changes: