Merge lp:~nik90/ubuntu-clock-app/change-timer-logic into lp:ubuntu-clock-app/saucy

Proposed by Nekhelesh Ramananthan
Status: Merged
Approved by: Michael Hall
Approved revision: 97
Merged at revision: 95
Proposed branch: lp:~nik90/ubuntu-clock-app/change-timer-logic
Merge into: lp:ubuntu-clock-app/saucy
Diff against target: 172 lines (+37/-54)
3 files modified
timer/AnalogTimer.qml (+15/-14)
timer/TimerPage.qml (+22/-5)
timer/TimerScript.js (+0/-35)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/change-timer-logic
Reviewer Review Type Date Requested Status
Michael Hall Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Renato Araujo Oliveira Filho Pending
Review via email: mp+166982@code.launchpad.net

Commit message

Fixes potential timer lag by using code logic similar to stopwatch functionality by relying on time delta to keep track of timer.

Description of the change

Fixes potential timer lag by using code logic similar to stopwatch functionality. The time keeping is no longer done by the qml timer which has been found to not be reliable on different hardware.

To post a comment you must log in.
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Note: Approve only after testing on Nexus 7. The test should include suspended state (by switching to other app), running the timer for atleast 10 minutes to ensure it keeps track of timer accurately.

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
Renato Araujo Oliveira Filho (renatofilho) wrote :

please avoid to create extra ".js" files try to keep everything on QML if is not possible use the commom file, this way we can re-use the code for other pages.

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

> please avoid to create extra ".js" files try to keep everything on QML if is
> not possible use the commom file, this way we can re-use the code for other
> pages.

I didn't create a new .js file. In fact I made the function function getstringTimer() smaller by utilizing function ssToTime(). The function ssToTime() is required by both analogTimer.qml and TimerPage.qml hence its place in the .js file.

96. By Nekhelesh Ramananthan

Removed .js files and integrated it into qml files

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

Removed .js files by moving functions to the appropriate qml file.

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

Simplified code

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
Michael Hall (mhall119) wrote :

