Simplify Info::Profile::Cover code, remove toggling.

This commit is contained in:
John Preston 2022-05-30 17:09:36 +04:00
parent b7259615a7
commit 8ca2f6a444
5 changed files with 6 additions and 134 deletions

View File

@ -163,66 +163,6 @@ auto ChatStatusText(int fullCount, int onlineCount, bool isGroup) {
} // namespace
SectionWithToggle *SectionWithToggle::setToggleShown(
rpl::producer<bool> &&shown) {
_toggle.create(
this,
QString(),
st::infoToggleCheckbox,
std::make_unique<SectionToggle>(
st::infoToggle,
false,
[this] { _toggle->updateCheck(); }));
_toggle->hide();
_toggle->lower();
_toggle->setCheckAlignment(style::al_right);
widthValue(
) | rpl::start_with_next([this](int newValue) {
_toggle->setGeometry(0, 0, newValue, height());
}, _toggle->lifetime());
std::move(
shown
) | rpl::start_with_next([this](bool shown) {
if (_toggle->isHidden() == shown) {
_toggle->setVisible(shown);
_toggleShown.fire_copy(shown);
}
}, lifetime());
return this;
}
void SectionWithToggle::toggle(bool toggled, anim::type animated) {
if (_toggle) {
_toggle->setChecked(toggled);
if (animated == anim::type::instant) {
_toggle->finishAnimating();
}
}
}
bool SectionWithToggle::toggled() const {
return _toggle ? _toggle->checked() : false;
}
rpl::producer<bool> SectionWithToggle::toggledValue() const {
if (_toggle) {
return _toggle->checkedValue();
}
return nullptr;
}
rpl::producer<bool> SectionWithToggle::toggleShownValue() const {
return _toggleShown.events_starting_with(
_toggle && !_toggle->isHidden());
}
int SectionWithToggle::toggleSkip() const {
return (!_toggle || _toggle->isHidden())
? 0
: st::infoToggleCheckbox.checkPosition.x()
+ _toggle->checkRect().width();
}
Cover::Cover(
QWidget *parent,
not_null<PeerData*> peer,
@ -239,7 +179,7 @@ Cover::Cover(
not_null<PeerData*> peer,
not_null<Window::SessionController*> controller,
rpl::producer<QString> title)
: SectionWithToggle(
: FixedHeightWidget(
parent,
st::infoProfilePhotoTop
+ st::infoProfilePhoto.size.height()
@ -279,11 +219,7 @@ Cover::Cover(
}
void Cover::setupChildGeometry() {
using namespace rpl::mappers;
rpl::combine(
toggleShownValue(),
widthValue(),
_2
widthValue(
) | rpl::start_with_next([this](int newWidth) {
_userpic->moveToLeft(
st::infoProfilePhotoLeft,
@ -451,8 +387,7 @@ void Cover::refreshNameGeometry(int newWidth) {
auto nameTop = st::infoProfileNameTop;
auto nameWidth = newWidth
- nameLeft
- st::infoProfileNameRight
- toggleSkip();
- st::infoProfileNameRight;
if (_verifiedCheck) {
nameWidth -= st::infoVerifiedCheckPosition.x()
+ _verifiedCheck->width();
@ -484,8 +419,7 @@ void Cover::refreshNameGeometry(int newWidth) {
void Cover::refreshStatusGeometry(int newWidth) {
auto statusWidth = newWidth
- st::infoProfileStatusLeft
- st::infoProfileStatusRight
- toggleSkip();
- st::infoProfileStatusRight;
_status->resizeToWidth(statusWidth);
_status->moveToLeft(
st::infoProfileStatusLeft,

View File

@ -36,26 +36,7 @@ namespace Profile {
enum class Badge;
class SectionWithToggle : public Ui::FixedHeightWidget {
public:
using FixedHeightWidget::FixedHeightWidget;
SectionWithToggle *setToggleShown(rpl::producer<bool> &&shown);
void toggle(bool toggled, anim::type animated);
bool toggled() const;
rpl::producer<bool> toggledValue() const;
protected:
rpl::producer<bool> toggleShownValue() const;
int toggleSkip() const;
private:
object_ptr<Ui::Checkbox> _toggle = { nullptr };
rpl::event_stream<bool> _toggleShown;
};
class Cover : public SectionWithToggle {
class Cover : public Ui::FixedHeightWidget {
public:
Cover(
QWidget *parent,
@ -69,11 +50,6 @@ public:
Cover *setOnlineCount(rpl::producer<int> &&count);
Cover *setToggleShown(rpl::producer<bool> &&shown) {
return static_cast<Cover*>(
SectionWithToggle::setToggleShown(std::move(shown)));
}
rpl::producer<Section> showSection() const {
return _showSection.events();
}

View File

@ -61,16 +61,6 @@ InnerWidget::InnerWidget(
}, lifetime());
}
bool InnerWidget::canHideDetailsEver() const {
return false;// (_peer->isChat() || _peer->isMegagroup());
}
rpl::producer<bool> InnerWidget::canHideDetails() const {
using namespace rpl::mappers;
return MembersCountValue(_peer)
| rpl::map(_1 > 0);
}
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
not_null<RpWidget*> parent) {
auto result = object_ptr<Ui::VerticalLayout>(parent);
@ -85,19 +75,7 @@ object_ptr<Ui::RpWidget> InnerWidget::setupContent(
}, _cover->lifetime());
_cover->setOnlineCount(rpl::single(0));
auto details = SetupDetails(_controller, parent, _peer);
if (canHideDetailsEver()) {
_cover->setToggleShown(canHideDetails());
_infoWrap = result->add(object_ptr<Ui::SlideWrap<>>(
result,
std::move(details))
)->setDuration(
st::infoSlideDuration
)->toggleOn(
_cover->toggledValue()
);
} else {
result->add(std::move(details));
}
result->add(std::move(details));
result->add(setupSharedMedia(result.data()));
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
result->add(std::move(members));
@ -244,20 +222,15 @@ void InnerWidget::visibleTopBottomUpdated(
}
void InnerWidget::saveState(not_null<Memento*> memento) {
memento->setInfoExpanded(_cover->toggled());
if (_members) {
memento->setMembersState(_members->saveState());
}
}
void InnerWidget::restoreState(not_null<Memento*> memento) {
_cover->toggle(memento->infoExpanded(), anim::type::instant);
if (_members) {
_members->restoreState(memento->membersState());
}
if (_infoWrap) {
_infoWrap->finishAnimating();
}
if (_sharedMediaWrap) {
_sharedMediaWrap->finishAnimating();
}

View File

@ -62,16 +62,12 @@ private:
_desiredHeight.fire(countDesiredHeight());
}
bool canHideDetailsEver() const;
rpl::producer<bool> canHideDetails() const;
const not_null<Controller*> _controller;
const not_null<PeerData*> _peer;
PeerData * const _migrated = nullptr;
Members *_members = nullptr;
Cover *_cover = nullptr;
Ui::SlideWrap<RpWidget> *_infoWrap = nullptr;
Ui::SlideWrap<RpWidget> *_sharedMediaWrap = nullptr;
object_ptr<RpWidget> _content;

View File

@ -28,19 +28,12 @@ public:
Section section() const override;
void setInfoExpanded(bool expanded) {
_infoExpanded = expanded;
}
bool infoExpanded() const {
return _infoExpanded;
}
void setMembersState(std::unique_ptr<MembersState> state);
std::unique_ptr<MembersState> membersState();
~Memento();
private:
bool _infoExpanded = true;
std::unique_ptr<MembersState> _membersState;
};