Add download option to audio preview

This commit is contained in:
Sebastian Wolf 2020-12-28 21:20:10 +01:00
parent f7c6f8a399
commit ef1f824cd8
No known key found for this signature in database
GPG key ID: CEA9522B5F38A90A
14 changed files with 158 additions and 17 deletions

View file

@ -163,7 +163,7 @@ Item {
height: Theme.iconSizeLarge height: Theme.iconSizeLarge
Item { Item {
height: Theme.iconSizeLarge height: Theme.iconSizeLarge
width: parent.width width: downloadItem.visible ? parent.width / 2 : parent.width
IconButton { IconButton {
id: playButton id: playButton
anchors.centerIn: parent anchors.centerIn: parent
@ -187,6 +187,35 @@ Item {
size: BusyIndicatorSize.Large size: BusyIndicatorSize.Large
} }
} }
Item {
id: downloadItem
width: parent.width / 2
height: Theme.iconSizeLarge
visible: audioData[audioType].local.is_downloading_completed
Rectangle {
color: Theme.primaryColor
opacity: Theme.opacityFaint
width: Theme.iconSizeLarge * 0.9
height: Theme.iconSizeLarge * 0.9
anchors.centerIn: parent
radius: width / 2
}
IconButton {
id: downloadButton
anchors.centerIn: parent
width: Theme.iconSizeLarge
height: Theme.iconSizeLarge
icon {
source: "image://theme/icon-m-cloud-download?white"
asynchronous: true
}
highlighted: audioMessageComponent.highlighted || down
onClicked: {
tdLibWrapper.copyFileToDownloads(audioData[audioType].local.path);
}
}
}
} }
ProgressBar { ProgressBar {
id: downloadingProgressBar id: downloadingProgressBar
@ -250,6 +279,7 @@ Item {
target: messageAudio target: messageAudio
onPlaying: { onPlaying: {
playButton.visible = false; playButton.visible = false;
downloadItem.visible = false;
} }
} }
@ -261,7 +291,6 @@ Item {
timeLeftItem.visible = true; timeLeftItem.visible = true;
} else { } else {
messageAudio.play(); messageAudio.play();
timeLeftTimer.start();
} }
} }
} }
@ -272,7 +301,6 @@ Item {
Component.onCompleted: { Component.onCompleted: {
if (messageAudio.error === MediaPlayer.NoError) { if (messageAudio.error === MediaPlayer.NoError) {
messageAudio.play(); messageAudio.play();
timeLeftTimer.start();
} else { } else {
errorText.text = qsTr("Error loading audio! " + messageAudio.errorString) errorText.text = qsTr("Error loading audio! " + messageAudio.errorString)
errorTextOverlay.visible = true; errorTextOverlay.visible = true;
@ -323,6 +351,7 @@ Item {
onStopped: { onStopped: {
playButton.visible = true; playButton.visible = true;
downloadItem.visible = true;
audioComponentLoader.active = false; audioComponentLoader.active = false;
} }
} }
@ -336,15 +365,6 @@ Item {
size: BusyIndicatorSize.Medium size: BusyIndicatorSize.Medium
} }
Timer {
id: timeLeftTimer
repeat: false
interval: 2000
onTriggered: {
timeLeftItem.visible = false;
}
}
Item { Item {
id: timeLeftItem id: timeLeftItem
width: parent.width width: parent.width
@ -372,7 +392,7 @@ Item {
visible: audioComponentLoader.active && messageAudio.playbackState === MediaPlayer.PausedState visible: audioComponentLoader.active && messageAudio.playbackState === MediaPlayer.PausedState
Item { Item {
height: parent.height height: parent.height
width: parent.width width: parent.width / 2
IconButton { IconButton {
id: pausedPlayButton id: pausedPlayButton
anchors.centerIn: parent anchors.centerIn: parent
@ -385,7 +405,34 @@ Item {
} }
onClicked: { onClicked: {
messageAudio.play(); messageAudio.play();
timeLeftTimer.start(); }
}
}
Item {
id: pausedDownloadItem
width: parent.width / 2
height: parent.height
Rectangle {
color: Theme.primaryColor
opacity: Theme.opacityFaint
width: Theme.iconSizeLarge * 0.9
height: Theme.iconSizeLarge * 0.9
anchors.centerIn: parent
radius: width / 2
}
IconButton {
id: pausedDownloadButton
anchors.centerIn: parent
width: Theme.iconSizeLarge
height: Theme.iconSizeLarge
icon {
source: "image://theme/icon-m-cloud-download?white"
asynchronous: true
}
highlighted: audioMessageComponent.highlighted || down
onClicked: {
tdLibWrapper.copyFileToDownloads(audioData[audioType].local.path);
} }
} }
} }
@ -406,7 +453,6 @@ Item {
onReleased: { onReleased: {
messageAudio.seek(Math.floor(value)); messageAudio.seek(Math.floor(value));
messageAudio.play(); messageAudio.play();
timeLeftTimer.start();
} }
valueText: getTimeString(Math.round((messageAudio.duration - messageAudioSlider.value) / 1000)) valueText: getTimeString(Math.round((messageAudio.duration - messageAudioSlider.value) / 1000))
} }

View file

@ -77,7 +77,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: qsTr("Download Document") text: qsTr("Download Document")
visible: false visible: false
highlighted: videoMessageComponent.highlighted || down highlighted: documentPreviewItem.highlighted || down
onClicked: { onClicked: {
downloadDocumentButton.visible = false; downloadDocumentButton.visible = false;
downloadingProgressBar.visible = true; downloadingProgressBar.visible = true;
@ -101,7 +101,7 @@ Item {
anchors.centerIn: parent anchors.centerIn: parent
text: qsTr("Open Document") text: qsTr("Open Document")
visible: false visible: false
highlighted: videoMessageComponent.highlighted || down highlighted: documentPreviewItem.highlighted || down
onClicked: { onClicked: {
documentPreviewItem.openRequested = true; documentPreviewItem.openRequested = true;
tdLibWrapper.openFileOnDevice(documentData.document.local.path); tdLibWrapper.openFileOnDevice(documentData.document.local.path);

View file

@ -183,6 +183,13 @@ Page {
onErrorReceived: { onErrorReceived: {
Functions.handleErrorMessage(code, message); Functions.handleErrorMessage(code, message);
} }
onCopyToDownloadsSuccessful: {
appNotification.show(qsTr("Download of %1 successful.").arg(fileName), filePath);
}
onCopyToDownloadsError: {
appNotification.show(qsTr("Download failed."));
}
} }
Component.onCompleted: { Component.onCompleted: {

View file

@ -1026,6 +1026,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Neuer Chat</translation> <translation>Neuer Chat</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Download von %1 erfolgreich.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Download fehlgeschlagen.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1026,6 +1026,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>New Chat</translation> <translation>New Chat</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Download of %1 successful.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Download failed.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1015,6 +1015,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Nueva charla</translation> <translation>Nueva charla</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Bajada de %1 exitosa.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Error al bajar</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1027,6 +1027,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Uusi keskustelu</translation> <translation>Uusi keskustelu</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Lataus epäonnistui.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1015,6 +1015,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">A %1 letöltése sikerült.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">A letöltés nem sikerült.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1026,6 +1026,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Nuova chat</translation> <translation>Nuova chat</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Download di %1 completato.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Download non riuscito.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1037,6 +1037,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Nowy czat</translation> <translation>Nowy czat</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1037,6 +1037,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Новый Чат</translation> <translation>Новый Чат</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Успешно скачано %1.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Ошибка скачивания.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1026,6 +1026,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation>Ny chatt</translation> <translation>Ny chatt</translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Nerladdning av %1 slutförd.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1015,6 +1015,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation></translation> <translation></translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished"> %1 </translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>

View file

@ -1026,6 +1026,14 @@
<source>New Chat</source> <source>New Chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Download of %1 successful.</source>
<translation type="unfinished">Download of %1 successful.</translation>
</message>
<message>
<source>Download failed.</source>
<translation type="unfinished">Download failed.</translation>
</message>
</context> </context>
<context> <context>
<name>PinnedMessageItem</name> <name>PinnedMessageItem</name>