Introduce some lazy loading

This commit is contained in:
Sebastian J. Wolf 2020-09-21 22:10:03 +02:00
parent cfb93912ec
commit c5dade71b0
7 changed files with 157 additions and 70 deletions

View file

@ -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

View file

@ -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,17 +82,24 @@ 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;
}
}
}
}
Component {
id: profileImageComponent
Item {
width: parent.width
height: width
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
@ -119,12 +126,26 @@ Item {
opacity: singleImage.status === Image.Ready ? 1 : 0
Behavior on opacity { NumberAnimation {} }
}
}
}
Loader {
id: profileImageLoader
active: false
asynchronous: true
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

View file

@ -56,7 +56,7 @@ Page {
}
Label {
text: "Fernschreiber 0.1"
text: "Fernschreiber 0.2"
horizontalAlignment: Text.AlignHCenter
font.pixelSize: Theme.fontSizeExtraLarge
anchors {

View file

@ -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,13 +538,26 @@ Page {
visible: (text !== "")
}
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
sourceComponent: webPagePreviewComponent
}
Component {
id: imagePreviewComponent
ImagePreview {
id: messageImagePreview
photoData: ( display.content['@type'] === "messagePhoto" ) ? display.content.photo : ""
@ -554,14 +565,36 @@ Page {
height: parent.width * 2 / 3
visible: display.content['@type'] === "messagePhoto"
}
}
Loader {
id: imagePreviewLoader
active: ( display.content['@type'] === "messagePhoto" )
asynchronous: true
width: parent.width
sourceComponent: imagePreviewComponent
}
Component {
id: stickerPreviewComponent
StickerPreview {
id: messageStickerPreview
stickerData: ( display.content['@type'] === "messageSticker" ) ? display.content.sticker : ""
visible: display.content['@type'] === "messageSticker"
anchors.horizontalCenter: parent.horizontalCenter
}
}
Loader {
id: stickerPreviewLoader
active: ( display.content['@type'] === "messageSticker" )
asynchronous: true
width: parent.width
sourceComponent: stickerPreviewComponent
}
Component {
id: videoPreviewComponent
VideoPreview {
id: messageVideoPreview
videoData: ( display.content['@type'] === "messageVideo" ) ? display.content.video : ( ( display.content['@type'] === "messageAnimation" ) ? display.content.animation : "")
@ -570,7 +603,18 @@ Page {
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
sourceComponent: videoPreviewComponent
}
Component {
id: audioPreviewComponent
AudioPreview {
id: messageAudioPreview
audioData: ( display.content['@type'] === "messageVoiceNote" ) ? display.content.voice_note : ( ( display.content['@type'] === "messageAudio" ) ? display.content.audio : "")
@ -579,12 +623,32 @@ Page {
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 {
id: messageDateUpdater

View file

@ -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/

View file

@ -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

View file

@ -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);
}