forked from ernesst/ActivityTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.qml
More file actions
353 lines (326 loc) · 10.4 KB
/
Main.qml
File metadata and controls
353 lines (326 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
import QtQuick 2.4
import QtPositioning 5.3
import Ubuntu.Components 1.3
import QtQuick.Layouts 1.1
import io.thp.pyotherside 1.5
import QtSystemInfo 5.0
import QtLocation 5.3
//import Ubuntu.Components.ListItems 1.3 as ListItem
import Ubuntu.Components.Popups 1.3
import "./lib/polyline.js" as Pl
import UserMetrics 0.1
import Qt.labs.settings 1.0
MainView {
id: mainView
// objectName for functional testing purposes (autopilot-qt5)
objectName: "mainView"
// Note! applicationName needs to match the "name" field of the click manifest
applicationName: "activitytracker.actidev"
width: units.gu(100)
height: units.gu(75)
property int count;
property int counter;
property var gpxx;
property string day;
property bool am_running;
property string runits;
property string timestring : "00:00"
property string smashkey;
property string dist;
property string distmet: i18n.tr("%1 run today")
property string bikedistmet: i18n.tr("%1 biked today")
property string drivedistmet: i18n.tr("%1 drived today")
//keep screen on so we still get to read GPS
ScreenSaver {
id: screenSaver
screenSaverEnabled: !am_running
}
Settings {
id: persistentSettings
property int pointsInterval: 5000
// onPointsIntervalChanged: {/*console.log("pointsInterval has changed: "+pointsInterval);*/loggingpoints.interval = pointsInterval}
}
function stopwatch(seconds) {
var totalNumberOfSeconds = seconds;
var hours = parseInt( totalNumberOfSeconds / 3600 );
var minutes = parseInt( (totalNumberOfSeconds - (hours * 3600)) / 60 );
var seconds = Math.floor((totalNumberOfSeconds - ((hours * 3600) + (minutes * 60))));
var hours2 = (hours == 0 ? "" : (hours < 10 ? "0" + hours +":" : hours+":"))
var result = hours2 + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
return result
}
function formatDist(distance) {
if (runits == "miles"){
var mi
mi = distance * 0.62137 / 1000
distance = mi.toFixed(2) + "mi"
}
else if (runits == "kilometers"){
if (distance > 1000){
distance = distance / 1000
distance = distance.toFixed(2) + "km"
}
else
distance = distance.toFixed(2) + "m"
}
return distance
}
function formatSpeed(speed) {
if (runits == "miles"){
var mi
mi = speed * 0.62137 / 1000 * 3600
speed = mi.toFixed(1) + "mi/h"
}
else if (runits == "kilometers"){
speed = speed / 1000 * 3600
speed = speed.toFixed(1) + "km/h"
}
return speed
}
ListModel {
id: listModel
}
onRunitsChanged: {
listModel.clear()
pygpx.get_runs(listModel)
}
Python {
id: pygpx
Component.onCompleted: {
function loadit(result){
console.warn("STARTING GPX")
listModel.clear()
call('geepeeex.onetime_db_fix',[])
call('geepeeex.onetime_db_fix_again_cus_im_dumb',[])
get_units(result)
}
addImportPath(Qt.resolvedUrl('py/'))
importModule('geepeeex', loadit)
console.warn('imported gpxpy')
}//Component.onCompleted
function addpoint(gpx,lat,lng,alt,speed){
call('geepeeex.add_point', [gpxx,lat,lng,alt])
}//addpoint
function get_runs(model){
listModel.clear()
call('geepeeex.get_runs', [], function(result) {
// Load the received data into the list model
listModel.clear()
for (var i=0; i<result.length; i++) {
console.warn(runits);
if (runits == "miles"){
console.warn(result[i].distance)
//console.warn(result[i].speed)
var mi
mi = result[i].distance * 0.62137
result[i].distance = i18n.tr("Distance: ")+mi.toFixed(2) + "mi"
}
else if (runits == "kilometers"){
result[i].distance = i18n.tr("Distance: ")+result[i].distance + "km"
}
var seconds = parseFloat(result[i].speed) * 60
result[i].speed = i18n.tr("Time: ") + stopwatch(seconds)
listModel.append(result[i]);
}
});
}
function addrun(name){
console.warn("addiing run")
call('geepeeex.add_run', [gpxx, name], function(result){
console.warn("run added")
})
}//addrun
function writeit(gpx, name,act_type){
console.warn("Writing file")
var b = Pl.polyline;
//console.log("https://maps.googleapis.com/maps/api/staticmap?size=400x400&path=weight:3%7Ccolor:blue%7Cenc:"+b.encode(c,4))
call('geepeeex.write_gpx', [gpxx,name,act_type])
}//writeit
function logit(result) {
console.warn(result)
gpxx = result
}//logit
function create_gpx() {
call('geepeeex.create_gpx', [], logit);
}//create_gpx
function get_units(result) {
call('geepeeex.get_units', [], function(result){
console.warn("getting units")
console.warn(result[0])
runits = result[0]
return runits
}
)}
function set_units(units) {
call('geepeeex.set_units', [units]
)}
function rm_run(run) {
call('geepeeex.rm_run', [run])
}
function current_distance(gpx) {
call('geepeeex.current_distance', [gpxx], function(result) {
console.warn("DIST")
console.warn(result)
//distlabel.text=result
if (runits == "miles"){
var mi
mi = result * 0.62137
dist = mi.toFixed(2) + "mi"
}
else if (runits == "kilometers"){
dist = result + "km"
}
//dist=result
return dist
})
}
function format_timer(secs){
call('geepeeex.stopwatchery', [counter], function(result){
timestring=result
return result
})
}
}//Python
Page {
id: page1
visible: true
header: PageHeader {
title: i18n.tr("Recent Activities")
id: page1Header
trailingActionBar.actions: [
Action {
text: i18n.tr("Settings")
iconName: "settings"
onTriggered: stack.push(Qt.resolvedUrl("Settings.qml"))
},
Action {
text: i18n.tr("About")
iconName: "info"
onTriggered: stack.push(Qt.resolvedUrl("About.qml"))
}
]
}
Rectangle {
visible : !(thelist.model.count > 0)
id: rekt
anchors {
left: page1.left
right: page1.right
bottom: page1.bottom
top: page1Header.bottom
}
color: "transparent"
EmptyState {
title: i18n.tr("No saved activities")
iconSource: Qt.resolvedUrl("./images/runman.svg")
iconColor: UbuntuColors.jet
subTitle: i18n.tr("Swipe up to log a new activity")
anchors.centerIn: parent
}
}
Component.onCompleted: {
// listModel.clear()
// pygpx.get_runs(listModel)
}
ListView {
anchors {
left: page1.left
right: page1.right
bottom: page1.bottom
top: page1Header.bottom
}
width: parent.width
height: parent.height
clip:true
id:thelist
model: listModel
// let refresh control know when the refresh gets completed
// pullToRefresh {
// enabled: false
// onRefresh: pygpx.get_runs()
// }
delegate: ListItem {
id :del
onClicked: {
stack.push(Qt.resolvedUrl('QMLMap.qml'), {polyline: filename})
}
ListItemLayout {
ProportionalShape {
SlotsLayout.position: SlotsLayout.Leading
source: Image { source: "images/"+act_type+".png" }
height: del.height-units.gu(2)
anchors.topMargin: units.gu(1)
anchors.top: parent.top
aspect: UbuntuShape.DropShadow
}
title.text: name
subtitle.text: speed+" "+distance
}
leadingActions: ListItemActions {
actions: [
Action {
iconName: "delete"
onTriggered: {
pygpx.rm_run(id)
listModel.remove(index)
}
}
]
}
}
}
Metric {
id: runmetric
name: 'activitytracker-runs'
format: '%1 activities logged today'
emptyFormat: 'No activities today, go do something!'
domain: 'metrics-activitytracker'
}
Metric {
id: rundist
name: 'activitytracker-runsdist'
format: '%1 ' + distmet.arg(runits)
emptyFormat: '0 ' + distmet.arg(runits)
domain: 'metrics-activitytracker'
}
Metric {
id: bikedist
name: 'activitytracker-bikes'
format: '%1 ' + bikedistmet.arg(runits)
emptyFormat: '0 ' + bikedistmet.arg(runits)
domain: 'metrics-activitytracker'
}
Metric {
id: drivedist
name: 'activitytracker-drive'
format: '%1 ' + drivedistmet.arg(runits)
emptyFormat: '0 ' + drivedistmet.arg(runits)
domain: 'metrics-activitytracker'
}
BottomEdge {
id:newrunEdge
hint {
text: i18n.tr("Log new Activity")
iconSource: "images/runman.svg"
status: "Active"
flickable: thelist
// onStatusChanged: {
// switch (hint.status) {
// case 1: console.log("hint status: "+1); hint.status=2; break;
// case 0: console.log("hint status: "+0); break;
// case 2: console.log("hint status: "+2); break;
// }
}
onCollapseStarted: hint.status = "Active"
preloadContent: true
contentUrl: Qt.resolvedUrl("Tracker.qml")
}//Bottom edge
}//Page
PageStack {
id: stack
Component.onCompleted: {
am_running = false
stack.push(page1)
}
}
}