mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-04 14:55:43 +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);
|
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
|
// 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
|
// And if the donation toggle is checked
|
||||||
var isDonationVisible = UtilsAdapter.getAppValue(Settings.Key.IsDonationVisible);
|
const isVisible = UtilsAdapter.getAppValue(Settings.Key.IsDonationVisible);
|
||||||
var endDonationDate = new Date(Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023EndDate)));
|
const endDate = Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023EndDate));
|
||||||
var donationVisibleDate = new Date(Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023VisibleDate)));
|
const startDate = Date.parse(UtilsAdapter.getAppValue(Settings.Key.Donation2023VisibleDate));
|
||||||
return new Date() < endDonationDate && new Date() > donationVisibleDate && isDonationVisible;
|
const now = new Date();
|
||||||
|
return isVisible && now < endDate && now >= startDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,7 @@ import "../../commoncomponents"
|
||||||
import "../../settingsview/components"
|
import "../../settingsview/components"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: donation
|
id: root
|
||||||
|
|
||||||
property bool donationVisible: JamiQmlUtils.isDonationBannerVisible()
|
|
||||||
|
|
||||||
width: parent.width - 30
|
width: parent.width - 30
|
||||||
height: donationTextRect.height + 45 > donationIcon.height + 20 ? donationTextRect.height + 45 : donationIcon.height + 20
|
height: donationTextRect.height + 45 > donationIcon.height + 20 ? donationTextRect.height + 45 : donationIcon.height + 20
|
||||||
|
@ -35,6 +33,17 @@ Rectangle {
|
||||||
|
|
||||||
color: JamiTheme.donationBackgroundColor
|
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 {
|
GridLayout {
|
||||||
id: donationLayout
|
id: donationLayout
|
||||||
|
|
||||||
|
@ -102,16 +111,13 @@ Rectangle {
|
||||||
|
|
||||||
color: JamiTheme.transparentColor
|
color: JamiTheme.transparentColor
|
||||||
|
|
||||||
|
// When the user clicks on "Not now", we set the donation date to 7 days from now
|
||||||
Text {
|
Text {
|
||||||
id: notNowText
|
id: notNowText
|
||||||
MouseArea {
|
MouseArea {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
onClicked: {
|
onClicked: bumpDonationReminderVisibility()
|
||||||
// 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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
text: JamiStrings.notNow
|
text: JamiStrings.notNow
|
||||||
color: JamiTheme.donationButtonTextColor
|
color: JamiTheme.donationButtonTextColor
|
||||||
|
|
|
@ -185,9 +185,7 @@ SidePanelBase {
|
||||||
Item {
|
Item {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: JamiQmlUtils.updateIsDonationBannerVisible()
|
||||||
donation.donationVisible = Qt.binding(() => JamiQmlUtils.isDonationBannerVisible());
|
|
||||||
}
|
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: titleBar
|
id: titleBar
|
||||||
|
@ -331,21 +329,21 @@ SidePanelBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
DonationBanner {
|
DonationBanner {
|
||||||
id: donation
|
id: donationBanner
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.leftMargin: 15
|
anchors.leftMargin: 15
|
||||||
anchors.rightMargin: 15
|
anchors.rightMargin: 15
|
||||||
anchors.top: sidePanelTabBar.bottom
|
anchors.top: sidePanelTabBar.bottom
|
||||||
anchors.topMargin: 10
|
anchors.topMargin: 10
|
||||||
visible: donation.donationVisible
|
visible: JamiQmlUtils.isDonationBannerVisible
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: smartListLayout
|
id: smartListLayout
|
||||||
|
|
||||||
width: parent.width
|
width: parent.width
|
||||||
anchors.top: donation.visible ? donation.bottom : searchStatusRect.bottom
|
anchors.top: donationBanner.visible ? donationBanner.bottom : searchStatusRect.bottom
|
||||||
anchors.topMargin: !donation.visible && (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
anchors.topMargin: !donationBanner.visible && (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
spacing: 4
|
spacing: 4
|
||||||
|
@ -398,7 +396,7 @@ SidePanelBase {
|
||||||
visible: inNewSwarm
|
visible: inNewSwarm
|
||||||
|
|
||||||
width: parent.width
|
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.topMargin: (sidePanelTabBar.visible || searchStatusRect.visible) ? 0 : 12
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,11 @@ UtilsAdapter::setAppValue(const Settings::Key key, const QVariant& value)
|
||||||
Q_EMIT chatviewPositionChanged();
|
Q_EMIT chatviewPositionChanged();
|
||||||
else if (key == Settings::Key::AppTheme)
|
else if (key == Settings::Key::AppTheme)
|
||||||
Q_EMIT appThemeChanged();
|
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
|
QVariant
|
||||||
|
|
|
@ -67,6 +67,7 @@ class UtilsAdapter final : public QmlAdapterBase
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_PROPERTY(QStringList, logList)
|
QML_PROPERTY(QStringList, logList)
|
||||||
QML_RO_PROPERTY(bool, isRTL)
|
QML_RO_PROPERTY(bool, isRTL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UtilsAdapter(AppSettingsManager* settingsManager,
|
explicit UtilsAdapter(AppSettingsManager* settingsManager,
|
||||||
SystemTray* systemTray,
|
SystemTray* systemTray,
|
||||||
|
@ -170,6 +171,7 @@ Q_SIGNALS:
|
||||||
void appThemeChanged();
|
void appThemeChanged();
|
||||||
void showExperimentalCallSwarm();
|
void showExperimentalCallSwarm();
|
||||||
void changeLanguage();
|
void changeLanguage();
|
||||||
|
void donationCampaignSettingChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QClipboard* clipboard_;
|
QClipboard* clipboard_;
|
||||||
|
|
Loading…
Add table
Reference in a new issue