on xenial help sign in
Reload Infographics userdata when the screen turns on in case the day changed
commit3d51efb5bdda61069f5fd153b642b30b8e13e4f2 authorTomás Tormo <tomas.tormo@gmail.com> dateMon 17 Oct 2016, 15:06 (10 years ago) parentdb64e4f
3 files changed+49−26
qml/Greeter/Infographics.qml+36−15 tests/mocks/libusermetrics/UserMetrics.cpp+5−3 tests/qmltests/Greeter/tst_Infographics.qml+8−8
qml/Greeter/Infographics.qml+36−15
@@ -17,6 +17,7 @@
1717import "Gradient.js" as Gradient
1818import QtQuick 2.4
1919import Ubuntu.Components 1.3
20+import Powerd 0.1
2021
2122Item {
2223 id: infographic
@@ -25,7 +26,7 @@ Item {
2526
2627 property int animDuration: 10
2728
28− property int currentDay: -1 // Boot time value
29+ property int currentWeekDay
2930
3031 QtObject {
3132 id: d
@@ -58,22 +59,40 @@ Item {
5859 onDataDisappeared: startShowAnimation() // show "no data" label
5960 }
6061
62+ Connections {
63+ id: screenState
64+ target: Powerd
6165
62− function startShowAnimation() {
63− if(currentDay !== model.currentDay){
64− currentDay = model.currentDay
65− model.nextDataSource();
66− }else{
67− dotHideAnimTimer.stop()
68− notification.hideAnim.stop()
69−
70− if (d.useDotAnimation) {
71− dotShowAnimTimer.startFromBeginning()
66+ onStatusChanged: {
67+ if(Powerd.status === Powerd.On){
68+ handleScreenOn()
7269 }
73− notification.showAnim.start()
7470 }
7571 }
7672
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+
7796 function startHideAnimation() {
7897 dotShowAnimTimer.stop()
7998 circleChangeAnimTimer.stop()
@@ -89,7 +108,10 @@ Item {
89108
90109 visible: model.username !== ""
91110
92− Component.onCompleted: startShowAnimation()
111+ Component.onCompleted: {
112+ currentWeekDay = new Date().getDay()
113+ startShowAnimation()
114+ }
93115
94116 Item {
95117 id: dataCircle
@@ -413,8 +435,7 @@ Item {
413435
414436 onDoubleClicked: {
415437 if (!d.animating) {
416− d.useDotAnimation = false
417− infographic.model.nextDataSource()
438+ reloadUserData()
418439 }
419440 }
420441 }
tests/mocks/libusermetrics/UserMetrics.cpp+5−3
@@ -136,7 +136,7 @@ private:
136136}
137137
138138UserMetricsDataPrivate::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)
140140{
141141 m_length = calculateLength();
142142}
@@ -225,7 +225,7 @@ int UserMetricsData::length() const
225225}
226226
227227UserMetricsPrivate::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)
229229{
230230 m_fakeData.insert("", UserMetricsDataPtr(new UserMetricsData(this)));
231231}
@@ -243,6 +243,8 @@ void UserMetricsPrivate::findAndSetUsername(const QString &username)
243243 {
244244 m_dataIndex = m_fakeData.constFind("");
245245 }
246+
247+ m_newData = *m_dataIndex;
246248}
247249
248250void UserMetricsPrivate::setUsername(const QString &username)
@@ -341,7 +343,6 @@ void UserMetricsPrivate::generateFakeData()
341343
342344void UserMetricsPrivate::loadFakeData()
343345{
344− m_newData = *m_dataIndex;
345346
346347 bool oldLabelEmpty = m_label.isEmpty();
347348 bool newLabelEmpty = m_newData->label().isEmpty();
@@ -408,6 +409,7 @@ void UserMetricsPrivate::nextFakeData()
408409 }
409410 }
410411
412+ m_newData = *m_dataIndex;
411413 loadFakeData();
412414}
413415
tests/qmltests/Greeter/tst_Infographics.qml+8−8
@@ -134,26 +134,26 @@ Item {
134134 compare(infographic.visible, data.visible);
135135 }
136136
137− function test_set_current_day_data(data)
137+ function test_update_userdata_when_new_day_data()
138138 {
139139 return [
140− { tag: "Same day", expectedDay: 0, label: "<b>19</b> minutes talk time" },
141− { tag: "Different day", expectedDay: 1, label: "<b>33</b> messages today" },
140+ { tag: "Same day", currentDayOffset: 0, label: "<b>19</b> minutes talk time" },
141+ { tag: "Different day", currentDayOffset: 1, label: "<b>33</b> messages today" },
142142 ]
143143 }
144144
145− function test_set_current_day(data)
145+ function test_update_userdata_when_new_day(data)
146146 {
147147 //Given
148+ var today = new Date().getDay()
148149 infographicModel.username = "single"
149− infographic.currentDay = 0
150+ infographic.currentWeekDay = (today - data.currentDayOffset)
150151
151152 //When
152− infographicModel.setDay(data.expectedDay)
153− infographic.startShowAnimation()
153+ infographic.handleScreenOn()
154154
155155 //Then
156− tryCompare(infographic, "currentDay", data.expectedDay)
156+ tryCompare(infographic, "currentWeekDay", today)
157157 tryCompare(label, "text", data.label)
158158 }
159159 }