Added credits oveview to section of channel earn.

This commit is contained in:
23rd 2024-06-22 05:47:38 +03:00 committed by John Preston
parent 68bf6f991c
commit c6e322de86

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/boxes/boost_box.h" #include "ui/boxes/boost_box.h"
#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/credits_graphics.h"
#include "ui/effects/toggle_arrow.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"
@ -277,7 +278,11 @@ void InnerWidget::load() {
) | rpl::start_with_error_done(fail, [=] { ) | rpl::start_with_error_done(fail, [=] {
_state.currencyEarn = api->data(); _state.currencyEarn = api->data();
apiCredits->request( apiCredits->request(
) | rpl::start_with_error_done(fail, [=] { ) | rpl::start_with_error_done([=](const QString &error) {
fail(error);
_loaded.fire(true);
fill();
}, [=] {
_state.creditsEarn = apiCredits->data(); _state.creditsEarn = apiCredits->data();
_loaded.fire(true); _loaded.fire(true);
fill(); fill();
@ -576,6 +581,7 @@ void InnerWidget::fill() {
const auto addOverview = [&]( const auto addOverview = [&](
EarnInt value, EarnInt value,
EarnInt credits,
const tr::phrase<> &text) { const tr::phrase<> &text) {
const auto line = container->add( const auto line = container->add(
Ui::CreateSkipWidget(container, 0), Ui::CreateSkipWidget(container, 0),
@ -592,21 +598,56 @@ void InnerWidget::fill() {
line, line,
value ? ToUsd(value, multiplier) : QString(), value ? ToUsd(value, multiplier) : QString(),
st::channelEarnOverviewSubMinorLabel); st::channelEarnOverviewSubMinorLabel);
const auto creditsLabel = Ui::CreateChild<Ui::FlatLabel>(
line,
QString::number(credits),
st::channelEarnOverviewMajorLabel);
const auto icon = Ui::CreateSingleStarWidget(
line,
creditsLabel->height());
const auto creditsMultiplies = creditsData.usdRate
* Data::kEarnMultiplier;
const auto creditsSecondLabel = Ui::CreateChild<Ui::FlatLabel>(
line,
credits ? ToUsd(credits, creditsMultiplies) : QString(),
st::channelEarnOverviewSubMinorLabel);
rpl::combine( rpl::combine(
line->widthValue(), line->widthValue(),
majorLabel->sizeValue() majorLabel->sizeValue(),
) | rpl::start_with_next([=](int available, const QSize &size) { creditsLabel->sizeValue()
) | rpl::start_with_next([=](
int available,
const QSize &size,
const QSize &creditsSize) {
const auto skip = st::channelEarnOverviewSubMinorLabelPos.x();
line->resize(line->width(), size.height()); line->resize(line->width(), size.height());
minorLabel->moveToLeft( minorLabel->moveToLeft(
size.width(), size.width(),
st::channelEarnOverviewMinorLabelSkip); st::channelEarnOverviewMinorLabelSkip);
secondMinorLabel->resizeToWidth(available secondMinorLabel->resizeToWidth(
- size.width() (credits ? (available / 2) : available)
- minorLabel->width()); - size.width()
- minorLabel->width());
secondMinorLabel->moveToLeft( secondMinorLabel->moveToLeft(
rect::right(minorLabel) rect::right(minorLabel) + skip,
+ st::channelEarnOverviewSubMinorLabelPos.x(),
st::channelEarnOverviewSubMinorLabelPos.y()); st::channelEarnOverviewSubMinorLabelPos.y());
icon->moveToLeft(
available / 2 + st::boxRowPadding.left() / 2,
0);
creditsLabel->moveToLeft(rect::right(icon) + skip, 0);
creditsSecondLabel->moveToLeft(
rect::right(creditsLabel) + skip,
st::channelEarnOverviewSubMinorLabelPos.y());
creditsSecondLabel->resizeToWidth(
available - creditsSecondLabel->pos().x());
if (!credits) {
const auto x = std::numeric_limits<int>::max();
icon->moveToLeft(x, 0);
creditsLabel->moveToLeft(x, 0);
creditsSecondLabel->moveToLeft(x, 0);
}
}, minorLabel->lifetime()); }, minorLabel->lifetime());
Ui::ToggleChildrenVisibility(line, true); Ui::ToggleChildrenVisibility(line, true);
@ -619,13 +660,22 @@ void InnerWidget::fill() {
st::boxRowPadding); st::boxRowPadding);
sub->setTextColorOverride(st::windowSubTextFg->c); sub->setTextColorOverride(st::windowSubTextFg->c);
}; };
addOverview(data.availableBalance, tr::lng_channel_earn_available); addOverview(
data.availableBalance,
creditsData.availableBalance,
tr::lng_channel_earn_available);
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddSkip(container); Ui::AddSkip(container);
addOverview(data.currentBalance, tr::lng_channel_earn_reward); addOverview(
data.currentBalance,
creditsData.currentBalance,
tr::lng_channel_earn_reward);
Ui::AddSkip(container); Ui::AddSkip(container);
Ui::AddSkip(container); Ui::AddSkip(container);
addOverview(data.overallRevenue, tr::lng_channel_earn_total); addOverview(
data.overallRevenue,
creditsData.overallRevenue,
tr::lng_channel_earn_total);
Ui::AddSkip(container); Ui::AddSkip(container);
} }
#ifndef _DEBUG #ifndef _DEBUG