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
anchors.fill: parent
property var recentStickers: stickerManager.getRecentStickers()
property var installedStickerSets: stickerManager.getInstalledStickerSets()
property bool pickerLoaded: false
property var recentStickers
property var installedStickerSets
property int setInRemoval: -1
signal stickerPicked(var stickerId)
Component.onCompleted: {
recentStickers = stickerManager.getRecentStickers();
installedStickerSets = stickerManager.getInstalledStickerSets();
}
Timer {
id: stickerPickerLoadedTimer
interval: 100
running: true
repeat: false
onTriggered: {
stickerPickerOverlayItem.pickerLoaded = true;
Connections {
target: tdLibWrapper
onOkReceived: {
if (request === "removeStickerSet") {
appNotification.show(qsTr("Sticker set successfully removed!"));
tdLibWrapper.getInstalledStickerSets();
console.log("Set in removal: " + setInRemoval);
if (setInRemoval > -1) {
installedStickerSets.splice(setInRemoval, 1);
setInRemoval = -1;
}
}
}
}
signal stickerPicked(var stickerId)
Rectangle {
id: stickerPickerOverlayBackground
anchors.fill: parent
@ -54,10 +64,6 @@ Item {
anchors.fill: parent
anchors.margins: Theme.paddingMedium
opacity: stickerPickerOverlayItem.pickerLoaded ? 1 : 0
Behavior on opacity { NumberAnimation {} }
visible: stickerPickerOverlayItem.pickerLoaded
contentHeight: stickerPickerColumn.height
clip: true
@ -66,7 +72,7 @@ Item {
spacing: Theme.paddingMedium
width: stickerPickerFlickable.width
Label {
font.pixelSize: Theme.fontSizeMedium
font.pixelSize: Theme.fontSizeLarge
font.bold: true
width: parent.width
maximumLineCount: 1
@ -90,15 +96,16 @@ Item {
width: recentStickersGridView.cellWidth
height: recentStickersGridView.cellHeight
Image {
source: modelData.thumbnail.file.local.path
TDLibThumbnail {
thumbnail: modelData.thumbnail
anchors.fill: parent
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerPickerLoadedTimer.restart();
}
}
}
Label {
font.pixelSize: Theme.fontSizeSmall
anchors.right: parent.right
anchors.bottom: parent.bottom
text: Emoji.emojify(modelData.emoji, font.pixelSize)
}
MouseArea {
@ -118,13 +125,32 @@ Item {
Column {
spacing: Theme.paddingMedium
width: parent.width
Label {
font.pixelSize: Theme.fontSizeMedium
font.bold: true
Row {
width: parent.width
maximumLineCount: 1
truncationMode: TruncationMode.Fade
text: modelData.title
height: Math.max(removeSetButton.height, setTitleText.height) + ( 2 * Theme.paddingSmall )
Label {
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 {
@ -142,25 +168,16 @@ Item {
width: installedStickerSetGridView.cellWidth
height: installedStickerSetGridView.cellHeight
Image {
id: singleStickerImage
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : ""
TDLibThumbnail {
thumbnail: modelData.thumbnail
anchors.fill: parent
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerPickerLoadedTimer.restart();
}
}
}
Label {
font.pixelSize: Theme.fontSizeHuge
anchors.fill: parent
maximumLineCount: 1
truncationMode: TruncationMode.Fade
font.pixelSize: Theme.fontSizeSmall
anchors.right: parent.right
anchors.bottom: parent.bottom
text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.file.local.is_downloading_completed
}
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 var stickerSet;
property bool setLoaded: false;
signal requestClose;
Component.onCompleted: {
@ -50,15 +49,17 @@ Flickable {
stickerSetOverlayFlickable.stickerSet = stickerSet;
}
}
}
Timer {
id: stickerSetLoadedTimer
interval: 100
running: true
repeat: false
onTriggered: {
stickerSetOverlayFlickable.setLoaded = true;
onOkReceived: {
if (request === "installStickerSet") {
appNotification.show(qsTr("Sticker set successfully installed!"));
installSetButton.visible = false;
tdLibWrapper.getInstalledStickerSets();
}
if (request === "removeStickerSet") {
appNotification.show(qsTr("Sticker set successfully removed!"));
installSetButton.visible = true;
tdLibWrapper.getInstalledStickerSets();
}
}
}
@ -90,7 +91,7 @@ Flickable {
Label {
id: overlayStickerTitleText
width: parent.width - ( installSetButton.visible ? installSetButton.width : 0 ) - closeSetButton.width
width: parent.width - installSetButton.width - closeSetButton.width
text: stickerSet.title
font.pixelSize: Theme.fontSizeExtraLarge
font.weight: Font.ExtraBold
@ -104,12 +105,22 @@ Flickable {
id: installSetButton
icon.source: "image://theme/icon-m-add"
anchors.verticalCenter: parent.verticalCenter
visible: !stickerSet.is_installed
visible: !stickerManager.isStickerSetInstalled(stickerSet.id)
onClicked: {
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 {
id: closeSetButton
icon.source: "image://theme/icon-m-clear"
@ -139,25 +150,17 @@ Flickable {
width: stickerSetGridView.cellWidth - Theme.paddingSmall
height: stickerSetGridView.cellHeight - Theme.paddingSmall
Image {
id: singleStickerImage
source: modelData.thumbnail.file.local.is_downloading_completed ? modelData.thumbnail.file.local.path : ""
TDLibThumbnail {
id: singleStickerThumbnail
thumbnail: modelData.thumbnail
anchors.fill: parent
visible: modelData.thumbnail.file.local.is_downloading_completed
asynchronous: true
onStatusChanged: {
if (status === Image.Ready) {
stickerSetLoadedTimer.restart();
}
}
}
Label {
font.pixelSize: Theme.fontSizeHuge
anchors.fill: parent
maximumLineCount: 1
truncationMode: TruncationMode.Fade
font.pixelSize: Theme.fontSizeSmall
anchors.right: parent.right
anchors.bottom: parent.bottom
text: Emoji.emojify(modelData.emoji, font.pixelSize)
visible: !modelData.thumbnail.file.local.is_downloading_completed
}
}

View file

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

View file

@ -60,6 +60,11 @@ bool StickerManager::hasStickerSet(const QString &stickerSetId)
return this->stickerSets.contains(stickerSetId);
}
bool StickerManager::isStickerSetInstalled(const QString &stickerSetId)
{
return this->installedStickerSetIds.contains(stickerSetId);
}
bool StickerManager::needsReload()
{
return this->reloadNeeded;
@ -105,7 +110,15 @@ void StickerManager::handleStickerSetsReceived(const QVariantList &stickerSets)
QListIterator<QVariant> stickerSetsIterator(stickerSets);
while (stickerSetsIterator.hasNext()) {
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();

View file

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

View file

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

View file

@ -1666,8 +1666,23 @@
<translation>Kürzlich verwendet</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Lade Sticker...</translation>
<source>Removing sticker set</source>
<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>
</context>
<context>

View file

@ -1668,8 +1668,23 @@ messages</numerusform>
<translation>Recently used</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Loading stickers...</translation>
<source>Removing sticker set</source>
<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>
</context>
<context>

View file

@ -1666,8 +1666,23 @@
<translation>Usado recientemente</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Cargando pegatinas...</translation>
<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>
</message>
</context>
<context>

View file

@ -1667,8 +1667,23 @@
<translation>Viimeksi käytetty</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Ladataan tarroja...</translation>
<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>
</message>
</context>
<context>

View file

@ -1639,7 +1639,22 @@
<translation type="unfinished"></translation>
</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>
</message>
</context>

View file

@ -1666,8 +1666,23 @@
<translation>Usati di recente</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Carica sticker...</translation>
<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>
</message>
</context>
<context>

View file

@ -1693,8 +1693,23 @@
<translation>Ostatnio użyty</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Ładowanie naklejek...</translation>
<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>
</message>
</context>
<context>

View file

@ -1696,8 +1696,23 @@
<translation>Недавно использованные</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Загрузка стикеров...</translation>
<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>
</message>
</context>
<context>

View file

@ -1693,8 +1693,23 @@
<translation>Nedávno použité</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Načítanie nálepiek...</translation>
<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>
</message>
</context>
<context>

View file

@ -1666,8 +1666,23 @@
<translation>Nyligen använt</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Läser in dekaler...</translation>
<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>
</message>
</context>
<context>

View file

@ -1640,8 +1640,23 @@
<translation>使</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation></translation>
<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>
</message>
</context>
<context>

View file

@ -1666,8 +1666,23 @@
<translation>Recently used</translation>
</message>
<message>
<source>Loading stickers...</source>
<translation>Loading stickers...</translation>
<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>
</message>
</context>
<context>