Files
pay/guis/mobile/BackgroundSyncConfig.qml
T
tomFlowee 81360632ba Make card behavior more smooth on device.
With some delays we allow the user interface to show up so the checkbox
actually is pained to be 'on' when the user gets a question from the OS
about allowing it.
2025-05-04 21:59:47 +02:00

161 lines
5.6 KiB
QML

/*
* This file is part of the Flowee project
* Copyright (C) 2025 Tom Zander <tom@flowee.org>
*
* 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
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import "../Flowee" as Flowee
Page {
headerText: qsTr("Background Synchronization")
id: root
property bool autoEnableAll: false
Column {
width: parent.width
spacing: 10
Flowee.Label {
width: parent.width
text: qsTr("Without background synchronization your wallets will not see new transactions until you open Flowee Pay")
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
}
Flowee.CheckBox {
id: checkbox
text: qsTr("Allow Background Synchronization")
checked: Pay.backgroundUpdates
onCheckedChanged: Pay.backgroundUpdates = checked
onToggled: {
if (checked && root.autoEnableAll)
Pay.externalNotifications = true;
}
// Make the user-enables-all action be nice and animated to make clear what is going on.
Timer {
running: root.autoEnableAll
interval: 400
repeat: false
onTriggered: if (!checkbox.checked) checkbox.toggle();
}
}
Item { width: 1; height: 10 } // spacer
QQC2.Slider {
id: slider
value: {
var ts = Pay.backgroundUpdateInterval
if (ts > 6) {
let s = 3;
while (ts > 6) {
s -= 1;
ts /= 2;
}
slider.value = s;
}
else {
slider.value = 6 - (ts - 3);
}
}
property int timeSpan: {
var i = slider.value;
if (i < 4) {
for (var h = 48; i > 0; --i) {
h = h / 2;
}
return h;
}
return 6 - (i - 3);
}
onTimeSpanChanged: Pay.backgroundUpdateInterval = timeSpan
opacity: checkbox.checked ? 1 : 0
width: parent.width
stepSize: 1
from: 0
to: 8
snapMode: QQC2.Slider.SnapAlways
background: Rectangle {
x: slider.leftPadding
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: 200
implicitHeight: 4
width: slider.availableWidth
height: implicitHeight
radius: 2
color: palette.button
Repeater {
id: repeater
model: slider.to - slider.from - 1
Rectangle {
width: 1.8
height: 10
color: palette.button
x: {
var offset = slider.handle.implicitWidth
var totalWidth = slider.width - slider.leftPadding - slider.rightPadding - offset;
var unit = totalWidth / (slider.to - slider.from);
return offset / 2 + unit + unit * modelData
}
y: 10
}
}
}
handle: Rectangle {
x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width)
y: slider.topPadding + slider.availableHeight / 2 - height / 2
implicitWidth: slider.font.pixelSize
implicitHeight: implicitWidth
radius: implicitWidth / 2
color: Pay.useDarkSkin ? slider.palette.windowText : slider.palette.highlight
}
Behavior on opacity { NumberAnimation { } }
}
Flowee.Label {
opacity: slider.opacity
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Every %1 hours").arg(slider.timeSpan)
}
PageTitledBox {
title: qsTr("Notifications")
width: parent.width
Flowee.CheckBox {
id: notificationsCheckbox
width: parent.width
text: qsTr("On Payments", "in relation to notifications")
checked: Pay.externalNotifications
onCheckedChanged: Pay.externalNotifications = checked
// Make the user-enables-all only trigger this if the user accepted background sync
Timer {
running: root.autoEnableAll && checkbox.checked
interval: 400
repeat: false
onTriggered: {
if (checkbox.checked && !notificationsCheckbox.checked)
notificationsCheckbox.toggle();
}
}
}
}
}
}