From 69ee975bf761578f59ba41b21575f7c0764b3681 Mon Sep 17 00:00:00 2001 From: dodoradio Date: Thu, 20 Jul 2023 23:48:37 +0100 Subject: Add steps detail page Currently this is a direct clone of the heartrate detail page, and isn't specialised for steps in any way --- src/graphs/StepsLineGraph.qml | 74 +++++++++++++++++++++++++++ src/resources.qrc | 2 + src/stepCounter/StepCounterPreview.qml | 92 ++++++++++++++++++--------------- src/stepCounter/StepsDetailPage.qml | 93 ++++++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 41 deletions(-) create mode 100644 src/graphs/StepsLineGraph.qml create mode 100644 src/stepCounter/StepsDetailPage.qml diff --git a/src/graphs/StepsLineGraph.qml b/src/graphs/StepsLineGraph.qml new file mode 100644 index 0000000..c654901 --- /dev/null +++ b/src/graphs/StepsLineGraph.qml @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2023 Arseniy Movshev + * 2019 Florent Revest + * + * 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 . + */ + +import QtQuick 2.15 +import org.asteroid.controls 1.0 + +import org.asteroid.health 1.0 +import org.asteroid.sensorlogd 1.0 + +Item { + id: graph + property date startTime: new Date() + property date endTime: new Date() + + onStartTimeChanged: stepsGraph.loadGraphData(stepsDataLoader.getDataFromTo(startTime,endTime)) + onEndTimeChanged: stepsGraph.loadGraphData(stepsDataLoader.getDataFromTo(startTime,endTime)) + + Component.onCompleted: { + stepsGraph.loadGraphData(stepsDataLoader.getDataFromTo(startTime,endTime)) + } + StepsDataLoader { id: stepsDataLoader } + VerticalLabels { // labels column + id: markerParent + width: parent.width/8 + startValue: 0 + endValue: stepsGraph.maxValue + anchors { + left: parent.left + top: stepsGraph.top + bottom: stepsGraph.bottom + topMargin: stepsGraph.lineWidth/2 + bottomMargin: anchors.topMargin + } + } + LineGraph { + id: stepsGraph + anchors { + left: markerParent.right + right: parent.right + top: parent.top + bottom: labelsRow.top + } + relativeMode: false + lineWidth: 4 + } + TimeLabels { + id: labelsRow + height: Dims.w(5) + startTime: stepsGraph.minTime / 1000 + endTime: stepsGraph.maxTime / 1000 + anchors { + bottom: parent.bottom + left: stepsGraph.left + right: stepsGraph.right + rightMargin: stepsGraph.lineWidth/2 + leftMargin: anchors.rightMargin + } + } +} diff --git a/src/resources.qrc b/src/resources.qrc index 04c32f9..fb35c71 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -2,6 +2,7 @@ main.qml stepCounter/StepCounterPreview.qml + stepCounter/StepsDetailPage.qml heartrate/HeartratePreview.qml heartrate/HeartrateDetailPage.qml settings/RootSettingsPage.qml @@ -9,6 +10,7 @@ settings/UiSettingsPage.qml graphs/BarGraph.qml graphs/HrGraph.qml + graphs/StepsLineGraph.qml graphs/TimeLabels.qml graphs/VerticalLabels.qml diff --git a/src/stepCounter/StepCounterPreview.qml b/src/stepCounter/StepCounterPreview.qml index f6a0228..3c2d3f0 100644 --- a/src/stepCounter/StepCounterPreview.qml +++ b/src/stepCounter/StepCounterPreview.qml @@ -23,57 +23,67 @@ import org.asteroid.sensorlogd 1.0 import "../graphs" -Column { +MouseArea { + implicitHeight: contentColumn.implicitHeight property var weekday: ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; + Column { + id: contentColumn + width: parent.width - Label { - width: parent.width*0.8 - anchors.horizontalCenter: parent.horizontalCenter - text: stepsDataLoader.getTodayTotal() ? "You've walked " + stepsDataLoader.todayTotal + " steps today, keep it up!" : "You haven't yet logged any steps today" - wrapMode: Text.WordWrap - horizontalAlignment: Text.AlignHCenter - } + Label { + width: parent.width*0.8 + anchors.horizontalCenter: parent.horizontalCenter + text: stepsDataLoader.getTodayTotal() ? "You've walked " + stepsDataLoader.todayTotal + " steps today, keep it up!" : "You haven't yet logged any steps today" + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + } - Item { width: parent.width; height: parent.width*0.1} - Label { - anchors { - left: parent.left - margins: app.width*0.1 + Item { width: parent.width; height: parent.width*0.1} + Label { + anchors { + left: parent.left + margins: app.width*0.1 + } + text: "Steps" } - text: "Steps" - } - Item { width: parent.width; height: parent.width*0.05} + Item { width: parent.width; height: parent.width*0.05} - BarGraph { - id: stepsGraph - anchors.horizontalCenter: parent.horizontalCenter - width: parent.width*0.85 - height: app.width*3/5 - StepsDataLoader { - id: stepsDataLoader - Component.onCompleted: { - triggerDaemonRecording() - stepsGraph.loadData() + BarGraph { + id: stepsGraph + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width*0.85 + height: app.width*3/5 + StepsDataLoader { + id: stepsDataLoader + Component.onCompleted: { + triggerDaemonRecording() + stepsGraph.loadData() + } } - } - function loadData() { - var currDate = new Date() - currDate.setDate(currDate.getDate() - 7) - for (var i = 0; i < 7; i++) { - currDate.setDate(currDate.getDate() + 1) - console.log(currDate) - var currvalue = stepsDataLoader.getTotalForDate(currDate) - if (currvalue > 0 || valuesArr.length > 0) { - if (currvalue > maxValue) { - maxValue = currvalue + function loadData() { + var currDate = new Date() + currDate.setDate(currDate.getDate() - 7) + for (var i = 0; i < 7; i++) { + currDate.setDate(currDate.getDate() + 1) + console.log(currDate) + var currvalue = stepsDataLoader.getTotalForDate(currDate) + if (currvalue > 0 || valuesArr.length > 0) { + if (currvalue > maxValue) { + maxValue = currvalue + } + valuesArr.push(currvalue) + labelsArr.push(weekday[currDate.getDay()]) } - valuesArr.push(currvalue) - labelsArr.push(weekday[currDate.getDay()]) } + dataLoadingDone() } - dataLoadingDone() + indicatorLineHeight: loggerSettings.stepGoalEnabled ? loggerSettings.stepGoalTarget : 0 } - indicatorLineHeight: loggerSettings.stepGoalEnabled ? loggerSettings.stepGoalTarget : 0 + } + onClicked: pageStack.push(detailPage) + Component { + id: detailPage + StepsDetailPage {} } } diff --git a/src/stepCounter/StepsDetailPage.qml b/src/stepCounter/StepsDetailPage.qml new file mode 100644 index 0000000..9d141dd --- /dev/null +++ b/src/stepCounter/StepsDetailPage.qml @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2023 Arseniy Movshev + * 2019 Florent Revest + * + * 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 . + */ + +import QtQuick 2.15 +import org.asteroid.controls 1.0 + +import org.asteroid.sensorlogd 1.0 + +import "../graphs" + +Item { + Flickable { + anchors.fill: parent + contentHeight: contentColumn.implicitHeight + Column { + id: contentColumn + width: parent.width + + Item { width: parent.width; height: parent.width*0.2} + + StepsLineGraph { + id: graph + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width*0.9 + height: app.height*2/3 + startTime: new Date() + endTime: new Date() + } + Row { + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width*0.9 + height: width/6 + MouseArea { + height: parent.height + width: parent.width/3 + Label { + anchors.centerIn: parent + text: "3 weeks" + } + onClicked: { + var d = graph.endTime + d.setDate(d.getDate() - 20) + graph.startTime = d + } + } + MouseArea { + height: parent.height + width: parent.width/3 + Label { + anchors.centerIn: parent + text: "week" + } + onClicked: { + var d = graph.endTime + d.setDate(d.getDate() - 6) + graph.startTime = d + } + } + MouseArea { + height: parent.height + width: parent.width/3 + Label { + anchors.centerIn: parent + text: "day" + } + onClicked: { + graph.startTime = graph.endTime + } + } + } + + Item { width: parent.width; height: parent.width*0.2} + } + } + PageHeader { + text: "Steps" + } +} -- cgit v1.2.3-54-g00ecf