Properly add/remove sticker sets (almost ;))

This commit is contained in:
Sebastian Wolf 2021-02-13 00:34:01 +01:00
parent 94aee83936
commit ef9a999994
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
18 changed files with 317 additions and 121 deletions

View file

@ -25,22 +25,32 @@ Item {
id: stickerPickerOverlayItem id: stickerPickerOverlayItem
anchors.fill: parent anchors.fill: parent
property var recentStickers: stickerManager.getRecentStickers() property var recentStickers
property var installedStickerSets: stickerManager.getInstalledStickerSets() property var installedStickerSets
property bool pickerLoaded: false property int setInRemoval: -1
signal stickerPicked(var stickerId) Component.onCompleted: {
recentStickers = stickerManager.getRecentStickers();
installedStickerSets = stickerManager.getInstalledStickerSets();
}
Timer { Connections {
id: stickerPickerLoadedTimer target: tdLibWrapper
interval: 100 onOkReceived: {
running: true if (request === "removeStickerSet") {
repeat: false appNotification.show(qsTr("Sticker set successfully removed!"));
onTriggered: { tdLibWrapper.getInstalledStickerSets();
stickerPickerOverlayItem.pickerLoaded = true; console.log("Set in removal: " + setInRemoval);
if (setInRemoval > -1) {
installedStickerSets.splice(setInRemoval, 1);
setInRemoval = -1;
}
}
} }
} }
signal stickerPicked(var stickerId)
Rectangle { Rectangle {
id: stickerPickerOverlayBackground id: stickerPickerOverlayBackground
anchors.fill: parent anchors.fill: parent
@ -54,10 +64,6 @@ Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: Theme.paddingMedium anchors.margins: Theme.paddingMedium
opacity: stickerPickerOverlayItem.pickerLoaded ? 1 : 0
Behavior on opacity { NumberAnimation {} }
visible: stickerPickerOverlayItem.pickerLoaded
contentHeight: stickerPickerColumn.height contentHeight: stickerPickerColumn.height
clip: true clip: true
@ -66,7 +72,7 @@ Item {
spacing: Theme.paddingMedium spacing: Theme.paddingMedium
width: stickerPickerFlickable.width width: stickerPickerFlickable.width
Label { Label {
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeLarge
font.bold: true font.bold: true
width: parent.width width: parent.width
maximumLineCount: 1 maximumLineCount: 1
@ -90,15 +96,16 @@ Item {
width: recentStickersGridView.cellWidth width: recentStickersGridView.cellWidth
height: recentStickersGridView.cellHeight height: recentStickersGridView.cellHeight
Image { TDLibThumbnail {
source: modelData.thumbnail.file.local.path thumbnail: modelData.thumbnail
anchors.fill: parent anchors.fill: parent
asynchronous: true }
onStatusChanged: {
if (status === Image.Ready) { Label {
stickerPickerLoadedTimer.restart(); font.pixelSize: Theme.fontSizeSmall
} anchors.right: parent.right
} anchors.bottom: parent.bottom
text: Emoji.emojify(modelData.emoji, font.pixelSize)
} }
MouseArea { MouseArea {
@ -118,13 +125,32 @@ Item {
Column { Column {
spacing: Theme.paddingMedium spacing: Theme.paddingMedium
width: parent.width width: parent.width
Label { Row {
font.pixelSize: Theme.fontSizeMedium
font.bold: true
width: parent.width width: parent.width
maximumLineCount: 1 height: Math.max(removeSetButton.height, setTitleText.height) + ( 2 * Theme.paddingSmall )
truncationMode: TruncationMode.Fade Label {
text: modelData.title id: setTitleText
font.pixelSize: Theme.fontSizeLarge
font.bold: true
width: parent.width - removeSetButton.width
anchors.verticalCenter: parent.verticalCenter
maximumLineCount: 1
truncationMode: TruncationMode.Fade
text: modelData.title
}
IconButton {
id: removeSetButton
icon.source: "image://theme/icon-m-remove"
anchors.verticalCenter: parent.verticalCenter
onClicked: {
var stickerSetId = modelData.id;
setInRemoval = index;
Remorse.popupAction(chatPage, qsTr("Removing sticker set"), function() {
tdLibWrapper.changeStickerSet(stickerSetId, false);
});
}
}
} }
SilicaGridView { SilicaGridView {
@ -142,25 +168,16 @@ Item {
width: installedStickerSetGridView.cellWidth width: installedStickerSetGridView.cellWidth
height: installedStickerSetGridView.cellHeight height: installedStickerSetGridView.cellHeight
Image { TDLibThumbnail {
id: singleStickerImage thumbnail: modelData.thumbnail
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : ""
anchors.fill: parent anchors.fill: parent
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerPickerLoadedTimer.restart();
}
}
} }
Label { Label {
font.pixelSize: Theme.fontSizeHuge font.pixelSize: Theme.fontSizeSmall
anchors.fill: parent anchors.right: parent.right
maximumLineCount: 1 anchors.bottom: parent.bottom
truncationMode: TruncationMode.Fade
text: Emoji.emojify(modelData.emoji, font.pixelSize) text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.file.local.is_downloading_completed
} }
MouseArea { MouseArea {
@ -177,27 +194,5 @@ Item {
} }
} }
Column {
anchors.centerIn: parent
width: parent.width
spacing: Theme.paddingMedium
opacity: stickerPickerOverlayItem.pickerLoaded ? 0 : 1
Behavior on opacity { NumberAnimation {} }
visible: !stickerPickerOverlayItem.pickerLoaded
InfoLabel {
id: loadingLabel
text: qsTr("Loading stickers...")
}
BusyIndicator {
id: loadingBusyIndicator
anchors.horizontalCenter: parent.horizontalCenter
running: !stickerPickerOverlayItem.pickerLoaded
size: BusyIndicatorSize.Large
}
}
} }

View file

@ -32,7 +32,6 @@ Flickable {
property string stickerSetId; property string stickerSetId;
property var stickerSet; property var stickerSet;
property bool setLoaded: false;
signal requestClose; signal requestClose;
Component.onCompleted: { Component.onCompleted: {
@ -50,15 +49,17 @@ Flickable {
stickerSetOverlayFlickable.stickerSet = stickerSet; stickerSetOverlayFlickable.stickerSet = stickerSet;
} }
} }
} onOkReceived: {
if (request === "installStickerSet") {
Timer { appNotification.show(qsTr("Sticker set successfully installed!"));
id: stickerSetLoadedTimer installSetButton.visible = false;
interval: 100 tdLibWrapper.getInstalledStickerSets();
running: true }
repeat: false if (request === "removeStickerSet") {
onTriggered: { appNotification.show(qsTr("Sticker set successfully removed!"));
stickerSetOverlayFlickable.setLoaded = true; installSetButton.visible = true;
tdLibWrapper.getInstalledStickerSets();
}
} }
} }
@ -90,7 +91,7 @@ Flickable {
Label { Label {
id: overlayStickerTitleText id: overlayStickerTitleText
width: parent.width - ( installSetButton.visible ? installSetButton.width : 0 ) - closeSetButton.width width: parent.width - installSetButton.width - closeSetButton.width
text: stickerSet.title text: stickerSet.title
font.pixelSize: Theme.fontSizeExtraLarge font.pixelSize: Theme.fontSizeExtraLarge
font.weight: Font.ExtraBold font.weight: Font.ExtraBold
@ -104,12 +105,22 @@ Flickable {
id: installSetButton id: installSetButton
icon.source: "image://theme/icon-m-add" icon.source: "image://theme/icon-m-add"
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
visible: !stickerSet.is_installed visible: !stickerManager.isStickerSetInstalled(stickerSet.id)
onClicked: { onClicked: {
tdLibWrapper.changeStickerSet(stickerSet.id, true); tdLibWrapper.changeStickerSet(stickerSet.id, true);
} }
} }
IconButton {
id: removeSetButton
icon.source: "image://theme/icon-m-remove"
anchors.verticalCenter: parent.verticalCenter
visible: !installSetButton.visible
onClicked: {
tdLibWrapper.changeStickerSet(stickerSet.id, false);
}
}
IconButton { IconButton {
id: closeSetButton id: closeSetButton
icon.source: "image://theme/icon-m-clear" icon.source: "image://theme/icon-m-clear"
@ -139,25 +150,17 @@ Flickable {
width: stickerSetGridView.cellWidth - Theme.paddingSmall width: stickerSetGridView.cellWidth - Theme.paddingSmall
height: stickerSetGridView.cellHeight - Theme.paddingSmall height: stickerSetGridView.cellHeight - Theme.paddingSmall
Image { TDLibThumbnail {
id: singleStickerImage id: singleStickerThumbnail
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : "" thumbnail: modelData.thumbnail
anchors.fill: parent anchors.fill: parent
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerSetLoadedTimer.restart();
}
}
} }
Label { Label {
font.pixelSize: Theme.fontSizeHuge font.pixelSize: Theme.fontSizeSmall
anchors.fill: parent anchors.right: parent.right
maximumLineCount: 1 anchors.bottom: parent.bottom
truncationMode: TruncationMode.Fade
text: Emoji.emojify(modelData.emoji, font.pixelSize) text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.file.local.is_downloading_completed
} }
} }

View file

@ -699,7 +699,7 @@ Page {
contentWidth: width contentWidth: width
PullDownMenu { PullDownMenu {
visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active && !voiceNoteOverlayLoader.active && !messageOverlayLoader.active visible: chatInformation.id !== chatPage.myUserId && !stickerPickerLoader.active && !voiceNoteOverlayLoader.active && !messageOverlayLoader.active && !stickerSetOverlayLoader.active
MenuItem { MenuItem {
id: closeSecretChatMenuItem id: closeSecretChatMenuItem
visible: chatPage.isSecretChat && chatPage.secretChatDetails.state["@type"] !== "secretChatStateClosed" visible: chatPage.isSecretChat && chatPage.secretChatDetails.state["@type"] !== "secretChatStateClosed"
@ -958,7 +958,7 @@ Page {
id: chatView id: chatView
visible: !blurred visible: !blurred
property bool blurred: messageOverlayLoader.item || stickerPickerLoader.item || voiceNoteOverlayLoader.item || inlineQuery.hasOverlay property bool blurred: messageOverlayLoader.item || stickerPickerLoader.item || voiceNoteOverlayLoader.item || inlineQuery.hasOverlay || stickerSetOverlayLoader.item
anchors.fill: parent anchors.fill: parent
opacity: chatPage.loading ? 0 : 1 opacity: chatPage.loading ? 0 : 1
@ -1304,6 +1304,9 @@ Page {
} }
onActiveChanged: { onActiveChanged: {
if (active) {
attachmentOptionsFlickable.isNeeded = false;
}
} }
} }
@ -1773,7 +1776,7 @@ Page {
icon.source: "image://theme/icon-m-attach?" + (attachmentOptionsFlickable.isNeeded ? Theme.highlightColor : Theme.primaryColor) icon.source: "image://theme/icon-m-attach?" + (attachmentOptionsFlickable.isNeeded ? Theme.highlightColor : Theme.primaryColor)
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.paddingSmall anchors.bottomMargin: Theme.paddingSmall
enabled: !attachmentPreviewRow.visible enabled: !attachmentPreviewRow.visible && !stickerSetOverlayLoader.item
visible: !inlineQuery.userNameIsValid visible: !inlineQuery.userNameIsValid
onClicked: { onClicked: {
if (attachmentOptionsFlickable.isNeeded) { if (attachmentOptionsFlickable.isNeeded) {

View file

@ -60,6 +60,11 @@ bool StickerManager::hasStickerSet(const QString &stickerSetId)
return this->stickerSets.contains(stickerSetId); return this->stickerSets.contains(stickerSetId);
} }
bool StickerManager::isStickerSetInstalled(const QString &stickerSetId)
{
return this->installedStickerSetIds.contains(stickerSetId);
}
bool StickerManager::needsReload() bool StickerManager::needsReload()
{ {
return this->reloadNeeded; return this->reloadNeeded;
@ -105,7 +110,15 @@ void StickerManager::handleStickerSetsReceived(const QVariantList &stickerSets)
QListIterator<QVariant> stickerSetsIterator(stickerSets); QListIterator<QVariant> stickerSetsIterator(stickerSets);
while (stickerSetsIterator.hasNext()) { while (stickerSetsIterator.hasNext()) {
QVariantMap newStickerSet = stickerSetsIterator.next().toMap(); QVariantMap newStickerSet = stickerSetsIterator.next().toMap();
this->stickerSets.insert(newStickerSet.value("id").toString(), newStickerSet); QString newSetId = newStickerSet.value("id").toString();
bool isInstalled = newStickerSet.value("is_installed").toBool();
if (isInstalled && !this->installedStickerSetIds.contains(newSetId)) {
this->installedStickerSetIds.append(newSetId);
}
if (!isInstalled && this->installedStickerSetIds.contains(newSetId)) {
this->installedStickerSetIds.removeAll(newSetId);
}
this->stickerSets.insert(newSetId, newStickerSet);
} }
this->installedStickerSets.clear(); this->installedStickerSets.clear();

View file

@ -37,6 +37,7 @@ public:
Q_INVOKABLE QVariantList getInstalledStickerSets(); Q_INVOKABLE QVariantList getInstalledStickerSets();
Q_INVOKABLE QVariantMap getStickerSet(const QString &stickerSetId); Q_INVOKABLE QVariantMap getStickerSet(const QString &stickerSetId);
Q_INVOKABLE bool hasStickerSet(const QString &stickerSetId); Q_INVOKABLE bool hasStickerSet(const QString &stickerSetId);
Q_INVOKABLE bool isStickerSetInstalled(const QString &stickerSetId);
Q_INVOKABLE bool needsReload(); Q_INVOKABLE bool needsReload();
Q_INVOKABLE void setNeedsReload(const bool &reloadNeeded); Q_INVOKABLE void setNeedsReload(const bool &reloadNeeded);

View file

@ -1332,6 +1332,7 @@ void TDLibWrapper::changeStickerSet(const QString &stickerSetId, bool isInstalle
QVariantMap requestObject; QVariantMap requestObject;
requestObject.insert(_TYPE, "changeStickerSet"); requestObject.insert(_TYPE, "changeStickerSet");
requestObject.insert(_EXTRA, isInstalled ? "installStickerSet" : "removeStickerSet");
requestObject.insert("set_id", stickerSetId); requestObject.insert("set_id", stickerSetId);
requestObject.insert("is_installed", isInstalled); requestObject.insert("is_installed", isInstalled);

View file

@ -1666,8 +1666,23 @@
<translation>Kürzlich verwendet</translation> <translation>Kürzlich verwendet</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Lade Sticker...</translation> <translation>Entferne Sticker-Set</translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation>Sticker-Set erfolgreich entfernt!</translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation>Sticker-Set erfolgreich installiert!</translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation>Sticker-Set erfolgreich entfernt!</translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1668,8 +1668,23 @@ messages</numerusform>
<translation>Recently used</translation> <translation>Recently used</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Loading stickers...</translation> <translation>Removing sticker set</translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation>Sticker set successfully removed!</translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation>Sticker set successfully installed!</translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation>Sticker set successfully removed!</translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1666,8 +1666,23 @@
<translation>Usado recientemente</translation> <translation>Usado recientemente</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Cargando pegatinas...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1667,8 +1667,23 @@
<translation>Viimeksi käytetty</translation> <translation>Viimeksi käytetty</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Ladataan tarroja...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1639,7 +1639,22 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>

View file

@ -1666,8 +1666,23 @@
<translation>Usati di recente</translation> <translation>Usati di recente</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Carica sticker...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1693,8 +1693,23 @@
<translation>Ostatnio użyty</translation> <translation>Ostatnio użyty</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Ładowanie naklejek...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1696,8 +1696,23 @@
<translation>Недавно использованные</translation> <translation>Недавно использованные</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Загрузка стикеров...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1693,8 +1693,23 @@
<translation>Nedávno použité</translation> <translation>Nedávno použité</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Načítanie nálepiek...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1666,8 +1666,23 @@
<translation>Nyligen använt</translation> <translation>Nyligen använt</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Läser in dekaler...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1640,8 +1640,23 @@
<translation>使</translation> <translation>使</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation></translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>

View file

@ -1666,8 +1666,23 @@
<translation>Recently used</translation> <translation>Recently used</translation>
</message> </message>
<message> <message>
<source>Loading stickers...</source> <source>Removing sticker set</source>
<translation>Loading stickers...</translation> <translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>StickerSetOverlay</name>
<message>
<source>Sticker set successfully installed!</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sticker set successfully removed!</source>
<translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context> <context>