Show mouse hold tip when clicking record button.

This commit is contained in:
John Preston 2021-10-30 15:13:10 +04:00
parent 05efc925f8
commit 7ad6699bff
4 changed files with 33 additions and 7 deletions

View file

@ -1542,6 +1542,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_record_lock_cancel_sure" = "Are you sure you want to stop recording and discard your voice message?"; "lng_record_lock_cancel_sure" = "Are you sure you want to stop recording and discard your voice message?";
"lng_record_listen_cancel_sure" = "Are you sure you want to discard your recorded voice message?"; "lng_record_listen_cancel_sure" = "Are you sure you want to discard your recorded voice message?";
"lng_record_lock_discard" = "Discard"; "lng_record_lock_discard" = "Discard";
"lng_record_hold_tip" = "Please hold the mouse button pressed to record a voice message.";
"lng_will_be_notified" = "Members will be notified when you post"; "lng_will_be_notified" = "Members will be notified when you post";
"lng_wont_be_notified" = "Members will not be notified when you post"; "lng_wont_be_notified" = "Members will not be notified when you post";
"lng_willbe_history" = "Please select a chat to start messaging"; "lng_willbe_history" = "Please select a chat to start messaging";

View file

@ -918,6 +918,13 @@ void HistoryWidget::initVoiceRecordBar() {
_scroll->viewportEvent(e); _scroll->viewportEvent(e);
}, lifetime()); }, lifetime());
_voiceRecordBar->recordingTipRequests(
) | rpl::start_with_next([=] {
Ui::ShowMultilineToast({
.text = { tr::lng_record_hold_tip(tr::now) },
});
}, lifetime());
_voiceRecordBar->hideFast(); _voiceRecordBar->hideFast();
} }

View file

@ -44,8 +44,10 @@ using VoiceToSend = VoiceRecordBar::VoiceToSend;
constexpr auto kAudioVoiceUpdateView = crl::time(200); constexpr auto kAudioVoiceUpdateView = crl::time(200);
constexpr auto kAudioVoiceMaxLength = 100 * 60; // 100 minutes constexpr auto kAudioVoiceMaxLength = 100 * 60; // 100 minutes
constexpr auto kMaxSamples = constexpr auto kMaxSamples
::Media::Player::kDefaultFrequency * kAudioVoiceMaxLength; = ::Media::Player::kDefaultFrequency * kAudioVoiceMaxLength;
constexpr auto kMinSamples
= ::Media::Player::kDefaultFrequency / 5; // 0.2 seconds
constexpr auto kInactiveWaveformBarAlpha = int(255 * 0.6); constexpr auto kInactiveWaveformBarAlpha = int(255 * 0.6);
@ -1190,8 +1192,12 @@ void VoiceRecordBar::init() {
if (_startRecordingFilter && _startRecordingFilter()) { if (_startRecordingFilter && _startRecordingFilter()) {
return; return;
} }
_recordingTipRequired = true;
_startTimer.callOnce(st::historyRecordVoiceShowDuration); _startTimer.callOnce(st::historyRecordVoiceShowDuration);
} else if (e->type() == QEvent::MouseButtonRelease) { } else if (e->type() == QEvent::MouseButtonRelease) {
if (base::take(_recordingTipRequired)) {
_recordingTipRequests.fire({});
}
_startTimer.cancel(); _startTimer.cancel();
} }
}, lifetime()); }, lifetime());
@ -1278,7 +1284,7 @@ void VoiceRecordBar::startRecording() {
return; return;
} }
auto appearanceCallback = [=] { auto appearanceCallback = [=] {
if(_showAnimation.animating()) { if (_showAnimation.animating()) {
return; return;
} }
@ -1296,6 +1302,7 @@ void VoiceRecordBar::startRecording() {
instance()->start(); instance()->start();
instance()->updated( instance()->updated(
) | rpl::start_with_next_error([=](const Update &update) { ) | rpl::start_with_next_error([=](const Update &update) {
_recordingTipRequired = (update.samples < kMinSamples);
recordUpdated(update.level, update.samples); recordUpdated(update.level, update.samples);
}, [=] { }, [=] {
stop(false); stop(false);
@ -1311,10 +1318,10 @@ void VoiceRecordBar::startRecording() {
_send->events( _send->events(
) | rpl::filter([=](not_null<QEvent*> e) { ) | rpl::filter([=](not_null<QEvent*> e) {
return isTypeRecord() return (e->type() == QEvent::MouseMove
&& !_lock->isLocked() || e->type() == QEvent::MouseButtonRelease)
&& (e->type() == QEvent::MouseMove && isTypeRecord()
|| e->type() == QEvent::MouseButtonRelease); && !_lock->isLocked();
}) | rpl::start_with_next([=](not_null<QEvent*> e) { }) | rpl::start_with_next([=](not_null<QEvent*> e) {
const auto type = e->type(); const auto type = e->type();
if (type == QEvent::MouseMove) { if (type == QEvent::MouseMove) {
@ -1331,6 +1338,9 @@ void VoiceRecordBar::startRecording() {
} }
computeAndSetLockProgress(mouse->globalPos()); computeAndSetLockProgress(mouse->globalPos());
} else if (type == QEvent::MouseButtonRelease) { } else if (type == QEvent::MouseButtonRelease) {
if (base::take(_recordingTipRequired)) {
_recordingTipRequests.fire({});
}
stop(_inField.current()); stop(_inField.current());
} }
}, _recordingLifetime); }, _recordingLifetime);
@ -1533,6 +1543,10 @@ rpl::producer<> VoiceRecordBar::updateSendButtonTypeRequests() const {
return _listenChanges.events(); return _listenChanges.events();
} }
rpl::producer<> VoiceRecordBar::recordingTipRequests() const {
return _recordingTipRequests.events();
}
bool VoiceRecordBar::isLockPresent() const { bool VoiceRecordBar::isLockPresent() const {
return _lockShowing.current(); return _lockShowing.current();
} }

View file

@ -67,6 +67,7 @@ public:
[[nodiscard]] rpl::producer<bool> lockShowStarts() const; [[nodiscard]] rpl::producer<bool> lockShowStarts() const;
[[nodiscard]] rpl::producer<not_null<QEvent*>> lockViewportEvents() const; [[nodiscard]] rpl::producer<not_null<QEvent*>> lockViewportEvents() const;
[[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const; [[nodiscard]] rpl::producer<> updateSendButtonTypeRequests() const;
[[nodiscard]] rpl::producer<> recordingTipRequests() const;
void requestToSendWithOptions(Api::SendOptions options); void requestToSendWithOptions(Api::SendOptions options);
@ -151,6 +152,9 @@ private:
int _recordingSamples = 0; int _recordingSamples = 0;
float64 _redCircleProgress = 0.; float64 _redCircleProgress = 0.;
rpl::event_stream<> _recordingTipRequests;
bool _recordingTipRequired = false;
const style::font &_cancelFont; const style::font &_cancelFont;
rpl::lifetime _recordingLifetime; rpl::lifetime _recordingLifetime;