Skip to content

Commit

Permalink
Merge pull request #11 from miikasda/plot_data_changes
Browse files Browse the repository at this point in the history
Improve PlotDataPage
  • Loading branch information
miikasda authored Jul 23, 2024
2 parents b363133 + 6e38501 commit b3221af
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 32 deletions.
2 changes: 2 additions & 0 deletions qml/pages/GetDataPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ Page {
} else if (data[0] === "extra_data") {
// Update voltage and movement counter
db.setVoltage(selectedDevice.deviceAddress, data[1])
selectedDevice.deviceVoltage = data[1]
db.setMovement(selectedDevice.deviceAddress, data[2])
selectedDevice.deviceMovement = data[2]
} else if (data[0] === "failed") {
loadingScreen.running = false;
failureOverlay.visible = true;
Expand Down
106 changes: 75 additions & 31 deletions qml/pages/PlotDataPage.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Skruuvi - Reader for Ruuvi sensors
Copyright (C) 2023 Miika Malin
Copyright (C) 2023-2024 Miika Malin
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
Expand All @@ -22,6 +22,7 @@ import Sailfish.Share 1.0
import "../modules/GraphData"

Page {
id: plotDataPage

property var startTime: pageStack.pop().startTime
property var endTime: pageStack.pop().endTime
Expand All @@ -34,15 +35,9 @@ Page {
property var humidityData: []
property var pressureData: []

function calculateUnixTimestamp(day, month, year, start) {
function calculateUnixTimestamp(minute, hour, day, month, year) {
var date = new Date(year, month - 1, day);
if (start) {
// Set the time to the start of the day (00:00:00)
date.setHours(0, 0, 0, 0);
} else {
// Set the time to the end of the day (23:59:59)
date.setHours(23, 59, 59, 999);
}
date.setHours(hour, minute, 0, 0);
var unixTimestamp = Math.floor(date.getTime() / 1000);
return unixTimestamp;
}
Expand Down Expand Up @@ -123,6 +118,43 @@ Page {
text: selectedDevice.deviceName
}

Row {
spacing: Theme.paddingSmall
anchors.left: parent.left
anchors.leftMargin: leftMargin

Image {
id: batteryIcon
source: "image://theme/icon-m-battery"
width: Theme.iconSizeSmall
height: Theme.iconSizeSmall
anchors.verticalCenter: parent.verticalCenter
}

Label {
id: voltageLabel
text: selectedDevice.deviceVoltage + " V"
anchors.verticalCenter: parent.verticalCenter
color: Theme.highlightColor
}

Image {
id: movementIcon
source: "image://theme/icon-s-sync"
width: Theme.iconSizeSmall
height: Theme.iconSizeSmall
anchors.verticalCenter: parent.verticalCenter
}

Label {
id: movementLabel
text: selectedDevice.deviceMovement + " Moves"
font.pixelSize: Theme.fontSizeSmall
anchors.verticalCenter: parent.verticalCenter
color: Theme.highlightColor
}
}

Label {
id: deviceAddressLabel
leftPadding: leftMargin
Expand Down Expand Up @@ -213,22 +245,29 @@ Page {
anchors.top: parent.top
width: parent.width - leftMargin - rightMargin
anchors.horizontalCenter: parent.horizontalCenter
text: "Start date"
text: "Start time"
property bool clicked: false

onClicked: {
var dialog = pageStack.push(startPicker, {})
dialog.accepted.connect(function() {
startDateButton.text = "Start date: " + dialog.dateText
startTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, true)
startDateButton.clicked = true
var startDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {})
startDatePicker.accepted.connect(function() {
// Ask for time
var startTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hourMode: DateTime.TwentyFourHours,
hour: 0,
minute: 0
})
// Set plotDataPage as return destination on accept,
// otherwise we will return to datepicker
startTimePicker.acceptDestinationAction = PageStackAction.Pop
startTimePicker.acceptDestination = plotDataPage
startTimePicker.accepted.connect(function() {
startDateButton.text = "Start time: " + startDatePicker.dateText + " " + startTimePicker.timeText
startTime = calculateUnixTimestamp(startTimePicker.minute, startTimePicker.hour, startDatePicker.day, startDatePicker.month, startDatePicker.year)
startDateButton.clicked = true
})
})
}

Component {
id: startPicker
DatePickerDialog {}
}
}

// Whitespace inbetween buttons
Expand All @@ -244,22 +283,27 @@ Page {
anchors.top: whiteSpace.bottom
width: parent.width - leftMargin - rightMargin
anchors.horizontalCenter: parent.horizontalCenter
text: "End date"
text: "End time"
property bool clicked: false

onClicked: {
var dialog = pageStack.push(endPicker, {})
dialog.accepted.connect(function() {
endDateButton.text = "End date: " + dialog.dateText
endTime = calculateUnixTimestamp(dialog.day, dialog.month, dialog.year, false)
endDateButton.clicked = true
var endDatePicker = pageStack.push("Sailfish.Silica.DatePickerDialog", {})
endDatePicker.accepted.connect(function() {
// Ask for time
var endTimePicker = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hourMode: DateTime.TwentyFourHours,
hour: 23,
minute: 59
})
endTimePicker.acceptDestinationAction = PageStackAction.Pop
endTimePicker.acceptDestination = plotDataPage
endTimePicker.accepted.connect(function() {
endDateButton.text = "End time: " + endDatePicker.dateText + " " + endTimePicker.timeText
endTime = calculateUnixTimestamp(endTimePicker.minute, endTimePicker.hour, endDatePicker.day, endDatePicker.month, endDatePicker.year)
endDateButton.clicked = true
})
})
}

Component {
id: endPicker
DatePickerDialog {}
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion qml/pages/SelectDevicePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ Page {
onClicked: {
var selectedDevice = {
deviceName: model.deviceName,
deviceAddress: model.deviceAddress
deviceAddress: model.deviceAddress,
deviceVoltage: model.deviceVoltage,
deviceMovement: model.deviceMovement
}
// On default show last 24h data
var currentTime = Math.floor(Date.now() / 1000);
Expand Down

0 comments on commit b3221af

Please sign in to comment.