/
DetailedViewPage.qml
532 lines (478 loc) · 18.4 KB
/
DetailedViewPage.qml
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
/*
* Copyright (C) 2017 Jens Drescher, Germany
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import harbour.laufhelden 1.0
import QtPositioning 5.3
import "../tools/JSTools.js" as JSTools
import "../tools/SportsTracker.js" as ST
import "../tools/SharedResources.js" as SharedResources
import com.pipacs.o2 1.0
import "../components/"
Page
{
id: detailPage
allowedOrientations: Orientation.All
property string filename
property string name
property int index
property int stSharing: 0
property string stComment: ""
property var vTrackLinePoints
property int iCurrentWorkout: 0
property bool bHeartrateSupported: false
property bool bPaceRelevantForWorkoutType: true
property int iPausePositionsCount: 0
property TrackLoader trackLoader
onStatusChanged:
{
if (status === PageStatus.Active)
{
trackLoader.filename = filename;
}
}
function displayNotification(text, type, delay){
console.log(text);
load_text.text = text;
if (type === "info"){
ntimer.interval = delay;
load_text.color = Theme.primaryColor;
}
else if (type === "success"){
ntimer.interval = delay;
load_text.color = Theme.primaryColor;
}
else if (type === "error"){
if (ST.loginstate == 1 && ST.recycledlogin === true){
console.log("Sessionkey might be too old. Trying to login again");
settings.stSessionkey = "";
ST.SESSIONKEY = "";
recycledlogin = false;
ST.uploadToSportsTracker(stSharing, stComment, displayNotification);
}
else{
ntimer.interval = delay;
load_text.color = Theme.secondaryHighlightColor;
}
}
ntimer.restart();
ntimer.start();
}
Timer{
id:ntimer;
running: false;
interval: 2000;
repeat: false;
onTriggered: {
detail_busy.running = false;
detail_flick.visible = true;
detail_busy.visible = false;
load_text.visible = false;
ntimer.restart();
ntimer.start();
}
}
TrackLoader
{
id: trackLoader
onTrackChanged:
{
var trackLength = trackLoader.trackPointCount();
var pauseLength = trackLoader.pausePositionsCount();
var iLastProperHeartRate = 0;
JSTools.arrayDataPoints = [];
JSTools.trackPointsAt = [];
JSTools.trackPausePointsTemporary = [];
for(var i=0; i<trackLength; i++)
{
var iHeartrate = trackLoader.heartRateAt(i);
//Problem is there are often HR points with value 0. This will be solved.
if (iHeartrate > 0)
{
iLastProperHeartRate = iHeartrate;
}
else
{
iHeartrate = iLastProperHeartRate;
}
//heartrate,elevation,distance,time,unixtime,speed,pace,pacevalue,paceimp,duration
JSTools.fncAddDataPoint(iHeartrate, trackLoader.elevationAt(i), trackLoader.distanceAt(i), trackLoader.timeAt(i), trackLoader.unixTimeAt(i), trackLoader.speedAt(i), trackLoader.paceStrAt(i), trackLoader.paceAt(i), trackLoader.paceImperialStrAt(i), trackLoader.durationAt(i));
JSTools.trackPointsAt.push(trackLoader.trackPointAt(i));
}
//Go through array with pause data points
for (i=0; i<pauseLength; i++)
{
//add this track point to temporary array in JS.
JSTools.trackPausePointsTemporary.push(trackLoader.pausePositionAt(i));
}
//console.log("JSTools.arrayDataPoints.length: " + JSTools.arrayDataPoints.length.toString());
bHeartrateSupported = trackLoader.hasHeartRateData();
bPaceRelevantForWorkoutType = trackLoader.paceRelevantForWorkoutType();
iPausePositionsCount = trackLoader.pausePositionsCount();
pageStack.pushAttached(Qt.resolvedUrl("MapViewPage.qml"),
{
bHeartrateSupported: bHeartrateSupported,
bPaceRelevantForWorkoutType: bPaceRelevantForWorkoutType,
trackLoader: trackLoader
});
}
}
BusyIndicator
{
id: detail_busy
visible: false
anchors.centerIn: detailPage
running: true
size: BusyIndicatorSize.Large
}
Label {
id:load_text
width: parent.width
anchors.top: detail_busy.bottom
anchors.topMargin: 25;
horizontalAlignment: Label.AlignHCenter
visible: false
text: qsTr("loading...")
font.pixelSize: Theme.fontSizeMedium
}
BusyIndicator
{
visible: true
anchors.centerIn: detailPage
running: !trackLoader.loaded
size: BusyIndicatorSize.Large
}
Image
{
visible: trackLoader.loaded
id: id_IMG_WorkoutIcon
anchors.bottom: id_IMG_PageLocator.top
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: Theme.paddingLarge
width: parent.width / 4
height: parent.width / 4
z: 2
opacity: 0.2
source: SharedResources.arrayWorkoutTypes[SharedResources.arrayWorkoutTypes.map(function(e) { return e.name; }).indexOf(trackLoader.workout)].icon
}
Label
{
visible: trackLoader.loaded
anchors.horizontalCenter: id_IMG_WorkoutIcon.horizontalCenter
anchors.verticalCenter: id_IMG_WorkoutIcon.verticalCenter
horizontalAlignment: Label.AlignHCenter
color: Theme.primaryColor
font.pixelSize: Theme.fontSizeHuge
width: parent.width
z: 3
text: SharedResources.arrayWorkoutTypes[SharedResources.arrayWorkoutTypes.map(function(e) { return e.name; }).indexOf(trackLoader.workout)].labeltext
}
Image
{
id: id_IMG_PageLocator
visible: trackLoader.loaded
height: parent.width / 14
width: (parent.width / 14) * 3
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottomMargin: Theme.paddingSmall
z: 2
source:"../img/pagelocator_1_3.png"
}
SilicaFlickable
{
id:detail_flick
visible: trackLoader.loaded
anchors.fill: parent
clip: true
contentHeight: id_Column_Main.height
VerticalScrollDecorator {}
PullDownMenu
{
id: menu
MenuItem
{
text: qsTr("Diagrams")
onClicked: pageStack.push(Qt.resolvedUrl("DiagramViewPage.qml"))
visible: false
}
MenuItem
{
text: qsTr("Edit workout")
onClicked:
{
iCurrentWorkout = SharedResources.fncGetIndexByName(trackLoader.workout);
var dialog = pageStack.push(id_Dialog_EditWorkout);
dialog.sName = trackLoader.name;
dialog.sDesc = trackLoader.description;
dialog.iWorkout = SharedResources.fncGetIndexByName(trackLoader.workout);
dialog.accepted.connect(function()
{
//Edit and save GPX file
trackLoader.vReadFile(filename);
trackLoader.vSetNewProperties(name, trackLoader.description, trackLoader.workout, dialog.sName, dialog.sDesc, dialog.sWorkout)
trackLoader.vWriteFile(filename);
//Set edited values to dialog
header.title = dialog.sName;
descriptionData.text = dialog.sDesc;
id_HistoryModel.editTrack(index);
//Mainpage must reload all GPX files
bLoadHistoryData = true;
})
}
}
MenuItem
{
text: qsTr("Send to Sports-Tracker.com")
visible: settings.stUsername === "" ? false:true
onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("SportsTrackerUploadPage.qml"),{ stcomment: descriptionData.text});
dialog.accepted.connect(function() {
detail_busy.running = true;
detail_busy.visible = true;
load_text.visible = true;
detail_flick.visible = false;
ST.uploadToSportsTracker(dialog.sharing*1, dialog.stcomment, displayNotification);
});
dialog.rejected.connect(function() {
});
}
}
MenuItem
{
text: qsTr("Send to Strava")
visible: o2strava.linked
onClicked: {
var dialog = pageStack.push(Qt.resolvedUrl("StravaUploadPage.qml"));
dialog.activityID = filename;
var gpx = trackLoader.readGpx();
dialog.gpx = gpx;
dialog.activityName = name;
dialog.activityDescription = trackLoader.description;
dialog.activityType = trackLoader.workout
}
O2 {
id: o2strava
clientId: STRAVA_CLIENT_ID
clientSecret: STRAVA_CLIENT_SECRET
scope: "write"
requestUrl: "https://www.strava.com/oauth/authorize"
tokenUrl: "https://www.strava.com/oauth/token"
}
}
}
Column
{
id: id_Column_Main
anchors.top: parent.top
width: parent.width
spacing: Theme.paddingMedium
PageHeader
{
id: header
title: qsTr("Overview")
}
Label
{
color: Theme.primaryColor
font.pixelSize: Theme.fontSizeLarge
width: parent.width
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
anchors.horizontalCenter: parent.horizontalCenter
text: trackLoader.name
}
Item
{
width: parent.width
height: Theme.paddingLarge
}
Label
{
width: parent.width
horizontalAlignment: Text.AlignLeft
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
text: qsTr("Description:")
visible: trackLoader.description !== ""
}
Label
{
id: descriptionData
width: parent.width
text: trackLoader.description
color: Theme.primaryColor
wrapMode: Text.WordWrap
visible: trackLoader.description !== ""
}
InfoItem
{
label: qsTr("Starting time:")
value: trackLoader.timeStr
leftPadding: Theme.paddingMedium
}
InfoItem
{
label: qsTr("Duration:")
value: trackLoader.durationStr
leftPadding: Theme.paddingMedium
}
InfoItem
{
label: qsTr("Distance:")
value: (settings.measureSystem === 0) ? ((trackLoader.distance/1000).toFixed(2) + " km") : (JSTools.fncConvertDistanceToImperial(trackLoader.distance/1000).toFixed(2) + " mi")
leftPadding: Theme.paddingMedium
}
InfoItem
{
label: qsTr("Speed max/⌀:")
leftPadding: Theme.paddingMedium
value: (settings.measureSystem === 0)
? (trackLoader.maxGroundSpeed * 3.6).toFixed(1) + "/" + (trackLoader.speed*3.6).toFixed(1) + " km/h"
: (JSTools.fncConvertSpeedToImperial(trackLoader.maxGroundSpeed*3.6)).toFixed(1) + "/" + (JSTools.fncConvertSpeedToImperial(trackLoader.speed*3.6)).toFixed(1) + " mi/h"
}
InfoItem
{
label: qsTr("Elevation min/max:")
value: ((settings.measureSystem === 0) ? trackLoader.elevationMin.toFixed(1) : JSTools.fncConvertelevationToImperial(trackLoader.elevationMin).toFixed(1))
+ ((settings.measureSystem === 0) ? " m" : " feet")
+ "/"
+ ((settings.measureSystem === 0) ? trackLoader.elevationMax.toFixed(1) : JSTools.fncConvertelevationToImperial(trackLoader.elevationMax).toFixed(1))
+ ((settings.measureSystem === 0) ? " m" : " feet")
leftPadding: Theme.paddingMedium
}
InfoItem
{
visible: bPaceRelevantForWorkoutType
label: qsTr("Pace ⌀:")
value: (settings.measureSystem === 0) ? trackLoader.paceStr + " min/km" : trackLoader.paceImperialStr + " min/mi"
leftPadding: Theme.paddingMedium
}
InfoItem
{
visible: bHeartrateSupported
label: qsTr("Heart rate min/max/⌀:")
value: trackLoader.heartRateMin + "/" + trackLoader.heartRateMax + "/" + trackLoader.heartRate.toFixed(1) + " bpm"
leftPadding: Theme.paddingMedium
}
InfoItem
{
visible: (iPausePositionsCount > 0)
label: qsTr("Pause number/duration:")
value: trackLoader.pauseDurationStr
leftPadding: Theme.paddingMedium
}
}
}
Component
{
id: id_Dialog_EditWorkout
Dialog
{
property string sName
property string sDesc
property int iWorkout
property string sWorkout
canAccept: true
acceptDestination: detailPage
acceptDestinationAction:
{
sName = id_TXF_WorkoutName.text;
sDesc = id_TXF_WorkoutDesc.text;
iWorkout = cmbWorkout.currentIndex;
PageStackAction.Pop;
}
Flickable
{
width: parent.width
height: parent.height
interactive: false
Column
{
width: parent.width
DialogHeader { title: qsTr("Edit workout") }
TextField
{
id: id_TXF_WorkoutName
width: parent.width
label: qsTr("Workout name")
placeholderText: qsTr("Workout name")
text: sName
inputMethodHints: Qt.ImhNoPredictiveText
focus: true
horizontalAlignment: TextInput.AlignLeft
}
Item
{
width: parent.width
height: Theme.paddingLarge
}
TextField
{
id: id_TXF_WorkoutDesc
width: parent.width
label: qsTr("Workout description")
placeholderText: qsTr("Workout description")
text: sDesc
inputMethodHints: Qt.ImhNoPredictiveText
focus: true
horizontalAlignment: TextInput.AlignLeft
}
Item
{
width: parent.width
height: Theme.paddingLarge
}
Row
{
spacing: Theme.paddingSmall
width:parent.width;
Image
{
id: imgWorkoutImage
height: parent.width / 8
width: parent.width / 8
fillMode: Image.PreserveAspectFit
}
ComboBox
{
id: cmbWorkout
width: (parent.width / 8) * 7
label: qsTr("Workout:")
currentIndex: iCurrentWorkout
menu: ContextMenu
{
Repeater
{
model: SharedResources.arrayWorkoutTypes;
MenuItem { text: modelData.labeltext }
}
}
onCurrentItemChanged:
{
console.log("Workout changed!");
imgWorkoutImage.source = SharedResources.arrayWorkoutTypes[currentIndex].icon;
iWorkout = currentIndex;
sWorkout = SharedResources.arrayWorkoutTypes[currentIndex].name;
}
}
}
}
}
}
}
}