Replaced icon with custom emoji in list of credits history entries.

This commit is contained in:
23rd 2024-08-09 23:20:33 +03:00 committed by John Preston
parent 70d5dd8b71
commit f2f85a9083
5 changed files with 30 additions and 49 deletions

View file

@ -361,16 +361,12 @@ void InnerWidget::fillHistory() {
e));
};
const auto star = lifetime().make_state<QImage>(
Ui::GenerateStars(st::creditsTopupButton.height, 1));
Info::Statistics::AddCreditsHistoryList(
controller->uiShow(),
fullSlice,
fullWrap->entity(),
entryClicked,
peer,
star,
true,
true);
Info::Statistics::AddCreditsHistoryList(
@ -379,7 +375,6 @@ void InnerWidget::fillHistory() {
inWrap->entity(),
entryClicked,
peer,
star,
true,
false);
Info::Statistics::AddCreditsHistoryList(
@ -388,7 +383,6 @@ void InnerWidget::fillHistory() {
outWrap->entity(),
std::move(entryClicked),
peer,
star,
false,
true);

View file

@ -1412,16 +1412,12 @@ void InnerWidget::fill() {
e));
};
const auto star = tabCreditsList->lifetime().make_state<QImage>(
Ui::GenerateStars(st::creditsTopupButton.height, 1));
Info::Statistics::AddCreditsHistoryList(
show,
data.creditsStatusSlice,
tabCreditsList->entity(),
entryClicked,
_peer,
star,
true,
true);
}

View file