Tested on Nexus 7, works perfectly

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'timer/AnalogTimer.qml'
2--- timer/AnalogTimer.qml 2013-05-11 22:09:42 +0000
3+++ timer/AnalogTimer.qml 2013-06-03 21:41:26 +0000
4@@ -25,6 +25,9 @@
5 AnalogFaceBase {
6 id: clockOuterCircle
7
8+ property var startTime: 0;
9+ property var remTime: 0;
10+
11 // Properties to store/set the time variables
12 property int seconds: 0;
13 property int minutes: 0;
14@@ -45,26 +48,23 @@
15 property bool hoursFlag
16 property bool inProgressFlag
17
18- onTotalTimeChanged: {
19- if (totalTime < 0) {
20- timerOn = false;
21- }
22- else {
23- setTime(totalTime);
24- }
25- }
26-
27 // Timer function called by the main clock loop
28 function onTimerUpdate () {
29 if( timerOn ) {
30- totalTime--;
31- timerHand.rotationAngle = seconds * 6;
32+ remTime = totalTime - Math.floor((new Date() - startTime)/ 1000);
33+
34+ if (remTime < 0) {
35+ timerOn = false
36+ totalTime = -1;
37+ } else {
38+ ssToTime(remTime);
39+ timerHand.rotationAngle = seconds * 6;
40+ }
41 }
42 }
43
44- // Function to calculate the hours, minutes and seconds from the total time
45- function setTime ( sec ) {
46- var time = sec
47+ // Function to convert time (in seconds) to hh:mm:ss format
48+ function ssToTime(time) {
49 seconds = time % 60
50 time = Math.floor(time / 60)
51 minutes = time % 60
52@@ -74,6 +74,7 @@
53 // Function to disable timer and reset time
54 function reset() {
55 timerOn = false;
56+ startTime = remTime = 0;
57 hours = minutes = seconds = totalTime = timerValue = timerHand.rotationAngle = 0;
58 }
59
60
61=== modified file 'timer/TimerPage.qml'
62--- timer/TimerPage.qml 2013-05-25 16:33:33 +0000
63+++ timer/TimerPage.qml 2013-06-03 21:41:26 +0000
64@@ -23,7 +23,6 @@
65 import "../common"
66 import "../common/Constants.js" as Constants
67 import "../common/ClockUtils.js" as Utils
68-import "TimerScript.js" as TScript
69
70 Page {
71 id: timerPage
72@@ -44,6 +43,23 @@
73 namePreset.text = "";
74 }
75
76+ // Function to return total seconds.
77+ function totalSeconds(hou, min, sec) {
78+ return( (hou * 60 * 60) + (min * 60) + sec );
79+ }
80+
81+ // Function to calculate and print the hours, minutes and seconds from the total time as a string
82+ function getstringTimer(time) {
83+ var hours, minutes, seconds;
84+
85+ seconds = time % 60
86+ time = Math.floor(time / 60)
87+ minutes = time % 60
88+ hours = Math.floor(time / 60)
89+
90+ return Utils.hmsToString(hours, minutes, seconds);
91+ }
92+
93 Component.onCompleted: {
94 Utils.log("TimerPage loaded");
95 }
96@@ -178,7 +194,8 @@
97 break;
98
99 case "START":
100- totalTime = TScript.totalSeconds(hours, minutes, seconds);
101+ totalTime = totalSeconds(hours, minutes, seconds);
102+ analogTimer.startTime = new Date();
103 timerOn = true;
104 state = "STOP";
105
106@@ -224,7 +241,7 @@
107
108 Label {
109 fontSize: "medium"
110- text: TScript.getstringTimer(seconds)
111+ text: getstringTimer(seconds);
112 anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: units.gu(2) }
113 }
114
115@@ -244,7 +261,7 @@
116 onClicked: {
117 if (!timerOn) {
118 buttonTimer.state = "START";
119- analogTimer.setTime(seconds);
120+ analogTimer.ssToTime(seconds);
121 listTimerPreset.currentIndex = index
122 }
123 }
124@@ -278,7 +295,7 @@
125 anchors.fill: parent
126 onClicked: {
127 if (namePreset.text != "" && (hours > 0 || minutes > 0 || seconds > 0)) {
128- presetModel.appendPreset(namePreset.text, TScript.totalSeconds(hours, minutes, seconds));
129+ presetModel.appendPreset(namePreset.text, totalSeconds(hours, minutes, seconds));
130 reset();
131 timerPage.state = ""
132 }
133
134=== removed file 'timer/TimerScript.js'
135--- timer/TimerScript.js 2013-05-25 01:13:27 +0000
136+++ timer/TimerScript.js 1970-01-01 00:00:00 +0000
137@@ -1,35 +0,0 @@
138-/*
139- * Copyright (C) 2013 Canonical Ltd
140- *
141- * This program is free software: you can redistribute it and/or modify
142- * it under the terms of the GNU General Public License version 3 as
143- * published by the Free Software Foundation.
144- *
145- * This program is distributed in the hope that it will be useful,
146- * but WITHOUT ANY WARRANTY; without even the implied warranty of
147- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148- * GNU General Public License for more details.
149- *
150- * You should have received a copy of the GNU General Public License
151- * along with this program. If not, see <http://www.gnu.org/licenses/>.
152- *
153- * Authored by: Alessandro Pozzi <signor.hyde@gmail.com>
154- * Nekhelesh Ramananthan <krnekhelesh@gmail.com>
155- */
156-
157-Qt.include("../common/ClockUtils.js")
158-
159-// Function to return total seconds.
160-function totalSeconds ( hou, min, sec ) {
161- return( (hou * 60 * 60) + (min * 60) + sec );
162-}
163-
164-// Function to calculate the hours, minutes and seconds from the total time
165-function getstringTimer ( seconds ) {
166- var time = seconds
167- var sec = time % 60
168- time = Math.floor(time / 60)
169- var min = time % 60
170- var hor = Math.floor(time / 60)
171- return Utils.hmsToString(hor, min, sec);
172-}

Subscribers

People subscribed via source and target branches