mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to load chunked history transactions in earn info section.
This commit is contained in:
parent
2f07bb3973
commit
496247c1d8
4 changed files with 95 additions and 24 deletions
|
@ -4995,6 +4995,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
"lng_channel_earn_history_return" = "Refund";
|
"lng_channel_earn_history_return" = "Refund";
|
||||||
"lng_channel_earn_history_return_about" = "Refunded back";
|
"lng_channel_earn_history_return_about" = "Refunded back";
|
||||||
"lng_channel_earn_history_pending" = "Pending";
|
"lng_channel_earn_history_pending" = "Pending";
|
||||||
|
"lng_channel_earn_history_show_more#one" = "Show {count} More Transaction";
|
||||||
|
"lng_channel_earn_history_show_more#other" = "Show {count} More Transactions";
|
||||||
"lng_channel_earn_off" = "Switch Off Ads";
|
"lng_channel_earn_off" = "Switch Off Ads";
|
||||||
"lng_channel_earn_off_about" = "You will not be eligible for any rewards if you switch off ads.";
|
"lng_channel_earn_off_about" = "You will not be eligible for any rewards if you switch off ads.";
|
||||||
"lng_channel_earn_cpm_min" = "No Ads";
|
"lng_channel_earn_cpm_min" = "No Ads";
|
||||||
|
|
|
@ -771,7 +771,7 @@ rpl::producer<rpl::no_value, QString> EarnStatistics::request() {
|
||||||
.usdRate = data.vusd_rate().v,
|
.usdRate = data.vusd_rate().v,
|
||||||
};
|
};
|
||||||
|
|
||||||
requestBoosts({}, [=](Data::EarnHistorySlice &&slice) {
|
requestHistory({}, [=](Data::EarnHistorySlice &&slice) {
|
||||||
_data.firstHistorySlice = std::move(slice);
|
_data.firstHistorySlice = std::move(slice);
|
||||||
|
|
||||||
api().request(
|
api().request(
|
||||||
|
@ -795,7 +795,7 @@ rpl::producer<rpl::no_value, QString> EarnStatistics::request() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void EarnStatistics::requestBoosts(
|
void EarnStatistics::requestHistory(
|
||||||
const Data::EarnHistorySlice::OffsetToken &token,
|
const Data::EarnHistorySlice::OffsetToken &token,
|
||||||
Fn<void(Data::EarnHistorySlice)> done) {
|
Fn<void(Data::EarnHistorySlice)> done) {
|
||||||
if (_requestId) {
|
if (_requestId) {
|
||||||
|
@ -831,11 +831,9 @@ void EarnStatistics::requestBoosts(
|
||||||
: d.is_failed()
|
: d.is_failed()
|
||||||
? Data::EarnHistoryEntry::Status::Failed
|
? Data::EarnHistoryEntry::Status::Failed
|
||||||
: Data::EarnHistoryEntry::Status::Success,
|
: Data::EarnHistoryEntry::Status::Success,
|
||||||
.amount = d.is_failed()
|
.amount = (std::numeric_limits<Data::EarnInt>::max()
|
||||||
? (std::numeric_limits<Data::EarnInt>::max()
|
- d.vamount().v
|
||||||
- d.vamount().v
|
+ 1),
|
||||||
+ 1)
|
|
||||||
: d.vamount().v,
|
|
||||||
.date = base::unixtime::parse(d.vdate().v),
|
.date = base::unixtime::parse(d.vdate().v),
|
||||||
// .provider = qs(d.vprovider()),
|
// .provider = qs(d.vprovider()),
|
||||||
.successDate = d.vtransaction_date()
|
.successDate = d.vtransaction_date()
|
||||||
|
|
|
@ -113,14 +113,14 @@ public:
|
||||||
explicit EarnStatistics(not_null<ChannelData*> channel);
|
explicit EarnStatistics(not_null<ChannelData*> channel);
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
[[nodiscard]] rpl::producer<rpl::no_value, QString> request();
|
||||||
void requestBoosts(
|
void requestHistory(
|
||||||
const Data::EarnHistorySlice::OffsetToken &token,
|
const Data::EarnHistorySlice::OffsetToken &token,
|
||||||
Fn<void(Data::EarnHistorySlice)> done);
|
Fn<void(Data::EarnHistorySlice)> done);
|
||||||
|
|
||||||
[[nodiscard]] Data::EarnStatistics data() const;
|
[[nodiscard]] Data::EarnStatistics data() const;
|
||||||
|
|
||||||
static constexpr auto kFirstSlice = int(10);
|
static constexpr auto kFirstSlice = int(5);
|
||||||
static constexpr auto kLimit = int(40);
|
static constexpr auto kLimit = int(10);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Data::EarnStatistics _data;
|
Data::EarnStatistics _data;
|
||||||
|
|
|
@ -31,14 +31,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/controls/userpic_button.h"
|
#include "ui/controls/userpic_button.h"
|
||||||
#include "ui/effects/animation_value_f.h"
|
#include "ui/effects/animation_value_f.h"
|
||||||
#include "ui/effects/fade_animation.h"
|
#include "ui/effects/fade_animation.h"
|
||||||
|
#include "ui/effects/toggle_arrow.h"
|
||||||
#include "ui/layers/generic_box.h"
|
#include "ui/layers/generic_box.h"
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/vertical_list.h"
|
#include "ui/vertical_list.h"
|
||||||
#include "ui/widgets/continuous_sliders.h"
|
#include "ui/widgets/continuous_sliders.h"
|
||||||
#include "main/main_account.h"
|
|
||||||
#include "main/main_app_config.h"
|
|
||||||
#include "ui/widgets/fields/input_field.h"
|
#include "ui/widgets/fields/input_field.h"
|
||||||
#include "ui/wrap/slide_wrap.h"
|
#include "ui/wrap/slide_wrap.h"
|
||||||
#include "styles/style_boxes.h"
|
#include "styles/style_boxes.h"
|
||||||
|
@ -48,6 +47,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_settings.h"
|
#include "styles/style_settings.h"
|
||||||
#include "styles/style_statistics.h"
|
#include "styles/style_statistics.h"
|
||||||
|
#include "styles/style_window.h" // mainMenuToggleFourStrokes.
|
||||||
|
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
|
@ -105,6 +105,27 @@ constexpr auto kDot = QChar('.');
|
||||||
return session->appConfig().get<bool>(key, false);
|
return session->appConfig().get<bool>(key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddArrow(not_null<Ui::RpWidget*> parent) {
|
||||||
|
const auto arrow = Ui::CreateChild<Ui::RpWidget>(parent.get());
|
||||||
|
arrow->paintRequest(
|
||||||
|
) | rpl::start_with_next([=](const QRect &r) {
|
||||||
|
auto p = QPainter(arrow);
|
||||||
|
|
||||||
|
const auto path = Ui::ToggleUpDownArrowPath(
|
||||||
|
st::statisticsShowMoreButtonArrowSize,
|
||||||
|
st::statisticsShowMoreButtonArrowSize,
|
||||||
|
st::statisticsShowMoreButtonArrowSize,
|
||||||
|
st::mainMenuToggleFourStrokes,
|
||||||
|
0.);
|
||||||
|
|
||||||
|
auto hq = PainterHighQualityEnabler(p);
|
||||||
|
p.fillPath(path, st::lightButtonFg);
|
||||||
|
}, arrow->lifetime());
|
||||||
|
arrow->resize(Size(st::statisticsShowMoreButtonArrowSize * 2));
|
||||||
|
arrow->move(st::statisticsShowMoreButtonArrowPosition);
|
||||||
|
arrow->show();
|
||||||
|
}
|
||||||
|
|
||||||
void AddHeader(
|
void AddHeader(
|
||||||
not_null<Ui::VerticalLayout*> content,
|
not_null<Ui::VerticalLayout*> content,
|
||||||
tr::phrase<> text) {
|
tr::phrase<> text) {
|
||||||
|
@ -625,13 +646,15 @@ void InnerWidget::fill() {
|
||||||
AddHeader(container, tr::lng_channel_earn_history_title);
|
AddHeader(container, tr::lng_channel_earn_history_title);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
|
|
||||||
const auto addHistoryEntry = [&](
|
const auto historyList = container->add(
|
||||||
|
object_ptr<Ui::VerticalLayout>(container));
|
||||||
|
const auto addHistoryEntry = [=](
|
||||||
const Data::EarnHistoryEntry &entry,
|
const Data::EarnHistoryEntry &entry,
|
||||||
const tr::phrase<> &text) {
|
const tr::phrase<> &text) {
|
||||||
const auto wrap = container->add(
|
const auto wrap = historyList->add(
|
||||||
object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
|
object_ptr<Ui::PaddingWrap<Ui::VerticalLayout>>(
|
||||||
container,
|
historyList,
|
||||||
object_ptr<Ui::VerticalLayout>(container),
|
object_ptr<Ui::VerticalLayout>(historyList),
|
||||||
QMargins()));
|
QMargins()));
|
||||||
const auto inner = wrap->entity();
|
const auto inner = wrap->entity();
|
||||||
inner->setAttribute(Qt::WA_TransparentForMouseEvents);
|
inner->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
|
@ -847,14 +870,62 @@ void InnerWidget::fill() {
|
||||||
button->lower();
|
button->lower();
|
||||||
}, wrap->lifetime());
|
}, wrap->lifetime());
|
||||||
};
|
};
|
||||||
for (const auto &entry : data.firstHistorySlice.list) {
|
const auto handleSlice = [=](const Data::EarnHistorySlice &slice) {
|
||||||
addHistoryEntry(
|
for (const auto &entry : slice.list) {
|
||||||
entry,
|
addHistoryEntry(
|
||||||
(entry.type == Data::EarnHistoryEntry::Type::In)
|
entry,
|
||||||
? tr::lng_channel_earn_history_in
|
(entry.type == Data::EarnHistoryEntry::Type::In)
|
||||||
: (entry.type == Data::EarnHistoryEntry::Type::Return)
|
? tr::lng_channel_earn_history_in
|
||||||
? tr::lng_channel_earn_history_return
|
: (entry.type == Data::EarnHistoryEntry::Type::Return)
|
||||||
: tr::lng_channel_earn_history_out);
|
? tr::lng_channel_earn_history_return
|
||||||
|
: tr::lng_channel_earn_history_out);
|
||||||
|
}
|
||||||
|
historyList->resizeToWidth(container->width());
|
||||||
|
};
|
||||||
|
handleSlice(data.firstHistorySlice);
|
||||||
|
if (!data.firstHistorySlice.allLoaded) {
|
||||||
|
struct ShowMoreState final {
|
||||||
|
ShowMoreState(not_null<ChannelData*> channel)
|
||||||
|
: api(channel) {
|
||||||
|
}
|
||||||
|
Api::EarnStatistics api;
|
||||||
|
bool loading = false;
|
||||||
|
Data::EarnHistorySlice::OffsetToken token;
|
||||||
|
rpl::variable<int> showed = 0;
|
||||||
|
};
|
||||||
|
const auto state = lifetime().make_state<ShowMoreState>(channel);
|
||||||
|
state->token = data.firstHistorySlice.token;
|
||||||
|
state->showed = data.firstHistorySlice.list.size();
|
||||||
|
const auto max = data.firstHistorySlice.total;
|
||||||
|
const auto wrap = container->add(
|
||||||
|
object_ptr<Ui::SlideWrap<Ui::SettingsButton>>(
|
||||||
|
container,
|
||||||
|
object_ptr<Ui::SettingsButton>(
|
||||||
|
container,
|
||||||
|
tr::lng_channel_earn_history_show_more(
|
||||||
|
lt_count,
|
||||||
|
state->showed.value(
|
||||||
|
) | rpl::map(
|
||||||
|
max - rpl::mappers::_1
|
||||||
|
) | tr::to_count()),
|
||||||
|
st::statisticsShowMoreButton)));
|
||||||
|
const auto button = wrap->entity();
|
||||||
|
AddArrow(button);
|
||||||
|
|
||||||
|
wrap->toggle(true, anim::type::instant);
|
||||||
|
const auto handleReceived = [=](Data::EarnHistorySlice slice) {
|
||||||
|
state->loading = false;
|
||||||
|
handleSlice(slice);
|
||||||
|
wrap->toggle(!slice.allLoaded, anim::type::instant);
|
||||||
|
state->token = slice.token;
|
||||||
|
state->showed = state->showed.current() + slice.list.size();
|
||||||
|
};
|
||||||
|
button->setClickedCallback([=] {
|
||||||
|
if (!state->loading) {
|
||||||
|
state->loading = true;
|
||||||
|
state->api.requestHistory(state->token, handleReceived);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
|
|
Loading…
Add table
Reference in a new issue