Added Connecting state to Calls::TopBar.

This commit is contained in:
23rd 2020-12-18 21:02:19 +03:00
parent 7a07acb124
commit b85bbadd74
5 changed files with 81 additions and 38 deletions

View file

@ -766,6 +766,15 @@ void GroupCall::sendMutedUpdate() {
}).send(); }).send();
} }
rpl::producer<bool> GroupCall::connectingValue() const {
using namespace rpl::mappers;
return _state.value() | rpl::map(
_1 == State::Creating
|| _1 == State::Joining
|| _1 == State::Connecting
) | rpl::distinct_until_changed();
}
void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) { void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) {
if (input) { if (input) {
_mediaDevices->switchToAudioInput(deviceId); _mediaDevices->switchToAudioInput(deviceId);

View file

@ -120,6 +120,7 @@ public:
[[nodiscard]] rpl::producer<State> stateValue() const { [[nodiscard]] rpl::producer<State> stateValue() const {
return _state.value(); return _state.value();
} }
[[nodiscard]] rpl::producer<bool> connectingValue() const;
[[nodiscard]] rpl::producer<LevelUpdate> levelUpdates() const { [[nodiscard]] rpl::producer<LevelUpdate> levelUpdates() const {
return _levelUpdates.events(); return _levelUpdates.events();

View file

@ -417,14 +417,9 @@ void GroupPanel::initWithCall(GroupCall *call) {
} }
}, _callLifetime); }, _callLifetime);
using namespace rpl::mappers;
rpl::combine( rpl::combine(
_call->mutedValue() | MapPushToTalkToActive(), _call->mutedValue() | MapPushToTalkToActive(),
_call->stateValue() | rpl::map( _call->connectingValue()
_1 == State::Creating
|| _1 == State::Joining
|| _1 == State::Connecting
)
) | rpl::distinct_until_changed( ) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](MuteState mute, bool connecting) { ) | rpl::start_with_next([=](MuteState mute, bool connecting) {
_mute->setState(Ui::CallMuteButtonState{ _mute->setState(Ui::CallMuteButtonState{

View file

@ -35,6 +35,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_layers.h" #include "styles/style_layers.h"
namespace Calls { namespace Calls {
enum class BarState {
Connecting,
Active,
Muted,
ForceMuted,
};
namespace { namespace {
constexpr auto kMaxUsersInBar = 3; constexpr auto kMaxUsersInBar = 3;
@ -47,6 +55,16 @@ constexpr auto kHideBlobsDuration = crl::time(500);
constexpr auto kBlobLevelDuration = crl::time(250); constexpr auto kBlobLevelDuration = crl::time(250);
constexpr auto kBlobUpdateInterval = crl::time(100); constexpr auto kBlobUpdateInterval = crl::time(100);
auto BarStateFromMuteState(MuteState state, bool connecting) {
return (connecting
? BarState::Connecting
: state == MuteState::ForceMuted
? BarState::ForceMuted
: state == MuteState::Muted
? BarState::Muted
: BarState::Active);
};
auto LinearBlobs() { auto LinearBlobs() {
return std::vector<Ui::Paint::LinearBlobs::BlobData>{ return std::vector<Ui::Paint::LinearBlobs::BlobData>{
{ {
@ -79,22 +97,26 @@ auto LinearBlobs() {
auto Colors() { auto Colors() {
using Vector = std::vector<QColor>; using Vector = std::vector<QColor>;
using Colors = anim::gradient_colors; using Colors = anim::gradient_colors;
return base::flat_map<MuteState, Colors>{ return base::flat_map<BarState, Colors>{
{ {
MuteState::ForceMuted, BarState::ForceMuted,
Colors(QGradientStops{ Colors(QGradientStops{
{ 0.0, st::groupCallForceMutedBar1->c }, { 0.0, st::groupCallForceMutedBar1->c },
{ .35, st::groupCallForceMutedBar2->c }, { .35, st::groupCallForceMutedBar2->c },
{ 1.0, st::groupCallForceMutedBar3->c } }) { 1.0, st::groupCallForceMutedBar3->c } })
}, },
{ {
MuteState::Active, BarState::Active,
Colors(Vector{ st::groupCallLive1->c, st::groupCallLive2->c }) Colors(Vector{ st::groupCallLive1->c, st::groupCallLive2->c })
}, },
{ {
MuteState::Muted, BarState::Muted,
Colors(Vector{ st::groupCallMuted1->c, st::groupCallMuted2->c }) Colors(Vector{ st::groupCallMuted1->c, st::groupCallMuted2->c })
}, },
{
BarState::Connecting,
Colors(st::callBarBgMuted->c)
},
}; };
} }
@ -257,21 +279,32 @@ void TopBar::initControls() {
const auto mapToState = [](bool muted) { const auto mapToState = [](bool muted) {
return muted ? MuteState::Muted : MuteState::Active; return muted ? MuteState::Muted : MuteState::Active;
}; };
const auto fromState = _mute->lifetime().make_state<MuteState>( const auto fromState = _mute->lifetime().make_state<BarState>(
_call ? mapToState(_call->muted()) : _groupCall->muted()); BarStateFromMuteState(
_call
? mapToState(_call->muted())
: _groupCall->muted(),
false));
auto muted = _call auto muted = _call
? _call->mutedValue() | rpl::map(mapToState) ? rpl::combine(
: (_groupCall->mutedValue() _call->mutedValue() | rpl::map(mapToState),
| MapPushToTalkToActive() rpl::single(false))
| rpl::distinct_until_changed() : rpl::combine(
| rpl::type_erased()); (_groupCall->mutedValue()
| MapPushToTalkToActive()
| rpl::distinct_until_changed()
| rpl::type_erased()),
_groupCall->connectingValue());
std::move( std::move(
muted muted
) | rpl::start_with_next([=](MuteState state) { ) | rpl::map(
setMuted(state != MuteState::Active); BarStateFromMuteState
) | rpl::start_with_next([=](BarState state) {
_isGroupConnecting = (state == BarState::Connecting);
setMuted(state != BarState::Active);
update(); update();
const auto isForceMuted = (state == MuteState::ForceMuted); const auto isForceMuted = (state == BarState::ForceMuted);
if (isForceMuted) { if (isForceMuted) {
_mute->clearState(); _mute->clearState();
} }
@ -285,8 +318,8 @@ void TopBar::initControls() {
const auto toMuted = state; const auto toMuted = state;
*fromState = state; *fromState = state;
const auto crossFrom = (fromMuted != MuteState::Active) ? 1. : 0.; const auto crossFrom = (fromMuted != BarState::Active) ? 1. : 0.;
const auto crossTo = (toMuted != MuteState::Active) ? 1. : 0.; const auto crossTo = (toMuted != BarState::Active) ? 1. : 0.;
auto animationCallback = [=](float64 value) { auto animationCallback = [=](float64 value) {
if (_groupCall) { if (_groupCall) {
@ -312,6 +345,14 @@ void TopBar::initControls() {
if (const auto group = _groupCall.get()) { if (const auto group = _groupCall.get()) {
subscribeToMembersChanges(group); subscribeToMembersChanges(group);
_isGroupConnecting.value(
) | rpl::start_with_next([=](bool isConnecting) {
_mute->setAttribute(
Qt::WA_TransparentForMouseEvents,
isConnecting);
updateInfoLabels();
}, lifetime());
} }
if (const auto call = _call.get()) { if (const auto call = _call.get()) {
@ -415,23 +456,14 @@ void TopBar::initBlobsUnder(
auto hideBlobs = rpl::combine( auto hideBlobs = rpl::combine(
rpl::single(anim::Disabled()) | rpl::then(anim::Disables()), rpl::single(anim::Disabled()) | rpl::then(anim::Disables()),
Core::App().appDeactivatedValue(), Core::App().appDeactivatedValue(),
group->stateValue( group->connectingValue()
) | rpl::map([](Calls::GroupCall::State state) { ) | rpl::map([](bool animDisabled, bool hide, bool connecting) {
using State = Calls::GroupCall::State; return connecting || animDisabled || hide;
if (state != State::Creating
&& state != State::Joining
&& state != State::Joined
&& state != State::Connecting) {
return true;
}
return false;
}) | rpl::distinct_until_changed()
) | rpl::map([](bool animDisabled, bool hide, bool isBadState) {
return isBadState || animDisabled || hide;
}); });
std::move( std::move(
hideBlobs hideBlobs
) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](bool hide) { ) | rpl::start_with_next([=](bool hide) {
if (hide) { if (hide) {
state->paint.setLevel(0.); state->paint.setLevel(0.);
@ -611,8 +643,11 @@ void TopBar::setInfoLabels() {
} else if (const auto group = _groupCall.get()) { } else if (const auto group = _groupCall.get()) {
const auto peer = group->peer(); const auto peer = group->peer();
const auto name = peer->name; const auto name = peer->name;
_fullInfoLabel->setText(name.toUpper()); const auto text = _isGroupConnecting.current()
_shortInfoLabel->setText(name.toUpper()); ? tr::lng_group_call_connecting(tr::now)
: name.toUpper();
_fullInfoLabel->setText(text);
_shortInfoLabel->setText(text);
} }
} }

View file

@ -33,6 +33,7 @@ class GroupCall;
class SignalBars; class SignalBars;
class Mute; class Mute;
enum class MuteState; enum class MuteState;
enum class BarState;
class TopBar : public Ui::RpWidget { class TopBar : public Ui::RpWidget {
public: public:
@ -83,8 +84,10 @@ private:
object_ptr<Ui::IconButton> _hangup; object_ptr<Ui::IconButton> _hangup;
base::unique_qptr<Ui::RpWidget> _blobs; base::unique_qptr<Ui::RpWidget> _blobs;
rpl::variable<bool> _isGroupConnecting = false;
QBrush _groupBrush; QBrush _groupBrush;
anim::linear_gradients<MuteState> _gradients; anim::linear_gradients<BarState> _gradients;
Ui::Animations::Simple _switchStateAnimation; Ui::Animations::Simple _switchStateAnimation;
base::Timer _updateDurationTimer; base::Timer _updateDurationTimer;