Improved display management of voice record controls.

This commit is contained in:
23rd 2020-10-14 02:48:10 +03:00 committed by John Preston
parent b3925a3bec
commit cb84e70bdc
5 changed files with 68 additions and 52 deletions

View file

@ -776,6 +776,8 @@ void HistoryWidget::initVoiceRecordBar() {
updateHistoryDownVisibility(); updateHistoryDownVisibility();
updateUnreadMentionsVisibility(); updateUnreadMentionsVisibility();
}, lifetime()); }, lifetime());
_voiceRecordBar->hideFast();
} }
void HistoryWidget::initTabbedSelector() { void HistoryWidget::initTabbedSelector() {
@ -2063,13 +2065,7 @@ void HistoryWidget::updateControlsVisibility() {
updateHistoryDownVisibility(); updateHistoryDownVisibility();
updateUnreadMentionsVisibility(); updateUnreadMentionsVisibility();
if (!_history || _a_show.animating()) { if (!_history || _a_show.animating()) {
if (_tabbedPanel) { hideChildWidgets();
_tabbedPanel->hideFast();
}
if (_pinnedBar) {
_pinnedBar->hide();
}
hideChildren();
return; return;
} }
@ -2140,6 +2136,9 @@ void HistoryWidget::updateControlsVisibility() {
if (_tabbedPanel) { if (_tabbedPanel) {
_tabbedPanel->hide(); _tabbedPanel->hide();
} }
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
if (_inlineResults) { if (_inlineResults) {
_inlineResults->hide(); _inlineResults->hide();
} }
@ -2231,6 +2230,9 @@ void HistoryWidget::updateControlsVisibility() {
if (_tabbedPanel) { if (_tabbedPanel) {
_tabbedPanel->hide(); _tabbedPanel->hide();
} }
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
if (_inlineResults) { if (_inlineResults) {
_inlineResults->hide(); _inlineResults->hide();
} }
@ -3005,6 +3007,19 @@ void HistoryWidget::saveEditMsg() {
fail); fail);
} }
void HistoryWidget::hideChildWidgets() {
if (_tabbedPanel) {
_tabbedPanel->hideFast();
}
if (_pinnedBar) {
_pinnedBar->hide();
}
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
hideChildren();
}
void HistoryWidget::hideSelectorControlsAnimated() { void HistoryWidget::hideSelectorControlsAnimated() {
_fieldAutocomplete->hideAnimated(); _fieldAutocomplete->hideAnimated();
if (_supportAutocomplete) { if (_supportAutocomplete) {
@ -3212,13 +3227,7 @@ void HistoryWidget::showAnimated(
_cacheOver = controller()->content()->grabForShowAnimation(params); _cacheOver = controller()->content()->grabForShowAnimation(params);
if (_tabbedPanel) { hideChildWidgets();
_tabbedPanel->hideFast();
}
if (_pinnedBar) {
_pinnedBar->hide();
}
hideChildren();
if (params.withTopBarShadow) _topShadow->show(); if (params.withTopBarShadow) _topShadow->show();
if (_showDirection == Window::SlideDirection::FromLeft) { if (_showDirection == Window::SlideDirection::FromLeft) {

View file

@ -456,6 +456,7 @@ private:
bool replyToNextMessage(); bool replyToNextMessage();
[[nodiscard]] bool showSlowmodeError(); [[nodiscard]] bool showSlowmodeError();
void hideChildWidgets();
void hideSelectorControlsAnimated(); void hideSelectorControlsAnimated();
int countMembersDropdownHeightMax() const; int countMembersDropdownHeightMax() const;

View file

@ -660,6 +660,9 @@ void ComposeControls::showStarted() {
if (_tabbedPanel) { if (_tabbedPanel) {
_tabbedPanel->hideFast(); _tabbedPanel->hideFast();
} }
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
_wrap->hide(); _wrap->hide();
_writeRestricted->hide(); _writeRestricted->hide();
} }
@ -671,6 +674,9 @@ void ComposeControls::showFinished() {
if (_tabbedPanel) { if (_tabbedPanel) {
_tabbedPanel->hideFast(); _tabbedPanel->hideFast();
} }
if (_voiceRecordBar) {
_voiceRecordBar->hideFast();
}
updateWrappingVisibility(); updateWrappingVisibility();
_voiceRecordBar->orderControls(); _voiceRecordBar->orderControls();
} }

View file

@ -68,7 +68,6 @@ public:
void requestPaintColor(float64 progress); void requestPaintColor(float64 progress);
void requestPaintProgress(float64 progress); void requestPaintProgress(float64 progress);
void requestPaintLevel(quint16 level); void requestPaintLevel(quint16 level);
void reset();
[[nodiscard]] rpl::producer<bool> actives() const; [[nodiscard]] rpl::producer<bool> actives() const;
@ -101,7 +100,6 @@ public:
RecordLock(not_null<Ui::RpWidget*> parent); RecordLock(not_null<Ui::RpWidget*> parent);
void requestPaintProgress(float64 progress); void requestPaintProgress(float64 progress);
void reset();
[[nodiscard]] rpl::producer<> locks() const; [[nodiscard]] rpl::producer<> locks() const;
[[nodiscard]] bool isLocked() const; [[nodiscard]] bool isLocked() const;
@ -161,26 +159,19 @@ bool RecordLevel::recordingAnimationCallback(crl::time now) {
void RecordLevel::init() { void RecordLevel::init() {
const auto hasProgress = [](auto value) { return value != 0.; }; const auto hasProgress = [](auto value) { return value != 0.; };
// Do not allow the widget to be shown from the outside.
shownValue(
) | rpl::start_with_next([=](bool shown) {
const auto shouldShown = hasProgress(_showProgress.current());
if (shown != shouldShown) {
setVisible(shouldShown);
}
}, lifetime());
paintRequest( paintRequest(
) | rpl::start_with_next([=](const QRect &clip) { ) | rpl::start_with_next([=](const QRect &clip) {
Painter p(this); Painter p(this);
drawProgress(p); drawProgress(p);
p.setOpacity(_showProgress.current());
st::historyRecordVoiceActive.paintInCenter(p, rect()); st::historyRecordVoiceActive.paintInCenter(p, rect());
}, lifetime()); }, lifetime());
_showProgress.changes( rpl::merge(
) | rpl::map(hasProgress) | rpl::distinct_until_changed( shownValue(),
_showProgress.value() | rpl::map(hasProgress)
) | rpl::start_with_next([=](bool show) { ) | rpl::start_with_next([=](bool show) {
setVisible(show); setVisible(show);
setMouseTracking(show); setMouseTracking(show);
@ -188,6 +179,7 @@ void RecordLevel::init() {
_recordingLevel = anim::value(); _recordingLevel = anim::value();
_recordingAnimation.stop(); _recordingAnimation.stop();
_showingLifetime.destroy(); _showingLifetime.destroy();
_showProgress = 0.;
} }
}, lifetime()); }, lifetime());
@ -281,6 +273,7 @@ void RecordLock::init() {
) | rpl::start_with_next([=](bool shown) { ) | rpl::start_with_next([=](bool shown) {
if (!shown) { if (!shown) {
_lockAnimation.stop(); _lockAnimation.stop();
_lockEnderAnimation.stop();
_progress = 0.; _progress = 0.;
} }
}, lifetime()); }, lifetime());
@ -433,6 +426,7 @@ VoiceRecordBar::VoiceRecordBar(
, _cancelFont(st::historyRecordFont) { , _cancelFont(st::historyRecordFont) {
resize(QSize(parent->width(), recorderHeight)); resize(QSize(parent->width(), recorderHeight));
init(); init();
hideFast();
} }
VoiceRecordBar::VoiceRecordBar( VoiceRecordBar::VoiceRecordBar(
@ -478,7 +472,6 @@ void VoiceRecordBar::updateLockGeometry() {
} }
void VoiceRecordBar::init() { void VoiceRecordBar::init() {
hide();
// Keep VoiceRecordBar behind SendButton. // Keep VoiceRecordBar behind SendButton.
rpl::single( rpl::single(
) | rpl::then( ) | rpl::then(
@ -490,6 +483,13 @@ void VoiceRecordBar::init() {
orderControls(); orderControls();
}, lifetime()); }, lifetime());
shownValue(
) | rpl::start_with_next([=](bool show) {
if (!show) {
finish();
}
}, lifetime());
sizeValue( sizeValue(
) | rpl::start_with_next([=](QSize size) { ) | rpl::start_with_next([=](QSize size) {
_centerY = size.height() / 2; _centerY = size.height() / 2;
@ -556,7 +556,6 @@ void VoiceRecordBar::init() {
_showLockAnimation.start(std::move(callback), from, to, duration); _showLockAnimation.start(std::move(callback), from, to, duration);
}, lifetime()); }, lifetime());
_lock->hide();
_lock->locks( _lock->locks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
installClickOutsideFilter(); installClickOutsideFilter();
@ -746,27 +745,35 @@ void VoiceRecordBar::recordUpdated(quint16 level, int samples) {
void VoiceRecordBar::stop(bool send) { void VoiceRecordBar::stop(bool send) {
auto disappearanceCallback = [=] { auto disappearanceCallback = [=] {
_showAnimation.stop();
hide(); hide();
_recording = false;
stopRecording(send); stopRecording(send);
_redCircleProgress = 0.;
_inField = false;
_recordingLifetime.destroy();
_recordingSamples = 0;
_sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 });
_controller->widget()->setInnerFocus();
}; };
_lockShowing = false; _lockShowing = false;
visibilityAnimate(false, std::move(disappearanceCallback)); visibilityAnimate(false, std::move(disappearanceCallback));
} }
void VoiceRecordBar::finish() {
_recordingLifetime.destroy();
_lockShowing = false;
_recording = false;
_inField = false;
_redCircleProgress = 0.;
_recordingSamples = 0;
_showAnimation.stop();
_sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 });
_controller->widget()->setInnerFocus();
}
void VoiceRecordBar::hideFast() {
hide();
_lock->hide();
_level->hide();
stopRecording(false);
}
void VoiceRecordBar::stopRecording(bool send) { void VoiceRecordBar::stopRecording(bool send) {
using namespace ::Media::Capture; using namespace ::Media::Capture;
if (!send) { if (!send) {
@ -880,12 +887,6 @@ float64 VoiceRecordBar::showAnimationRatio() const {
return _showAnimation.value(1.); return _showAnimation.value(1.);
} }
QString VoiceRecordBar::cancelMessage() const {
return _lock->isLocked()
? tr::lng_record_lock_cancel(tr::now)
: tr::lng_record_cancel(tr::now);
}
void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) { void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) {
const auto localPos = mapFromGlobal(globalPos); const auto localPos = mapFromGlobal(globalPos);
const auto lower = _lock->height(); const auto lower = _lock->height();

View file

@ -46,6 +46,7 @@ public:
void startRecording(); void startRecording();
void finishAnimating(); void finishAnimating();
void hideFast();
void orderControls(); void orderControls();
@ -68,7 +69,6 @@ private:
void updateMessageGeometry(); void updateMessageGeometry();
void updateLockGeometry(); void updateLockGeometry();
void recordError();
void recordUpdated(quint16 level, int samples); void recordUpdated(quint16 level, int samples);
bool recordingAnimationCallback(crl::time now); bool recordingAnimationCallback(crl::time now);
@ -81,7 +81,6 @@ private:
void drawDuration(Painter &p); void drawDuration(Painter &p);
void drawRedCircle(Painter &p); void drawRedCircle(Painter &p);
void drawMessage(Painter &p, float64 recordActive); void drawMessage(Painter &p, float64 recordActive);
void updateOverStates(QPoint pos);
void startRedCircleAnimation(); void startRedCircleAnimation();
void installClickOutsideFilter(); void installClickOutsideFilter();
@ -89,14 +88,14 @@ private:
bool isTypeRecord() const; bool isTypeRecord() const;
bool hasDuration() const; bool hasDuration() const;
void finish();
void activeAnimate(bool active); void activeAnimate(bool active);
float64 showAnimationRatio() const; float64 showAnimationRatio() const;
float64 activeAnimationRatio() const; float64 activeAnimationRatio() const;
void computeAndSetLockProgress(QPoint globalPos); void computeAndSetLockProgress(QPoint globalPos);
QString cancelMessage() const;
const not_null<Ui::RpWidget*> _sectionWidget; const not_null<Ui::RpWidget*> _sectionWidget;
const not_null<Window::SessionController*> _controller; const not_null<Window::SessionController*> _controller;
const std::shared_ptr<Ui::SendButton> _send; const std::shared_ptr<Ui::SendButton> _send;