From f241703784d59483a68e17ecdd4d6a1045060a7c Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 7 Dec 2023 02:40:59 +0200 Subject: [PATCH] Make the reaction button configurable --- harbour-fernschreiber.pro | 1 + qml/components/MessageListViewItem.qml | 48 ++++++++----------- qml/components/ReactionButton.qml | 19 ++++++++ .../settingsPage/SettingsBehavior.qml | 27 +++++++++++ src/appsettings.cpp | 15 ++++++ src/appsettings.h | 15 ++++-- 6 files changed, 92 insertions(+), 33 deletions(-) create mode 100644 qml/components/ReactionButton.qml diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 79af618..52e212c 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -64,6 +64,7 @@ DISTFILES += qml/harbour-fernschreiber.qml \ qml/components/PollPreview.qml \ qml/components/PressEffect.qml \ qml/components/ProfilePictureList.qml \ + qml/components/ReactionButton.qml \ qml/components/ReplyMarkupButtons.qml \ qml/components/StickerPicker.qml \ qml/components/PhotoTextsListItem.qml \ diff --git a/qml/components/MessageListViewItem.qml b/qml/components/MessageListViewItem.qml index a0cf5d8..d01e530 100644 --- a/qml/components/MessageListViewItem.qml +++ b/qml/components/MessageListViewItem.qml @@ -126,7 +126,7 @@ ListItem { Debug.log("Obtaining message reactions") tdLibWrapper.getMessageAvailableReactions(messageListItem.chatId, messageListItem.messageId); } - selectReactionBubble.visible = false; + selectReactionBubble.enabled = false; } function getContentWidthMultiplier() { @@ -150,9 +150,13 @@ ListItem { if (messageListItem.messageReactions) { messageListItem.messageReactions = null; - selectReactionBubble.visible = false; + selectReactionBubble.enabled = false; } else { - selectReactionBubble.visible = !selectReactionBubble.visible; + if (selectReactionBubble.enabled) { + selectReactionBubble.enabled = false + } else if (appSettings.showReactionButton) { + selectReactionBubble.enabled = true + } elementSelected(index); } } @@ -189,11 +193,11 @@ ListItem { target: chatPage onResetElements: { messageListItem.messageReactions = null; - selectReactionBubble.visible = false; + selectReactionBubble.enabled = false; } onElementSelected: { if (elementIndex !== index) { - selectReactionBubble.visible = false; + selectReactionBubble.enabled = false; } } onNavigatedTo: { @@ -716,7 +720,7 @@ ListItem { onClicked: { if (messageListItem.messageReactions) { messageListItem.messageReactions = null; - selectReactionBubble.visible = false; + selectReactionBubble.enabled = false; } else { openReactions(); } @@ -728,35 +732,23 @@ ListItem { } - Rectangle { + Loader { id: selectReactionBubble - visible: false - opacity: visible ? 0.5 : 0.0 - Behavior on opacity { NumberAnimation {} } anchors { horizontalCenter: messageListItem.isOwnMessage ? messageBackground.left : messageBackground.right verticalCenter: messageBackground.verticalCenter } - height: Theme.itemSizeExtraSmall - width: Theme.itemSizeExtraSmall - color: Theme.primaryColor - radius: parent.width / 2 - } - - IconButton { - id: selectReactionButton - visible: selectReactionBubble.visible - opacity: visible ? 1.0 : 0.0 - Behavior on opacity { NumberAnimation {} } - icon.source: "image://theme/icon-s-favorite" - anchors.centerIn: selectReactionBubble - onClicked: { - openReactions(); + enabled: false + opacity: enabled ? 1 : 0 + active: opacity > 0 + Behavior on opacity { FadeAnimation {} } + sourceComponent: Component { + ReactionButton { + onClicked: openReactions() + } } } - } - } Column { @@ -818,7 +810,7 @@ ListItem { // Reaction is not yet selected tdLibWrapper.addMessageReaction(chatId, messageId, modelData) messageReactions = null - selectReactionBubble.visible = false + selectReactionBubble.enabled = false } } } diff --git a/qml/components/ReactionButton.qml b/qml/components/ReactionButton.qml new file mode 100644 index 0000000..06bc908 --- /dev/null +++ b/qml/components/ReactionButton.qml @@ -0,0 +1,19 @@ +import QtQuick 2.0 +import Sailfish.Silica 1.0 + +Rectangle { + id: button + + height: Theme.itemSizeExtraSmall + width: Theme.itemSizeExtraSmall + color: Theme.rgba(Theme.primaryColor, 0.4) + radius: width / 2 + + signal clicked() + + IconButton { + icon.source: "image://theme/icon-s-favorite" + anchors.centerIn: parent + onClicked: button.clicked() + } +} diff --git a/qml/components/settingsPage/SettingsBehavior.qml b/qml/components/settingsPage/SettingsBehavior.qml index 2232791..b32a60c 100644 --- a/qml/components/settingsPage/SettingsBehavior.qml +++ b/qml/components/settingsPage/SettingsBehavior.qml @@ -21,6 +21,8 @@ import QtQuick 2.6 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 +import ".." + AccordionItem { text: qsTr("Behavior") Component { @@ -114,6 +116,31 @@ AccordionItem { } } + TextSwitch { + width: parent.columnWidth + checked: appSettings.showReactionButton + text: qsTr("Show reaction button on tap") + description: qsTr("The reaction button may appear when you tap the message bubble, to make access to the reactions even easier.") + automaticCheck: false + onClicked: { + appSettings.showReactionButton = !checked + } + + ReactionButton { + Behavior on opacity { FadeAnimation {} } + opacity: appSettings.showReactionButton ? 1 : 0 + visible: opacity > 0 + anchors { + right: parent.right + rightMargin: parent.rightMargin + verticalCenter: parent.verticalCenter + } + onClicked: { + appSettings.showReactionButton = !parent.checked + } + } + } + ComboBox { id: feedbackComboBox width: parent.columnWidth diff --git a/src/appsettings.cpp b/src/appsettings.cpp index 6df3f38..3e04134 100644 --- a/src/appsettings.cpp +++ b/src/appsettings.cpp @@ -42,6 +42,7 @@ namespace { const QString KEY_FOCUS_TEXTAREA_ON_CHAT_OPEN("focusTextAreaOnChatOpen"); const QString KEY_SPONSORED_MESS("sponsoredMess"); const QString KEY_HIGHLIGHT_UNREADCONVS("highlightUnreadConversations"); + const QString KEY_SHOW_REACTION_BUTTON("showReactionButton"); } AppSettings::AppSettings(QObject *parent) : QObject(parent), settings(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/de.ygriega/fernschreiber/settings.conf", QSettings::NativeFormat) @@ -329,6 +330,20 @@ void AppSettings::setFocusTextAreaOnChatOpen(bool focusTextAreaOnChatOpen) } } +bool AppSettings::showReactionButton() const +{ + return settings.value(KEY_SHOW_REACTION_BUTTON, true).toBool(); +} + +void AppSettings::setShowReactionButton(bool enable) +{ + if (showReactionButton() != enable) { + LOG(KEY_SHOW_REACTION_BUTTON << enable); + settings.setValue(KEY_SHOW_REACTION_BUTTON, enable); + emit showReactionButtonChanged(); + } +} + AppSettings::SponsoredMess AppSettings::getSponsoredMess() const { return (SponsoredMess) settings.value(KEY_SPONSORED_MESS, (int) diff --git a/src/appsettings.h b/src/appsettings.h index acc38b2..9382fee 100644 --- a/src/appsettings.h +++ b/src/appsettings.h @@ -43,8 +43,9 @@ class AppSettings : public QObject { Q_PROPERTY(bool onlineOnlyMode READ onlineOnlyMode WRITE setOnlineOnlyMode NOTIFY onlineOnlyModeChanged) Q_PROPERTY(bool delayMessageRead READ delayMessageRead WRITE setDelayMessageRead NOTIFY delayMessageReadChanged) Q_PROPERTY(bool focusTextAreaOnChatOpen READ getFocusTextAreaOnChatOpen WRITE setFocusTextAreaOnChatOpen NOTIFY focusTextAreaOnChatOpenChanged) - Q_PROPERTY(SponsoredMess sponsoredMess READ getSponsoredMess WRITE setSponsoredMess NOTIFY sponsoredMessChanged) Q_PROPERTY(bool highlightUnreadConversations READ highlightUnreadConversations WRITE setHighlightUnreadConversations NOTIFY highlightUnreadConversationsChanged) + Q_PROPERTY(bool showReactionButton READ showReactionButton WRITE setShowReactionButton NOTIFY showReactionButtonChanged) + Q_PROPERTY(SponsoredMess sponsoredMess READ getSponsoredMess WRITE setSponsoredMess NOTIFY sponsoredMessChanged) public: enum SponsoredMess { @@ -121,12 +122,15 @@ public: bool getFocusTextAreaOnChatOpen() const; void setFocusTextAreaOnChatOpen(bool focusTextAreaOnChatOpen); - SponsoredMess getSponsoredMess() const; - void setSponsoredMess(SponsoredMess sponsoredMess); - bool highlightUnreadConversations() const; void setHighlightUnreadConversations(bool enable); + bool showReactionButton() const; + void setShowReactionButton(bool enable); + + SponsoredMess getSponsoredMess() const; + void setSponsoredMess(SponsoredMess sponsoredMess); + signals: void sendByEnterChanged(); void focusTextAreaAfterSendChanged(); @@ -147,8 +151,9 @@ signals: void onlineOnlyModeChanged(); void delayMessageReadChanged(); void focusTextAreaOnChatOpenChanged(); - void sponsoredMessChanged(); void highlightUnreadConversationsChanged(); + void showReactionButtonChanged(); + void sponsoredMessChanged(); private: QSettings settings;