on xenial help sign in
Reload Infographics userdata when the screen turns on in case the day changed
3d51efbTomás Tormo
qml/Greeter/Infographics.qml+36−15
@@ -17,6 +17,7 @@
17import "Gradient.js" as Gradient
17import "Gradient.js" as Gradient
18import QtQuick 2.4
18import QtQuick 2.4
19import Ubuntu.Components 1.3
19import Ubuntu.Components 1.3
20+import Powerd 0.1
20
21
21Item {
22Item {
22 id: infographic
23 id: infographic
@@ -25,7 +26,7 @@ Item {
25
26
26 property int animDuration: 10
27 property int animDuration: 10
27
28
28− property int currentDay: -1 // Boot time value
29+ property int currentWeekDay
29
30
30 QtObject {
31 QtObject {
31 id: d
32 id: d
@@ -58,22 +59,40 @@ Item {
58 onDataDisappeared: startShowAnimation() // show "no data" label
59 onDataDisappeared: startShowAnimation() // show "no data" label
59 }
60 }
60
61
62+ Connections {
63+ id: screenState
64+ target: Powerd
61
65
62− function startShowAnimation() {
66+ onStatusChanged: {
63− if(currentDay !== model.currentDay){
67+ if(Powerd.status === Powerd.On){
64− currentDay = model.currentDay
68+ handleScreenOn()
65− model.nextDataSource();
66− }else{
67− dotHideAnimTimer.stop()
68− notification.hideAnim.stop()
69−
70− if (d.useDotAnimation) {
71− dotShowAnimTimer.startFromBeginning()
72 }
69 }
73− notification.showAnim.start()
74 }
70 }
75 }
71 }
76
72
73+ function handleScreenOn(){
74+ var today = new Date().getDay()
75+ if(infographic.currentWeekDay !== today){
76+ infographic.currentWeekDay = today
77+ reloadUserData();
78+ }
79+ }
80+
81+ function reloadUserData(){
82+ d.useDotAnimation = false
83+ infographic.model.nextDataSource()
84+ }
85+
86+ function startShowAnimation() {
87+ dotHideAnimTimer.stop()
88+ notification.hideAnim.stop()
89+
90+ if (d.useDotAnimation) {
91+ dotShowAnimTimer.startFromBeginning()
92+ }
93+ notification.showAnim.start()
94+ }
95+
77 function startHideAnimation() {
96 function startHideAnimation() {
78 dotShowAnimTimer.stop()
97 dotShowAnimTimer.stop()
79 circleChangeAnimTimer.stop()
98 circleChangeAnimTimer.stop()
@@ -89,7 +108,10 @@ Item {
89
108
90 visible: model.username !== ""
109 visible: model.username !== ""
91
110
92− Component.onCompleted: startShowAnimation()
111+ Component.onCompleted: {
112+ currentWeekDay = new Date().getDay()
113+ startShowAnimation()
114+ }
93
115
94 Item {
116 Item {
95 id: dataCircle
117 id: dataCircle
@@ -413,8 +435,7 @@ Item {
413
435
414 onDoubleClicked: {
436 onDoubleClicked: {
415 if (!d.animating) {
437 if (!d.animating) {
416− d.useDotAnimation = false
438+ reloadUserData()
417− infographic.model.nextDataSource()
418 }
439 }
419 }
440 }
420 }
441 }
tests/mocks/libusermetrics/UserMetrics.cpp+5−3
@@ -136,7 +136,7 @@ private:
136}
136}
137
137
138UserMetricsDataPrivate::UserMetricsDataPrivate(UserMetricsData *parent) :
138UserMetricsDataPrivate::UserMetricsDataPrivate(UserMetricsData *parent) :
139− q_ptr(parent), m_firstColor(this), m_secondColor(this)
139+ q_ptr(parent), m_label(""), m_firstColor(this), m_secondColor(this)
140{
140{
141 m_length = calculateLength();
141 m_length = calculateLength();
142}
142}
@@ -225,7 +225,7 @@ int UserMetricsData::length() const
225}
225}
226
226
227UserMetricsPrivate::UserMetricsPrivate(UserMetrics *parent) :
227UserMetricsPrivate::UserMetricsPrivate(UserMetrics *parent) :
228− q_ptr(parent), m_firstColor(this), m_secondColor(this), m_currentDay(-1), m_currentDayChanged(false)
228+ q_ptr(parent), m_firstColor(this), m_secondColor(this), m_currentDay(0), m_currentDayChanged(false)
229{
229{
230 m_fakeData.insert("", UserMetricsDataPtr(new UserMetricsData(this)));
230 m_fakeData.insert("", UserMetricsDataPtr(new UserMetricsData(this)));
231}
231}
@@ -243,6 +243,8 @@ void UserMetricsPrivate::findAndSetUsername(const QString &username)
243 {
243 {
244 m_dataIndex = m_fakeData.constFind("");
244 m_dataIndex = m_fakeData.constFind("");
245 }
245 }
246+
247+ m_newData = *m_dataIndex;
246}
248}
247
249
248void UserMetricsPrivate::setUsername(const QString &username)
250void UserMetricsPrivate::setUsername(const QString &username)
@@ -341,7 +343,6 @@ void UserMetricsPrivate::generateFakeData()
341
343
342void UserMetricsPrivate::loadFakeData()
344void UserMetricsPrivate::loadFakeData()
343{
345{
344− m_newData = *m_dataIndex;
345
346
346 bool oldLabelEmpty = m_label.isEmpty();
347 bool oldLabelEmpty = m_label.isEmpty();
347 bool newLabelEmpty = m_newData->label().isEmpty();
348 bool newLabelEmpty = m_newData->label().isEmpty();
@@ -408,6 +409,7 @@ void UserMetricsPrivate::nextFakeData()
408 }
409 }
409 }
410 }
410
411
412+ m_newData = *m_dataIndex;
411 loadFakeData();
413 loadFakeData();
412}
414}
413
415
tests/qmltests/Greeter/tst_Infographics.qml+8−8
@@ -134,26 +134,26 @@ Item {
134 compare(infographic.visible, data.visible);
134 compare(infographic.visible, data.visible);
135 }
135 }
136
136
137− function test_set_current_day_data(data)
137+ function test_update_userdata_when_new_day_data()
138 {
138 {
139 return [
139 return [
140− { tag: "Same day", expectedDay: 0, label: "<b>19</b> minutes talk time" },
140+ { tag: "Same day", currentDayOffset: 0, label: "<b>19</b> minutes talk time" },
141− { tag: "Different day", expectedDay: 1, label: "<b>33</b> messages today" },
141+ { tag: "Different day", currentDayOffset: 1, label: "<b>33</b> messages today" },
142 ]
142 ]
143 }
143 }
144
144
145− function test_set_current_day(data)
145+ function test_update_userdata_when_new_day(data)
146 {
146 {
147 //Given
147 //Given
148+ var today = new Date().getDay()
148 infographicModel.username = "single"
149 infographicModel.username = "single"
149− infographic.currentDay = 0
150+ infographic.currentWeekDay = (today - data.currentDayOffset)
150
151
151 //When
152 //When
152− infographicModel.setDay(data.expectedDay)
153− infographic.startShowAnimation()
153+ infographic.handleScreenOn()
154
154
155 //Then
155 //Then
156− tryCompare(infographic, "currentDay", data.expectedDay)
156+ tryCompare(infographic, "currentWeekDay", today)
157 tryCompare(label, "text", data.label)
157 tryCompare(label, "text", data.label)
158 }
158 }
159 }
159 }