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 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 LIBS += -L$$PWD/tdlib/lib/ -ltdjson

View file

@ -47,7 +47,7 @@ Item {
function updatePicture() { function updatePicture() {
if (typeof photoData === "object") { if (typeof photoData === "object") {
if (photoData.local.is_downloading_completed) { if (photoData.local.is_downloading_completed) {
singleImage.source = photoData.local.path; profileImageLoader.active = true;
} else { } else {
tdLibWrapper.downloadFile(photoData.id); tdLibWrapper.downloadFile(photoData.id);
} }
@ -82,17 +82,24 @@ Item {
console.log("File updated, completed? " + fileInformation.local.is_downloading_completed); console.log("File updated, completed? " + fileInformation.local.is_downloading_completed);
if (fileInformation.local.is_downloading_completed) { if (fileInformation.local.is_downloading_completed) {
photoData = fileInformation; photoData = fileInformation;
singleImage.source = photoData.local.path; profileImageLoader.active = true;
} }
} }
} }
} }
Component {
id: profileImageComponent
Item {
width: parent.width
height: width
Image { Image {
id: singleImage id: singleImage
width: parent.width - Theme.paddingSmall width: parent.width - Theme.paddingSmall
height: parent.height - Theme.paddingSmall height: parent.height - Theme.paddingSmall
anchors.centerIn: parent anchors.centerIn: parent
source: profileThumbnail.photoData.local.path
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
autoTransform: true autoTransform: true
@ -119,12 +126,26 @@ Item {
opacity: singleImage.status === Image.Ready ? 1 : 0 opacity: singleImage.status === Image.Ready ? 1 : 0
Behavior on opacity { NumberAnimation {} } Behavior on opacity { NumberAnimation {} }
} }
}
}
Loader {
id: profileImageLoader
active: false
asynchronous: true
width: parent.width
sourceComponent: profileImageComponent
onLoaded: {
console.log(profileThumbnail.photoData.local.path);
}
}
Item { Item {
id: replacementThumbnailItem id: replacementThumbnailItem
width: parent.width - Theme.paddingSmall width: parent.width - Theme.paddingSmall
height: parent.height - Theme.paddingSmall height: parent.height - Theme.paddingSmall
visible: singleImage.status !== Image.Ready //visible: singleImage.status !== Image.Ready
visible: !profileImageLoader.active
Rectangle { Rectangle {
id: replacementThumbnailBackground id: replacementThumbnailBackground

View file

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

View file

@ -354,10 +354,8 @@ Page {
id: chatView id: chatView
anchors.fill: parent anchors.fill: parent
opacity: chatPage.loading ? 0 : 1 opacity: chatPage.loading ? 0 : 1
Behavior on opacity { NumberAnimation {} } Behavior on opacity { NumberAnimation {} }
clip: true clip: true
property int lastReadSentIndex: 0 property int lastReadSentIndex: 0
@ -540,13 +538,26 @@ Page {
visible: (text !== "") visible: (text !== "")
} }
Component {
id: webPagePreviewComponent
WebPagePreview { WebPagePreview {
id: webPagePreview id: webPagePreview
webPageData: ( typeof display.content.web_page !== "undefined" ) ? display.content.web_page : "" webPageData: ( typeof display.content.web_page !== "undefined" ) ? display.content.web_page : ""
width: parent.width width: parent.width
visible: typeof display.content.web_page !== "undefined" 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 { ImagePreview {
id: messageImagePreview id: messageImagePreview
photoData: ( display.content['@type'] === "messagePhoto" ) ? display.content.photo : "" photoData: ( display.content['@type'] === "messagePhoto" ) ? display.content.photo : ""
@ -554,14 +565,36 @@ Page {
height: parent.width * 2 / 3 height: parent.width * 2 / 3
visible: display.content['@type'] === "messagePhoto" visible: display.content['@type'] === "messagePhoto"
} }
}
Loader {
id: imagePreviewLoader
active: ( display.content['@type'] === "messagePhoto" )
asynchronous: true
width: parent.width
sourceComponent: imagePreviewComponent
}
Component {
id: stickerPreviewComponent
StickerPreview { StickerPreview {
id: messageStickerPreview id: messageStickerPreview
stickerData: ( display.content['@type'] === "messageSticker" ) ? display.content.sticker : "" stickerData: ( display.content['@type'] === "messageSticker" ) ? display.content.sticker : ""
visible: display.content['@type'] === "messageSticker" visible: display.content['@type'] === "messageSticker"
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
} }
}
Loader {
id: stickerPreviewLoader
active: ( display.content['@type'] === "messageSticker" )
asynchronous: true
width: parent.width
sourceComponent: stickerPreviewComponent
}
Component {
id: videoPreviewComponent
VideoPreview { VideoPreview {
id: messageVideoPreview id: messageVideoPreview
videoData: ( display.content['@type'] === "messageVideo" ) ? display.content.video : ( ( display.content['@type'] === "messageAnimation" ) ? display.content.animation : "") 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" ) visible: ( display.content['@type'] === "messageVideo" || display.content['@type'] === "messageAnimation" )
onScreen: chatPage.status === PageStatus.Active 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 { AudioPreview {
id: messageAudioPreview id: messageAudioPreview
audioData: ( display.content['@type'] === "messageVoiceNote" ) ? display.content.voice_note : ( ( display.content['@type'] === "messageAudio" ) ? display.content.audio : "") 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" ) visible: ( display.content['@type'] === "messageVoiceNote" || display.content['@type'] === "messageAudio" )
onScreen: chatPage.status === PageStatus.Active 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 { DocumentPreview {
id: messageDocumentPreview id: messageDocumentPreview
documentData: ( display.content['@type'] === "messageDocument" ) ? display.content.document : "" documentData: ( display.content['@type'] === "messageDocument" ) ? display.content.document : ""
visible: display.content['@type'] === "messageDocument" visible: display.content['@type'] === "messageDocument"
} }
}
Loader {
id: documentPreviewLoader
active: ( display.content['@type'] === "messageDocument" )
asynchronous: true
width: parent.width
sourceComponent: documentPreviewComponent
}
Timer { Timer {
id: messageDateUpdater id: messageDateUpdater

View file

@ -11,8 +11,8 @@ Name: harbour-fernschreiber
# << macros # << macros
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.2
Release: 6 Release: 1
Group: Qt/Qt Group: Qt/Qt
License: LICENSE License: LICENSE
URL: http://werkwolf.eu/ URL: http://werkwolf.eu/

View file

@ -1,7 +1,7 @@
Name: harbour-fernschreiber Name: harbour-fernschreiber
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.2
Release: 6 Release: 1
# The contents of the Group field should be one of the groups listed here: # The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Qt/Qt Group: Qt/Qt

View file

@ -631,7 +631,7 @@ void TDLibWrapper::setInitialParameters()
QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat); QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat);
initialParameters.insert("device_model", hardwareSettings.value("NAME", "Unknown Mobile Device").toString()); initialParameters.insert("device_model", hardwareSettings.value("NAME", "Unknown Mobile Device").toString());
initialParameters.insert("system_version", QSysInfo::prettyProductName()); initialParameters.insert("system_version", QSysInfo::prettyProductName());
initialParameters.insert("application_version", "0.1"); initialParameters.insert("application_version", "0.2");
requestObject.insert("parameters", initialParameters); requestObject.insert("parameters", initialParameters);
this->sendRequest(requestObject); this->sendRequest(requestObject);
} }