Add video story saved toast to viewer.

This commit is contained in:
John Preston 2023-06-29 20:50:32 +04:00
parent 3d795f2f67
commit 1d5b57c39c
4 changed files with 69 additions and 31 deletions

View File

@ -2502,6 +2502,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_mediaview_title" = "Media viewer";
"lng_mediaview_saved_to" = "Image was saved to your {downloads} folder";
"lng_mediaview_saved_images_to" = "Images were saved to your {downloads} folder";
"lng_mediaview_video_saved_to" = "Video file was saved to your {downloads} folder";
"lng_mediaview_downloads" = "Downloads";
"lng_mediaview_playback_speed" = "Playback speed: {speed}";
"lng_mediaview_rotate_video" = "Rotate video";

View File

@ -444,20 +444,8 @@ OverlayWidget::OverlayWidget()
? Core::App().settings().videoVolume()
: Core::Settings::kDefaultVolume;
const auto text = tr::lng_mediaview_saved_to(
tr::now,
lt_downloads,
Ui::Text::Link(
tr::lng_mediaview_downloads(tr::now),
"internal:show_saved_message"),
Ui::Text::WithEntities);
_saveMsgText.setMarkedText(st::mediaviewSaveMsgStyle, text);
_saveMsg = QRect(0, 0, _saveMsgText.maxWidth() + st::mediaviewSaveMsgPadding.left() + st::mediaviewSaveMsgPadding.right(), st::mediaviewSaveMsgStyle.font->height + st::mediaviewSaveMsgPadding.top() + st::mediaviewSaveMsgPadding.bottom());
_saveMsgImage = QImage(
_saveMsg.size() * cIntRetinaFactor(),
QImage::Format_ARGB32_Premultiplied);
_saveMsgTimer.setCallback([=, delay = st::mediaviewSaveMsgHiding] {
_saveMsgAnimation.start([=] { updateImage(); }, 1., 0., delay);
_saveMsgAnimation.start([=] { updateSaveMsg(); }, 1., 0., delay);
});
_docRectImage = QImage(
@ -663,6 +651,40 @@ OverlayWidget::OverlayWidget()
orderWidgets();
}
void OverlayWidget::showSaveMsgToast(const QString &path, auto phrase) {
showSaveMsgToastWith(path, phrase(
tr::now,
lt_downloads,
Ui::Text::Link(
tr::lng_mediaview_downloads(tr::now),
"internal:show_saved_message"),
Ui::Text::WithEntities));
}
void OverlayWidget::showSaveMsgToastWith(
const QString &path,
const TextWithEntities &text) {
_saveMsgFilename = path;
_saveMsgText.setMarkedText(st::mediaviewSaveMsgStyle, text);
const auto w = _saveMsgText.maxWidth()
+ st::mediaviewSaveMsgPadding.left()
+ st::mediaviewSaveMsgPadding.right();
const auto h = st::mediaviewSaveMsgStyle.font->height
+ st::mediaviewSaveMsgPadding.top()
+ st::mediaviewSaveMsgPadding.bottom();
_saveMsg = QRect((width() - w) / 2, (height() - h) / 2, w, h);
const auto toIn = 1.;
const auto callback = [=](float64 value) {
updateSaveMsg();
if (!_saveMsgAnimation.animating()) {
_saveMsgTimer.callOnce(st::mediaviewSaveMsgShown);
}
};
const auto duration = st::mediaviewSaveMsgShowing;
_saveMsgAnimation.start(callback, 0., 1., duration);
updateSaveMsg();
}
void OverlayWidget::orderWidgets() {
_helper->orderWidgets();
}
@ -1104,6 +1126,13 @@ void OverlayWidget::documentUpdated(not_null<DocumentData*> document) {
: 0;
_streamed->controls->setLoadingProgress(ready, _document->size);
}
if (_stories
&& !_documentLoadingTo.isEmpty()
&& _document->location(true).isEmpty()) {
showSaveMsgToast(
base::take(_documentLoadingTo),
tr::lng_mediaview_video_saved_to);
}
}
void OverlayWidget::changingMsgId(FullMsgId newId, MsgId oldId) {
@ -1995,6 +2024,7 @@ void OverlayWidget::assignMediaPointer(DocumentData *document) {
} else {
_documentMedia = nullptr;
}
_documentLoadingTo = QString();
}
}
@ -2002,6 +2032,7 @@ void OverlayWidget::assignMediaPointer(not_null<PhotoData*> photo) {
_savePhotoVideoWhenLoaded = SavePhotoVideo::None;
_document = nullptr;
_documentMedia = nullptr;
_documentLoadingTo = QString();
if (_photo != photo) {
_photo = photo;
_photoMedia = _photo->createMediaView();
@ -2349,6 +2380,9 @@ void OverlayWidget::downloadMedia() {
}, toName, manager.computeNextStartDate());
}
}
if (_stories && !toName.isEmpty()) {
showSaveMsgToast(toName, tr::lng_mediaview_video_saved_to);
}
location.accessDisable();
} else {
if (_document->filepath(true).isEmpty()
@ -2357,7 +2391,15 @@ void OverlayWidget::downloadMedia() {
_message ? _message->fullId() : FullMsgId(),
_document,
DocumentSaveClickHandler::Mode::ToFile);
updateControls();
_documentLoadingTo = _document->loadingFilePath();
if (_stories && _documentLoadingTo.isEmpty()) {
toName = _document->filepath(true);
if (!toName.isEmpty()) {
showSaveMsgToast(
toName,
tr::lng_mediaview_video_saved_to);
}
}
} else {
_saveVisible = contentCanBeSaved();
update(_saveNavOver);
@ -2393,19 +2435,9 @@ void OverlayWidget::downloadMedia() {
}
}
if (!toName.isEmpty()) {
_saveMsgFilename = toName;
const auto toIn = 1.;
_saveMsgAnimation.start(
[=](float64 value) {
updateImage();
if (value == toIn) {
_saveMsgTimer.callOnce(st::mediaviewSaveMsgShown);
}
},
0.,
toIn,
st::mediaviewSaveMsgShowing);
updateImage();
showSaveMsgToast(toName, (_stories && _document)
? tr::lng_mediaview_video_saved_to
: tr::lng_mediaview_saved_to);
}
}
@ -5879,7 +5911,7 @@ void OverlayWidget::handleTouchTimer() {
_touchRightButton = true;
}
void OverlayWidget::updateImage() {
void OverlayWidget::updateSaveMsg() {
update(_saveMsg);
}

View File

@ -278,7 +278,12 @@ private:
void showDropdown();
void handleTouchTimer();
void handleDocumentClick();
void updateImage();
void showSaveMsgToast(const QString &path, auto phrase);
void showSaveMsgToastWith(
const QString &path,
const TextWithEntities &text);
void updateSaveMsg();
void clearBeforeHide();
void clearAfterHide();
@ -533,6 +538,7 @@ private:
rpl::lifetime _sessionLifetime;
PhotoData *_photo = nullptr;
DocumentData *_document = nullptr;
QString _documentLoadingTo;
std::shared_ptr<Data::PhotoMedia> _photoMedia;
std::shared_ptr<Data::DocumentMedia> _documentMedia;
base::flat_set<std::shared_ptr<Data::PhotoMedia>> _preloadPhotos;
@ -689,7 +695,6 @@ private:
QString _saveMsgFilename;
QRect _saveMsg;
QImage _saveMsgImage;
Ui::Text::String _saveMsgText;
SavePhotoVideo _savePhotoVideoWhenLoaded = SavePhotoVideo::None;
// _saveMsgAnimation -> _saveMsgTimer -> _saveMsgAnimation.

@ -1 +1 @@
Subproject commit ed00cd28098e1b04979e7b2dd3a582b7a8a6713a
Subproject commit 08f80548668df2737905365b254624055642b937