@ -135,7 +135,6 @@ struct CreditsDescriptor final {
Data::CreditsStatusSlice firstSlice;
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback;
not_null<PeerData*> peer;
not_null<QImage*> creditIcon;
bool in = false;
bool out = false;
};
@ -724,7 +723,7 @@ public:
struct Descriptor final {
Data::CreditsHistoryEntry entry;
Data::SubscriptionEntry subscription;
not_null<QImage*> creditIcon;
Core::MarkedTextContext context;
int rowHeight = 0;
Fn<void(not_null<PeerListRow*>)> updateCallback;
};
@ -755,7 +754,7 @@ private:
const Data::CreditsHistoryEntry _entry;
const Data::SubscriptionEntry _subscription;
not_null<QImage*> const _creditIcon;
const Core::MarkedTextContext _context;
const int _rowHeight;
PaintRoundImageCallback _paintUserpicCallback;
@ -773,7 +772,7 @@ CreditsRow::CreditsRow(
: PeerListRow(peer, UniqueRowIdFromEntry(descriptor.entry))
, _entry(descriptor.entry)
, _subscription(descriptor.subscription)
, _creditIcon(descriptor.creditIcon)
, _context(descriptor.context)
, _rowHeight(descriptor.rowHeight) {
const auto callback = Ui::PaintPreviewCallback(
&peer->session(),
@ -790,7 +789,7 @@ CreditsRow::CreditsRow(const Descriptor &descriptor)
: PeerListRow(UniqueRowIdFromEntry(descriptor.entry))
, _entry(descriptor.entry)
, _subscription(descriptor.subscription)
, _creditIcon(descriptor.creditIcon)
, _context(descriptor.context)
, _rowHeight(descriptor.rowHeight) {
init();
}
@ -831,23 +830,27 @@ void CreditsRow::init() {
lt_date,
langDayOfMonthFull(_subscription.until.date())));
}
auto &manager = _context.session->data().customEmojiManager();
if (_entry) {
constexpr auto kMinus = QChar(0x2212);
_rightText.setText(
_rightText.setMarkedText(
st::semiboldTextStyle,
(_entry.in ? QChar('+') : kMinus)
+ Lang::FormatCountDecimal(std::abs(int64(_entry.credits))));
TextWithEntities()
.append(_entry.in ? QChar('+') : kMinus)
.append(
Lang::FormatCountDecimal(std::abs(int64(_entry.credits))))
.append(QChar(' '))
.append(manager.creditsEmoji()),
kMarkupTextOptions,
_context);
} else if (_subscription.subscription.credits && !isSpecial) {
const auto peer = PeerListRow::peer();
_rightText.setMarkedText(
st::semiboldTextStyle,
peer->owner().customEmojiManager().creditsEmoji().append(
manager.creditsEmoji().append(
Lang::FormatCountDecimal(_subscription.subscription.credits)),
kMarkupTextOptions,
Core::MarkedTextContext{
.session = &peer->session(),
.customEmojiRepaint = [] {},
});
_context);
}
if (!_paintUserpicCallback) {
_paintUserpicCallback = !isSpecial
@ -880,19 +883,14 @@ QSize CreditsRow::rightActionSize() const {
return QSize(
st::contactsStatusFont->width(text) + st::boxRowPadding.right(),
_rowHeight);
} else if (_subscription) {
} else if (_subscription || _entry) {
return QSize(
_rightText.maxWidth() + st::boxRowPadding.right(),
_rowHeight);
} else if (!_entry && !_subscription) {
return QSize();
}
return QSize(
_rightText.maxWidth()
+ (_creditIcon->width() / style::DevicePixelRatio())
+ st::creditsHistoryRightSkip
+ _rightText.style()->font->spacew * 2,
_rowHeight);
return QSize();
}
QMargins CreditsRow::rightActionMargins() const {
@ -911,12 +909,12 @@ void CreditsRow::rightActionPaint(
bool selected,
bool actionSelected) {
const auto &font = _rightText.style()->font;
const auto rightSkip = st::boxRowPadding.right();
if (_subscription) {
const auto &statusFont = st::contactsStatusFont;
const auto &st = st::boostsListBox.item;
const auto textHeight = font->height + statusFont->height;
const auto skip = (_rowHeight - textHeight) / 2;
const auto rightSkip = st::boxRowPadding.right();
if (_subscription.cancelled || _subscription.expired) {
y += _rowHeight / 2;
p.setFont(statusFont);
@ -955,17 +953,13 @@ void CreditsRow::rightActionPaint(
: _entry.in
? st::boxTextFgGood
: st::menuIconAttentionColor);
x += st::creditsHistoryRightSkip;
_rightText.draw(p, Ui::Text::PaintContext{
.position = QPoint(x, y - font->height / 2),
.position = QPoint(
outerWidth - _rightText.maxWidth() - rightSkip,
y - font->height / 2),
.outerWidth = outerWidth,
.availableWidth = outerWidth,
});
x += _rightText.maxWidth() + font->spacew * 2;
p.drawImage(
x,
y -(_creditIcon->height() / style::DevicePixelRatio()) / 2,
*_creditIcon);
}
class CreditsController final : public PeerListController {
@ -987,11 +981,11 @@ private:
const not_null<Main::Session*> _session;
Fn<void(const Data::CreditsHistoryEntry &)> _entryClickedCallback;
not_null<QImage*> const _creditIcon;
Api::CreditsHistory _api;
Data::CreditsStatusSlice _firstSlice;
Data::CreditsStatusSlice::OffsetToken _apiToken;
Core::MarkedTextContext _context;
rpl::variable<bool> _allLoaded = false;
bool _requesting = false;
@ -1001,9 +995,12 @@ private:
CreditsController::CreditsController(CreditsDescriptor d)
: _session(&d.peer->session())
, _entryClickedCallback(std::move(d.entryClickedCallback))
, _creditIcon(d.creditIcon)
, _api(d.peer, d.in, d.out)
, _firstSlice(std::move(d.firstSlice)) {
, _firstSlice(std::move(d.firstSlice))
, _context(Core::MarkedTextContext{
.session = _session,
.customEmojiRepaint = [] {},
}) {
PeerListController::setStyleOverrides(&st::boostsListBox);
}
@ -1045,7 +1042,7 @@ void CreditsController::applySlice(const Data::CreditsStatusSlice &slice) {
const auto descriptor = CreditsRow::Descriptor{
.entry = i,
.subscription = s,
.creditIcon = _creditIcon,
.context = _context,
.rowHeight = computeListSt().item.height,
.updateCallback = [=](not_null<PeerListRow*> row) {
delegate()->peerListUpdateRow(row);
@ -1235,7 +1232,6 @@ void AddCreditsHistoryList(
not_null<Ui::VerticalLayout*> container,
Fn<void(const Data::CreditsHistoryEntry &)> callback,
not_null<PeerData*> bot,
not_null<QImage*> icon,
bool in,
bool out) {
struct State final {
@ -1249,7 +1245,7 @@ void AddCreditsHistoryList(
CreditsController controller;
};
const auto state = container->lifetime().make_state<State>(
CreditsDescriptor{ firstSlice, callback, bot, icon, in, out },
CreditsDescriptor{ firstSlice, callback, bot, in, out },
show);
state->delegate.setContent(container->add(

View file

@ -56,7 +56,6 @@ void AddCreditsHistoryList(
not_null<Ui::VerticalLayout*> container,
Fn<void(const Data::CreditsHistoryEntry &)> entryClickedCallback,
not_null<PeerData*> peer,
not_null<QImage*> creditIcon,
bool in,
bool out);

View file

@ -164,7 +164,6 @@ void Credits::setupSubscriptions(not_null<Ui::VerticalLayout*> container) {
fullWrap->entity(),
entryClicked,
self,
&_star,
true,
true);
@ -296,7 +295,6 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
fullWrap->entity(),
entryClicked,
self,
&_star,
true,
true);
Info::Statistics::AddCreditsHistoryList(
@ -305,7 +303,6 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
inWrap->entity(),
entryClicked,
self,
&_star,
true,
false);
Info::Statistics::AddCreditsHistoryList(
@ -314,7 +311,6 @@ void Credits::setupHistory(not_null<Ui::VerticalLayout*> container) {
outWrap->entity(),
std::move(entryClicked),
self,
&_star,
false,
true);