Use TDLibImage in location content

This commit is contained in:
John Gibbon 2021-01-19 22:41:06 +01:00
parent 710254dc0f
commit bba5bf94b8
2 changed files with 26 additions and 42 deletions

View file

@ -22,72 +22,50 @@ import Sailfish.Silica 1.0
import "../" import "../"
MessageContentBase { MessageContentBase {
id: contentItem
id: imagePreviewItem
property var locationData : ( rawMessage.content['@type'] === "messageLocation" ) ? rawMessage.content.location : ( ( rawMessage.content['@type'] === "messageVenue" ) ? rawMessage.content.venue.location : "" )
property string chatId: rawMessage.chat_id
property var pictureFileInformation;
height: width * 0.66666666; height: width * 0.66666666;
property string fileExtra
Component.onCompleted: { property var locationData : rawMessage.content.location
updatePicture(); property string fileExtra;
}
onClicked: { onClicked: {
if(!processLauncher.launchProgram('harbour-pure-maps', ["geo:"+locationData.latitude+","+locationData.longitude])) { if(!processLauncher.launchProgram('harbour-pure-maps', ["geo:"+locationData.latitude+","+locationData.longitude])) {
imageNotification.show(qsTr("Install Pure Maps to inspect this location.")); imageNotification.show(qsTr("Install Pure Maps to inspect this location."));
} }
} }
onLocationDataChanged: updatePicture()
onWidthChanged: updatePicture()
function updatePicture() { function updatePicture() {
imagePreviewItem.pictureFileInformation = null;
if (locationData) { if (locationData) {
fileExtra = "location:" + locationData.latitude + ":" + locationData.longitude + ":" + Math.round(imagePreviewItem.width) + ":" + Math.round(imagePreviewItem.height); fileExtra = "location:" + locationData.latitude + ":" + locationData.longitude + ":" + Math.round(contentItem.width) + ":" + Math.round(contentItem.height);
tdLibWrapper.getMapThumbnailFile(chatId, locationData.latitude, locationData.longitude, Math.round(imagePreviewItem.width), Math.round(imagePreviewItem.height), fileExtra); tdLibWrapper.getMapThumbnailFile(rawMessage.chat_id, locationData.latitude, locationData.longitude, Math.round(contentItem.width), Math.round(contentItem.height), fileExtra);
} }
} }
Connections { Connections {
target: tdLibWrapper target: tdLibWrapper
onFileUpdated: { onFileUpdated: {
if(fileInformation["@extra"] !== imagePreviewItem.fileExtra && (!imagePreviewItem.pictureFileInformation || imagePreviewItem.pictureFileInformation.id !== fileInformation.id)) { if(fileInformation["@extra"] === contentItem.fileExtra) {
return; if(fileInformation.id !== image.file.fileId) {
image.fileInformation = fileInformation
} }
if(fileInformation.local.is_downloading_completed) {
singleImage.source = fileInformation.local.path;
} else if(fileInformation.local.can_be_downloaded && !fileInformation.local.is_downloading_active) {
tdLibWrapper.downloadFile(fileInformation.id);
} }
imagePreviewItem.pictureFileInformation = fileInformation;
} }
} }
AppNotification { AppNotification {
id: imageNotification id: imageNotification
} }
TDLibImage {
Image { id: image
id: singleImage anchors.fill: parent
width: parent.width - Theme.paddingSmall cache: false
height: parent.height - Theme.paddingSmall
anchors.centerIn: parent
fillMode: Image.PreserveAspectCrop
autoTransform: true
asynchronous: true
visible: status === Image.Ready
opacity: status === Image.Ready ? 1 : 0
Behavior on opacity { NumberAnimation {} }
layer.enabled: imagePreviewItem.highlighted
layer.effect: PressEffect { source: singleImage }
Item { Item {
anchors.centerIn: parent anchors.centerIn: parent
width: markerImage.width width: markerImage.width
height: markerImage.height * 1.75 // 0.875 (vertical pin point) * 2 height: markerImage.height * 1.75 // 0.875 (vertical pin point) * 2
Image { Icon {
id: markerImage id: markerImage
source: 'image://theme/icon-m-location' source: 'image://theme/icon-m-location'
} }
@ -105,7 +83,10 @@ MessageContentBase {
} }
BackgroundImage { BackgroundImage {
visible: singleImage.status !== Image.Ready visible: image.status !== Image.Ready
} }
Component.onCompleted: {
updatePicture();
}
} }

View file

@ -16,6 +16,9 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>. along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/ */
import QtQuick 2.6 import QtQuick 2.6
MessageLocation {} MessageLocation {
locationData: rawMessage.content.venue.location
}