Added initial ability to save and restore state for boosts info.
This commit is contained in:
parent
daf76c1bc2
commit
2ca489b2fb
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
|
||||
#include "api/api_statistics.h"
|
||||
#include "boxes/peers/edit_peer_invite_link.h"
|
||||
#include "info/boosts/info_boosts_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/statistics/info_statistics_list_controllers.h"
|
||||
#include "lang/lang_keys.h"
|
||||
|
@ -182,87 +183,108 @@ InnerWidget::InnerWidget(
|
|||
, _controller(controller)
|
||||
, _peer(peer)
|
||||
, _show(controller->uiShow()) {
|
||||
const auto api = lifetime().make_state<Api::Boosts>(peer);
|
||||
}
|
||||
|
||||
const auto fakeShowed = lifetime().make_state<rpl::event_stream<>>();
|
||||
void InnerWidget::load() {
|
||||
const auto api = lifetime().make_state<Api::Boosts>(_peer);
|
||||
|
||||
_showFinished.events(
|
||||
) | rpl::take(1) | rpl::start_with_next([=] {
|
||||
api->request(
|
||||
) | rpl::start_with_error_done([](const QString &error) {
|
||||
}, [=] {
|
||||
const auto status = api->boostStatus();
|
||||
const auto inner = this;
|
||||
|
||||
{
|
||||
auto dividerContent = object_ptr<Ui::VerticalLayout>(inner);
|
||||
Ui::FillBoostLimit(
|
||||
fakeShowed->events(),
|
||||
rpl::single(status.overview.isBoosted),
|
||||
dividerContent.data(),
|
||||
Ui::BoostBoxData{
|
||||
.boost = Ui::BoostCounters{
|
||||
.level = status.overview.level,
|
||||
.boosts = status.overview.boostCount,
|
||||
.thisLevelBoosts
|
||||
= status.overview.currentLevelBoostCount,
|
||||
.nextLevelBoosts
|
||||
= status.overview.nextLevelBoostCount,
|
||||
.mine = status.overview.isBoosted,
|
||||
}
|
||||
},
|
||||
st::statisticsLimitsLinePadding);
|
||||
inner->add(object_ptr<Ui::DividerLabel>(
|
||||
inner,
|
||||
std::move(dividerContent),
|
||||
st::statisticsLimitsDividerPadding));
|
||||
}
|
||||
|
||||
FillOverview(inner, status);
|
||||
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDivider(inner);
|
||||
::Settings::AddSkip(inner);
|
||||
|
||||
if (status.firstSlice.total > 0) {
|
||||
::Settings::AddSkip(inner);
|
||||
using PeerPtr = not_null<PeerData*>;
|
||||
const auto header = inner->add(
|
||||
object_ptr<Statistic::Header>(inner),
|
||||
st::statisticsLayerMargins
|
||||
+ st::boostsChartHeaderPadding);
|
||||
header->resizeToWidth(header->width());
|
||||
header->setTitle(tr::lng_boosts_list_title(
|
||||
tr::now,
|
||||
lt_count,
|
||||
status.firstSlice.total));
|
||||
header->setSubTitle({});
|
||||
Statistics::AddBoostsList(
|
||||
status.firstSlice,
|
||||
inner,
|
||||
[=](PeerPtr p) { controller->showPeerInfo(p); },
|
||||
peer,
|
||||
tr::lng_boosts_title());
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDividerText(
|
||||
inner,
|
||||
tr::lng_boosts_list_subtext());
|
||||
::Settings::AddSkip(inner);
|
||||
}
|
||||
|
||||
::Settings::AddSkip(inner);
|
||||
AddHeader(inner, tr::lng_boosts_link_title);
|
||||
::Settings::AddSkip(inner, st::boostsLinkSkip);
|
||||
FillShareLink(inner, _show, status.link, peer);
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDividerText(inner, tr::lng_boosts_link_subtext());
|
||||
|
||||
resizeToWidth(width());
|
||||
crl::on_main([=]{ fakeShowed->fire({}); });
|
||||
_state = api->boostStatus();
|
||||
fill();
|
||||
}, lifetime());
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void InnerWidget::fill() {
|
||||
const auto fakeShowed = lifetime().make_state<rpl::event_stream<>>();
|
||||
const auto &status = _state;
|
||||
const auto inner = this;
|
||||
|
||||
{
|
||||
auto dividerContent = object_ptr<Ui::VerticalLayout>(inner);
|
||||
Ui::FillBoostLimit(
|
||||
fakeShowed->events(),
|
||||
rpl::single(status.overview.isBoosted),
|
||||
dividerContent.data(),
|
||||
Ui::BoostBoxData{
|
||||
.boost = Ui::BoostCounters{
|
||||
.level = status.overview.level,
|
||||
.boosts = status.overview.boostCount,
|
||||
.thisLevelBoosts
|
||||
= status.overview.currentLevelBoostCount,
|
||||
.nextLevelBoosts
|
||||
= status.overview.nextLevelBoostCount,
|
||||
.mine = status.overview.isBoosted,
|
||||
}
|
||||
},
|
||||
st::statisticsLimitsLinePadding);
|
||||
inner->add(object_ptr<Ui::DividerLabel>(
|
||||
inner,
|
||||
std::move(dividerContent),
|
||||
st::statisticsLimitsDividerPadding));
|
||||
}
|
||||
|
||||
FillOverview(inner, status);
|
||||
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDivider(inner);
|
||||
::Settings::AddSkip(inner);
|
||||
|
||||
if (status.firstSlice.total > 0) {
|
||||
::Settings::AddSkip(inner);
|
||||
using PeerPtr = not_null<PeerData*>;
|
||||
const auto header = inner->add(
|
||||
object_ptr<Statistic::Header>(inner),
|
||||
st::statisticsLayerMargins
|
||||
+ st::boostsChartHeaderPadding);
|
||||
header->resizeToWidth(header->width());
|
||||
header->setTitle(tr::lng_boosts_list_title(
|
||||
tr::now,
|
||||
lt_count,
|
||||
status.firstSlice.total));
|
||||
header->setSubTitle({});
|
||||
Statistics::AddBoostsList(
|
||||
status.firstSlice,
|
||||
inner,
|
||||
[=](PeerPtr p) { _controller->showPeerInfo(p); },
|
||||
_peer,
|
||||
tr::lng_boosts_title());
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDividerText(
|
||||
inner,
|
||||
tr::lng_boosts_list_subtext());
|
||||
::Settings::AddSkip(inner);
|
||||
}
|
||||
|
||||
::Settings::AddSkip(inner);
|
||||
AddHeader(inner, tr::lng_boosts_link_title);
|
||||
::Settings::AddSkip(inner, st::boostsLinkSkip);
|
||||
FillShareLink(inner, _show, status.link, _peer);
|
||||
::Settings::AddSkip(inner);
|
||||
::Settings::AddDividerText(inner, tr::lng_boosts_link_subtext());
|
||||
|
||||
resizeToWidth(width());
|
||||
crl::on_main([=]{ fakeShowed->fire({}); });
|
||||
}
|
||||
|
||||
void InnerWidget::saveState(not_null<Memento*> memento) {
|
||||
memento->setState(base::take(_state));
|
||||
}
|
||||
|
||||
void InnerWidget::restoreState(not_null<Memento*> memento) {
|
||||
_state = memento->state();
|
||||
if (!_state.link.isEmpty()) {
|
||||
fill();
|
||||
} else {
|
||||
load();
|
||||
}
|
||||
Ui::RpWidget::resizeToWidth(width());
|
||||
}
|
||||
|
||||
rpl::producer<Ui::ScrollToRequest> InnerWidget::scrollToRequests() const {
|
||||
return _scrollToRequests.events();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "data/data_boosts.h"
|
||||
#include "ui/widgets/scroll_area.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
|
||||
|
@ -39,11 +40,19 @@ public:
|
|||
|
||||
void showFinished();
|
||||
|
||||
void saveState(not_null<Memento*> memento);
|
||||
void restoreState(not_null<Memento*> memento);
|
||||
|
||||
private:
|
||||
void load();
|
||||
void fill();
|
||||
|
||||
not_null<Controller*> _controller;
|
||||
not_null<PeerData*> _peer;
|
||||
std::shared_ptr<Ui::Show> _show;
|
||||
|
||||
Data::BoostStatus _state;
|
||||
|
||||
rpl::event_stream<Ui::ScrollToRequest> _scrollToRequests;
|
||||
rpl::event_stream<ShowRequest> _showRequests;
|
||||
rpl::event_stream<> _showFinished;
|
||||
|
|
|
@ -31,6 +31,14 @@ Section Memento::section() const {
|
|||
return Section(Section::Type::Boosts);
|
||||
}
|
||||
|
||||
void Memento::setState(SavedState state) {
|
||||
_state = std::move(state);
|
||||
}
|
||||
|
||||
Memento::SavedState Memento::state() {
|
||||
return base::take(_state);
|
||||
}
|
||||
|
||||
object_ptr<ContentWidget> Memento::createWidget(
|
||||
QWidget *parent,
|
||||
not_null<Controller*> controller,
|
||||
|
@ -75,7 +83,7 @@ void Widget::setInternalState(
|
|||
not_null<Memento*> memento) {
|
||||
setGeometry(geometry);
|
||||
Ui::SendPendingMoveResizeEvents(this);
|
||||
// restoreState(memento);
|
||||
restoreState(memento);
|
||||
}
|
||||
|
||||
rpl::producer<bool> Widget::desiredShadowVisibility() const {
|
||||
|
@ -88,10 +96,20 @@ void Widget::showFinished() {
|
|||
|
||||
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
|
||||
auto result = std::make_shared<Memento>(controller());
|
||||
// saveState(result.get());
|
||||
saveState(result.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
void Widget::saveState(not_null<Memento*> memento) {
|
||||
memento->setScrollTop(scrollTopSave());
|
||||
_inner->saveState(memento);
|
||||
}
|
||||
|
||||
void Widget::restoreState(not_null<Memento*> memento) {
|
||||
_inner->restoreState(memento);
|
||||
scrollTopRestore(memento->scrollTop());
|
||||
}
|
||||
|
||||
std::shared_ptr<Info::Memento> Make(not_null<PeerData*> peer) {
|
||||
return std::make_shared<Info::Memento>(
|
||||
std::vector<std::shared_ptr<ContentMemento>>(
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#pragma once
|
||||
|
||||
#include "data/data_boosts.h"
|
||||
#include "info/info_content_widget.h"
|
||||
|
||||
namespace Info::Boosts {
|
||||
|
@ -26,6 +27,14 @@ public:
|
|||
|
||||
Section section() const override;
|
||||
|
||||
using SavedState = Data::BoostStatus;
|
||||
|
||||
void setState(SavedState states);
|
||||
[[nodiscard]] SavedState state();
|
||||
|
||||
private:
|
||||
SavedState _state;
|
||||
|
||||
};
|
||||
|
||||
class Widget final : public ContentWidget {
|
||||
|
|
Loading…
Reference in New Issue