From c5dade71b0c81e9b9d681ed2d2a5b110900c72f3 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Mon, 21 Sep 2020 22:10:03 +0200 Subject: [PATCH] Introduce some lazy loading --- harbour-fernschreiber.pro | 4 +- qml/components/ProfileThumbnail.qml | 83 +++++++++++------- qml/pages/AboutPage.qml | 2 +- qml/pages/ChatPage.qml | 128 +++++++++++++++++++++------- rpm/harbour-fernschreiber.spec | 4 +- rpm/harbour-fernschreiber.yaml | 4 +- src/tdlibwrapper.cpp | 2 +- 7 files changed, 157 insertions(+), 70 deletions(-) diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 13995ca..20901a0 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -50,7 +50,9 @@ DISTFILES += qml/harbour-fernschreiber.qml \ SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172 256x256 -TRANSLATIONS += translations/harbour-fernschreiber-de.ts +TRANSLATIONS += translations/harbour-fernschreiber-de.ts \ + translations/harbour-fernschreiber-es.ts \ + translations/harbour-fernschreiber-zh_CN.ts LIBS += -L$$PWD/tdlib/lib/ -ltdjson diff --git a/qml/components/ProfileThumbnail.qml b/qml/components/ProfileThumbnail.qml index ccce452..f28ae04 100644 --- a/qml/components/ProfileThumbnail.qml +++ b/qml/components/ProfileThumbnail.qml @@ -47,7 +47,7 @@ Item { function updatePicture() { if (typeof photoData === "object") { if (photoData.local.is_downloading_completed) { - singleImage.source = photoData.local.path; + profileImageLoader.active = true; } else { tdLibWrapper.downloadFile(photoData.id); } @@ -82,49 +82,70 @@ Item { console.log("File updated, completed? " + fileInformation.local.is_downloading_completed); if (fileInformation.local.is_downloading_completed) { photoData = fileInformation; - singleImage.source = photoData.local.path; + profileImageLoader.active = true; } } } } - Image { - id: singleImage - width: parent.width - Theme.paddingSmall - height: parent.height - Theme.paddingSmall - anchors.centerIn: parent + Component { + id: profileImageComponent + Item { + width: parent.width + height: width - fillMode: Image.PreserveAspectCrop - autoTransform: true + Image { + id: singleImage + width: parent.width - Theme.paddingSmall + height: parent.height - Theme.paddingSmall + anchors.centerIn: parent + source: profileThumbnail.photoData.local.path + + fillMode: Image.PreserveAspectCrop + autoTransform: true + asynchronous: true + visible: false + } + + Rectangle { + id: profileThumbnailMask + width: parent.width - Theme.paddingSmall + height: parent.height - Theme.paddingSmall + color: Theme.primaryColor + radius: parent.width / 2 + anchors.centerIn: singleImage + visible: false + } + + OpacityMask { + id: maskedThumbnail + source: singleImage + maskSource: profileThumbnailMask + anchors.fill: singleImage + visible: singleImage.status === Image.Ready ? true : false + opacity: singleImage.status === Image.Ready ? 1 : 0 + Behavior on opacity { NumberAnimation {} } + } + } + } + + Loader { + id: profileImageLoader + active: false asynchronous: true - visible: false - } - - Rectangle { - id: profileThumbnailMask - width: parent.width - Theme.paddingSmall - height: parent.height - Theme.paddingSmall - color: Theme.primaryColor - radius: parent.width / 2 - anchors.centerIn: singleImage - visible: false - } - - OpacityMask { - id: maskedThumbnail - source: singleImage - maskSource: profileThumbnailMask - anchors.fill: singleImage - visible: singleImage.status === Image.Ready ? true : false - opacity: singleImage.status === Image.Ready ? 1 : 0 - Behavior on opacity { NumberAnimation {} } + width: parent.width + sourceComponent: profileImageComponent + onLoaded: { + console.log(profileThumbnail.photoData.local.path); + } } Item { id: replacementThumbnailItem width: parent.width - Theme.paddingSmall height: parent.height - Theme.paddingSmall - visible: singleImage.status !== Image.Ready + //visible: singleImage.status !== Image.Ready + visible: !profileImageLoader.active Rectangle { id: replacementThumbnailBackground diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index ef4ae1c..e3d7be7 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -56,7 +56,7 @@ Page { } Label { - text: "Fernschreiber 0.1" + text: "Fernschreiber 0.2" horizontalAlignment: Text.AlignHCenter font.pixelSize: Theme.fontSizeExtraLarge anchors { diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index 57a6e42..6f74be1 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -354,10 +354,8 @@ Page { id: chatView anchors.fill: parent - opacity: chatPage.loading ? 0 : 1 Behavior on opacity { NumberAnimation {} } - clip: true property int lastReadSentIndex: 0 @@ -540,50 +538,116 @@ Page { visible: (text !== "") } - WebPagePreview { - id: webPagePreview - webPageData: ( typeof display.content.web_page !== "undefined" ) ? display.content.web_page : "" + Component { + id: webPagePreviewComponent + WebPagePreview { + id: webPagePreview + webPageData: ( typeof display.content.web_page !== "undefined" ) ? display.content.web_page : "" + width: parent.width + visible: typeof display.content.web_page !== "undefined" + } + } + + Loader { + id: webPagePreviewLoader + active: ( typeof display.content.web_page !== "undefined" ) + asynchronous: true width: parent.width - visible: typeof display.content.web_page !== "undefined" + sourceComponent: webPagePreviewComponent } - ImagePreview { - id: messageImagePreview - photoData: ( display.content['@type'] === "messagePhoto" ) ? display.content.photo : "" + Component { + id: imagePreviewComponent + ImagePreview { + id: messageImagePreview + photoData: ( display.content['@type'] === "messagePhoto" ) ? display.content.photo : "" + width: parent.width + height: parent.width * 2 / 3 + visible: display.content['@type'] === "messagePhoto" + } + } + + Loader { + id: imagePreviewLoader + active: ( display.content['@type'] === "messagePhoto" ) + asynchronous: true width: parent.width - height: parent.width * 2 / 3 - visible: display.content['@type'] === "messagePhoto" + sourceComponent: imagePreviewComponent } - StickerPreview { - id: messageStickerPreview - stickerData: ( display.content['@type'] === "messageSticker" ) ? display.content.sticker : "" - visible: display.content['@type'] === "messageSticker" - anchors.horizontalCenter: parent.horizontalCenter + Component { + id: stickerPreviewComponent + StickerPreview { + id: messageStickerPreview + stickerData: ( display.content['@type'] === "messageSticker" ) ? display.content.sticker : "" + visible: display.content['@type'] === "messageSticker" + anchors.horizontalCenter: parent.horizontalCenter + } } - VideoPreview { - id: messageVideoPreview - videoData: ( display.content['@type'] === "messageVideo" ) ? display.content.video : ( ( display.content['@type'] === "messageAnimation" ) ? display.content.animation : "") + Loader { + id: stickerPreviewLoader + active: ( display.content['@type'] === "messageSticker" ) + asynchronous: true width: parent.width - height: ( display.content['@type'] === "messageVideo" ) ? Functions.getVideoHeight(width, display.content.video) : Functions.getVideoHeight(width, display.content.animation) - visible: ( display.content['@type'] === "messageVideo" || display.content['@type'] === "messageAnimation" ) - onScreen: chatPage.status === PageStatus.Active + sourceComponent: stickerPreviewComponent } - AudioPreview { - id: messageAudioPreview - audioData: ( display.content['@type'] === "messageVoiceNote" ) ? display.content.voice_note : ( ( display.content['@type'] === "messageAudio" ) ? display.content.audio : "") + Component { + id: videoPreviewComponent + VideoPreview { + id: messageVideoPreview + videoData: ( display.content['@type'] === "messageVideo" ) ? display.content.video : ( ( display.content['@type'] === "messageAnimation" ) ? display.content.animation : "") + width: parent.width + height: ( display.content['@type'] === "messageVideo" ) ? Functions.getVideoHeight(width, display.content.video) : Functions.getVideoHeight(width, display.content.animation) + visible: ( display.content['@type'] === "messageVideo" || display.content['@type'] === "messageAnimation" ) + onScreen: chatPage.status === PageStatus.Active + } + } + + Loader { + id: videoPreviewLoader + active: (( display.content['@type'] === "messageVideo" ) || ( display.content['@type'] === "messageAnimation" )) + asynchronous: true width: parent.width - height: parent.width / 2 - visible: ( display.content['@type'] === "messageVoiceNote" || display.content['@type'] === "messageAudio" ) - onScreen: chatPage.status === PageStatus.Active + sourceComponent: videoPreviewComponent } - DocumentPreview { - id: messageDocumentPreview - documentData: ( display.content['@type'] === "messageDocument" ) ? display.content.document : "" - visible: display.content['@type'] === "messageDocument" + Component { + id: audioPreviewComponent + AudioPreview { + id: messageAudioPreview + audioData: ( display.content['@type'] === "messageVoiceNote" ) ? display.content.voice_note : ( ( display.content['@type'] === "messageAudio" ) ? display.content.audio : "") + width: parent.width + height: parent.width / 2 + visible: ( display.content['@type'] === "messageVoiceNote" || display.content['@type'] === "messageAudio" ) + onScreen: chatPage.status === PageStatus.Active + } + } + + Loader { + id: audioPreviewLoader + active: (( display.content['@type'] === "messageVoiceNote" ) || ( display.content['@type'] === "messageAudio" )) + asynchronous: true + width: parent.width + sourceComponent: audioPreviewComponent + } + + Component { + id: documentPreviewComponent + DocumentPreview { + id: messageDocumentPreview + documentData: ( display.content['@type'] === "messageDocument" ) ? display.content.document : "" + visible: display.content['@type'] === "messageDocument" + } + } + + Loader { + id: documentPreviewLoader + active: ( display.content['@type'] === "messageDocument" ) + asynchronous: true + width: parent.width + sourceComponent: documentPreviewComponent } Timer { diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index eed48bc..e868998 100644 --- a/rpm/harbour-fernschreiber.spec +++ b/rpm/harbour-fernschreiber.spec @@ -11,8 +11,8 @@ Name: harbour-fernschreiber # << macros Summary: Fernschreiber is a Telegram client for Sailfish OS -Version: 0.1 -Release: 6 +Version: 0.2 +Release: 1 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index f65cc4d..f5c0929 100644 --- a/rpm/harbour-fernschreiber.yaml +++ b/rpm/harbour-fernschreiber.yaml @@ -1,7 +1,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Sailfish OS -Version: 0.1 -Release: 6 +Version: 0.2 +Release: 1 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS Group: Qt/Qt diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 03e1ce4..1c22c3f 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -631,7 +631,7 @@ void TDLibWrapper::setInitialParameters() QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat); initialParameters.insert("device_model", hardwareSettings.value("NAME", "Unknown Mobile Device").toString()); initialParameters.insert("system_version", QSysInfo::prettyProductName()); - initialParameters.insert("application_version", "0.1"); + initialParameters.insert("application_version", "0.2"); requestObject.insert("parameters", initialParameters); this->sendRequest(requestObject); }