Replaced observable with rpl in FixedBar of admin log.

This commit is contained in:
23rd 2021-05-25 16:15:35 +03:00
parent c22d200c17
commit 0fe7c07007

View file

@ -34,16 +34,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace AdminLog { namespace AdminLog {
class FixedBar final : public TWidget, private base::Subscriber { class FixedBar final : public TWidget {
public: public:
FixedBar( FixedBar(
QWidget *parent, QWidget *parent,
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<ChannelData*> channel); not_null<ChannelData*> channel);
base::Observable<void> showFilterSignal; [[nodiscard]] rpl::producer<> showFilterRequests() const;
base::Observable<void> searchCancelledSignal; [[nodiscard]] rpl::producer<> searchCancelRequests() const;
base::Observable<QString> searchSignal; [[nodiscard]] rpl::producer<QString> searchRequests() const;
// When animating mode is enabled the content is hidden and the // When animating mode is enabled the content is hidden and the
// whole fixed bar acts like a back button. // whole fixed bar acts like a back button.
@ -85,6 +85,9 @@ private:
bool _animatingMode = false; bool _animatingMode = false;
base::Timer _searchTimer; base::Timer _searchTimer;
rpl::event_stream<> _searchCancelRequests;
rpl::event_stream<QString> _searchRequests;
}; };
object_ptr<Window::SectionWidget> SectionMemento::createWidget( object_ptr<Window::SectionWidget> SectionMemento::createWidget(
@ -116,7 +119,6 @@ FixedBar::FixedBar(
, _filter(this, tr::lng_admin_log_filter(), st::topBarButton) { , _filter(this, tr::lng_admin_log_filter(), st::topBarButton) {
_backButton->moveToLeft(0, 0); _backButton->moveToLeft(0, 0);
_backButton->setClickedCallback([=] { goBack(); }); _backButton->setClickedCallback([=] { goBack(); });
_filter->setClickedCallback([=] { showFilterSignal.notify(); });
_search->setClickedCallback([=] { showSearch(); }); _search->setClickedCallback([=] { showSearch(); });
_cancel->setClickedCallback([=] { cancelSearch(); }); _cancel->setClickedCallback([=] { cancelSearch(); });
_field->hide(); _field->hide();
@ -158,7 +160,7 @@ void FixedBar::toggleSearch() {
_field->show(); _field->show();
_field->setFocus(); _field->setFocus();
} else { } else {
searchCancelledSignal.notify(true); _searchCancelRequests.fire({});
} }
} }
@ -198,7 +200,7 @@ void FixedBar::searchUpdated() {
} }
void FixedBar::applySearch() { void FixedBar::applySearch() {
searchSignal.notify(_field->getLastText()); _searchRequests.fire_copy(_field->getLastText());
} }
int FixedBar::resizeGetHeight(int newWidth) { int FixedBar::resizeGetHeight(int newWidth) {
@ -223,6 +225,18 @@ int FixedBar::resizeGetHeight(int newWidth) {
return newHeight; return newHeight;
} }
rpl::producer<> FixedBar::showFilterRequests() const {
return _filter->clicks() | rpl::to_empty;
}
rpl::producer<> FixedBar::searchCancelRequests() const {
return _searchCancelRequests.events();
}
rpl::producer<QString> FixedBar::searchRequests() const {
return _searchRequests.events();
}
void FixedBar::setAnimatingMode(bool enabled) { void FixedBar::setAnimatingMode(bool enabled) {
if (_animatingMode != enabled) { if (_animatingMode != enabled) {
_animatingMode = enabled; _animatingMode = enabled;
@ -266,9 +280,18 @@ Widget::Widget(
, _whatIsThis(this, tr::lng_admin_log_about(tr::now).toUpper(), st::historyComposeButton) { , _whatIsThis(this, tr::lng_admin_log_about(tr::now).toUpper(), st::historyComposeButton) {
_fixedBar->move(0, 0); _fixedBar->move(0, 0);
_fixedBar->resizeToWidth(width()); _fixedBar->resizeToWidth(width());
subscribe(_fixedBar->showFilterSignal, [this] { showFilter(); }); _fixedBar->showFilterRequests(
subscribe(_fixedBar->searchCancelledSignal, [this] { setInnerFocus(); }); ) | rpl::start_with_next([=] {
subscribe(_fixedBar->searchSignal, [this](const QString &query) { _inner->applySearch(query); }); showFilter();
}, lifetime());
_fixedBar->searchCancelRequests(
) | rpl::start_with_next([=] {
setInnerFocus();
}, lifetime());
_fixedBar->searchRequests(
) | rpl::start_with_next([=](const QString &query) {
_inner->applySearch(query);
}, lifetime());
_fixedBar->show(); _fixedBar->show();
_fixedBarShadow->raise(); _fixedBarShadow->raise();