mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-03 22:35:45 +02:00
donation-ui: simplify settings property observation
Change-Id: I4f1442a9ee92f965a09eb6f5421b939e48b0fbf8
This commit is contained in:
parent
87aed4c039
commit
45271413b6
5 changed files with 46 additions and 21 deletions
|
@ -71,12 +71,26 @@ Item {
|
|||
return Math.min(Math.max(val, min), max);
|
||||
}
|
||||
|
||||
function isDonationBannerVisible() {
|
||||
property bool isDonationBannerVisible: getIsDonationBannerVisible()
|
||||
Connections {
|
||||
target: UtilsAdapter
|
||||
function onDonationCampaignSettingChanged() {
|
||||
// Changing any of the donation campaign settings will trigger a recompute of the banner visibility.
|
||||
updateIsDonationBannerVisible();
|
||||
}
|
||||
}
|
||||
|
||||
function updateIsDonationBannerVisible() {
|
||||
isDonationBannerVisible = getIsDonationBannerVisible();
|
||||
}
|
||||
|
||||
function getIsDonationBannerVisible() {
|
||||
// The banner is visible if the current date is after the date set in the settings and before the end date
|
||||
// And if the donation toggle is checked
|
||||
var isDonationVisible = UtilsAdapter.getAppValue(Settings.Key.IsDonationVisible);
|
||||
var endDonationDate = new Date(Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023EndDate)));
|
||||
var donationVisibleDate = new Date(Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023VisibleDate)));
|
||||
return new Date() < endDonationDate && new Date() > donationVisibleDate && isDonationVisible;
|
||||
const isVisible = UtilsAdapter.getAppValue(Settings.Key.IsDonationVisible);
|
||||
const endDate = Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023EndDate));
|
||||
const startDate = Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023VisibleDate));
|
||||
const now = new Date();
|
||||
return isVisible && now < endDate && now >= startDate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,7 @@ import "../../commoncomponents"
|
|||
import "../../settingsview/components"
|
||||
|
||||
Rectangle {
|
||||
id: donation
|
||||
|
||||
property bool donationVisible: JamiQmlUtils.isDonationBannerVisible()
|
||||
id: root
|
||||
|
||||
width: parent.width - 30
|
||||
height: donationTextRect.height + 45 > donationIcon.height + 20 ? donationTextRect.height + 45 : donationIcon.height + 20
|
||||
|
@ -35,6 +33,17 @@ Rectangle {
|
|||
|
||||
color: JamiTheme.donationBackgroundColor
|
||||
|
||||
function bumpDonationReminderVisibility() {
|
||||
// Calculate the time 7 days from now
|
||||
var futureDate = new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// Format the date to 'yyyy-MM-dd hh:mm' format
|
||||
var formattedDate = Qt.formatDateTime(futureDate, "yyyy-MM-dd hh:mm");
|
||||
|
||||
// Set the application value
|
||||
UtilsAdapter.setAppValue(Settings.Key.Donation2023VisibleDate, formattedDate);
|
||||
}
|
||||
|
||||
GridLayout {
|
||||
id: donationLayout
|
||||
|
||||
|
@ -102,16 +111,13 @@ Rectangle {
|
|||
|
||||
color: JamiTheme.transparentColor
|
||||
|
||||
// When the user clicks on "Not now", we set the donation date to 7 days from now
|
||||
Text {
|
||||
id: notNowText
|
||||
MouseArea {
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
// When the user clicks on "Not now", we set the donation date to 7 days from now (1 for the test)
|
||||
UtilsAdapter.setAppValue(Settings.Key.Donation2023VisibleDate, new Date(new Date().getTime() + 7 * 24 * 60 * 60 * 1000).toISOString().slice(0, 16).replace("T", " "));
|
||||
donation.donationVisible = Qt.binding(() => JamiQmlUtils.isDonationBannerVisible());
|
||||
}
|
||||
onClicked: bumpDonationReminderVisibility()
|
||||
}
|
||||
text: JamiStrings.notNow
|
||||
color: JamiTheme.donationButtonTextColor
|
||||
|
|
|
@ -185,9 +185,7 @@ SidePanelBase {
|
|||
Item {
|
||||
anchors.fill: parent
|
||||
|
||||
onVisibleChanged: {
|
||||
donation.donationVisible = Qt.binding(() => JamiQmlUtils.isDonationBannerVisible());
|
||||
}
|
||||
onVisibleChanged: JamiQmlUtils.updateIsDonationBannerVisible()
|
||||
|
||||
RowLayout {
|
||||
id: titleBar
|
||||
|
@ -331,21 +329,21 @@ SidePanelBase {
|
|||
}
|
||||
|
||||
DonationBanner {
|
||||
id: donation
|
||||
id: donationBanner
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.leftMargin: 15
|
||||
anchors.rightMargin: 15
|
||||
anchors.top: sidePanelTabBar.bottom
|
||||
anchors.topMargin: 10
|
||||
visible: donation.donationVisible
|
||||
visible: JamiQmlUtils.isDonationBannerVisible
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: smartListLayout
|
||||
|
||||
width: parent.width
|
||||
anchors.top: donation.visible ? donation.bottom : searchStatusRect.bottom
|
||||
anchors.topMargin: !donation.visible && (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
||||
anchors.top: donationBanner.visible ? donationBanner.bottom : searchStatusRect.bottom
|
||||
anchors.topMargin: !donationBanner.visible && (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
spacing: 4
|
||||
|
@ -398,7 +396,7 @@ SidePanelBase {
|
|||
visible: inNewSwarm
|
||||
|
||||
width: parent.width
|
||||
anchors.top: donation.donationVisible ? donation.bottom : sidePanelTabBar.bottom
|
||||
anchors.top: donationBanner.visible ? donationBanner.bottom : sidePanelTabBar.bottom
|
||||
anchors.topMargin: (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
||||
anchors.bottom: parent.bottom
|
||||
|
||||
|
|
|
@ -92,6 +92,11 @@ UtilsAdapter::setAppValue(const Settings::Key key, const QVariant& value)
|
|||
Q_EMIT chatviewPositionChanged();
|
||||
else if (key == Settings::Key::AppTheme)
|
||||
Q_EMIT appThemeChanged();
|
||||
// Any donation campaign-related keys can trigger a donation campaign check
|
||||
else if (key == Settings::Key::IsDonationVisible
|
||||
|| key == Settings::Key::Donation2023VisibleDate
|
||||
|| key == Settings::Key::Donation2023EndDate)
|
||||
Q_EMIT donationCampaignSettingChanged();
|
||||
}
|
||||
|
||||
QVariant
|
||||
|
|
|
@ -67,6 +67,7 @@ class UtilsAdapter final : public QmlAdapterBase
|
|||
Q_OBJECT
|
||||
QML_PROPERTY(QStringList, logList)
|
||||
QML_RO_PROPERTY(bool, isRTL)
|
||||
|
||||
public:
|
||||
explicit UtilsAdapter(AppSettingsManager* settingsManager,
|
||||
SystemTray* systemTray,
|
||||
|
@ -170,6 +171,7 @@ Q_SIGNALS:
|
|||
void appThemeChanged();
|
||||
void showExperimentalCallSwarm();
|
||||
void changeLanguage();
|
||||
void donationCampaignSettingChanged();
|
||||
|
||||
private:
|
||||
QClipboard* clipboard_;
|
||||
|
|
Loading…
Add table
Reference in a new issue