mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Improve giveaway prices display.
This commit is contained in:
@@ -56,6 +56,9 @@ namespace {
|
||||
+ QChar(0x00D7)
|
||||
+ ' '
|
||||
+ QString::number(tlOption.vusers().v);
|
||||
options[i].total = Ui::FillAmountAndCurrency(
|
||||
tlOption.vamount().v,
|
||||
currency);
|
||||
options[i].currency = currency;
|
||||
}
|
||||
return options;
|
||||
|
||||
@@ -15,29 +15,33 @@ constexpr auto kDiscountDivider = 1.;
|
||||
|
||||
Data::PremiumSubscriptionOption CreateSubscriptionOption(
|
||||
int months,
|
||||
int monthlyAmount,
|
||||
float64 monthlyAmount,
|
||||
int64 amount,
|
||||
const QString ¤cy,
|
||||
const QString &botUrl) {
|
||||
const auto baselineAmount = monthlyAmount * months;
|
||||
const auto discount = [&] {
|
||||
const auto percent = 1. - float64(amount) / (monthlyAmount * months);
|
||||
return std::round(percent * 100. / kDiscountDivider)
|
||||
const auto percent = 1. - float64(amount) / baselineAmount;
|
||||
return base::SafeRound(percent * 100. / kDiscountDivider)
|
||||
* kDiscountDivider;
|
||||
}();
|
||||
const auto hasDiscount = (discount > 0);
|
||||
return {
|
||||
.months = months,
|
||||
.duration = Ui::FormatTTL(months * 86400 * 31),
|
||||
.discount = (discount > 0)
|
||||
.discount = hasDiscount
|
||||
? QString::fromUtf8("\xe2\x88\x92%1%").arg(discount)
|
||||
: QString(),
|
||||
.costPerMonth = Ui::FillAmountAndCurrency(
|
||||
amount / float64(months),
|
||||
currency),
|
||||
.costNoDiscount = Ui::FillAmountAndCurrency(
|
||||
monthlyAmount * months,
|
||||
int64(base::SafeRound(amount / float64(months))),
|
||||
currency),
|
||||
.costNoDiscount = hasDiscount
|
||||
? Ui::FillAmountAndCurrency(
|
||||
int64(base::SafeRound(baselineAmount)),
|
||||
currency)
|
||||
: QString(),
|
||||
.costPerYear = Ui::FillAmountAndCurrency(
|
||||
amount / float64(months / 12.),
|
||||
int64(base::SafeRound(amount / float64(months / 12.))),
|
||||
currency),
|
||||
.botUrl = botUrl,
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Api {
|
||||
|
||||
[[nodiscard]] Data::PremiumSubscriptionOption CreateSubscriptionOption(
|
||||
int months,
|
||||
int monthlyAmount,
|
||||
float64 monthlyAmount,
|
||||
int64 amount,
|
||||
const QString ¤cy,
|
||||
const QString &botUrl);
|
||||
@@ -24,9 +24,9 @@ template<typename Option>
|
||||
if (tlOpts.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
auto monthlyAmountPerCurrency = base::flat_map<QString, int>();
|
||||
auto monthlyAmountPerCurrency = base::flat_map<QString, float64>();
|
||||
auto result = Data::PremiumSubscriptionOptions();
|
||||
const auto monthlyAmount = [&](const QString ¤cy) -> int {
|
||||
const auto monthlyAmount = [&](const QString ¤cy) -> float64 {
|
||||
const auto it = monthlyAmountPerCurrency.find(currency);
|
||||
if (it != end(monthlyAmountPerCurrency)) {
|
||||
return it->second;
|
||||
|
||||
@@ -938,24 +938,30 @@ void AddGiftOptions(
|
||||
const auto costPerMonthIcon = info.costPerMonth.startsWith(kStar)
|
||||
? GenerateStars(costPerMonthFont->height, 1)
|
||||
: QImage();
|
||||
auto leftText = TextWithEntities();
|
||||
if (!info.costNoDiscount.isEmpty()) {
|
||||
leftText.append(Ui::Text::Wrapped(
|
||||
TextWithEntities{ info.costNoDiscount },
|
||||
EntityType::StrikeOut));
|
||||
leftText.append(' ');
|
||||
}
|
||||
leftText.append(costPerMonthIcon.isNull()
|
||||
? info.costPerMonth
|
||||
: removedStar(info.costPerMonth));
|
||||
const auto costPerMonthLabel
|
||||
= row->lifetime().make_state<Ui::Text::String>();
|
||||
costPerMonthLabel->setMarkedText(
|
||||
st::shareBoxListItem.nameStyle,
|
||||
TextWithEntities()
|
||||
.append(Ui::Text::Wrapped(
|
||||
TextWithEntities{ info.costNoDiscount },
|
||||
EntityType::StrikeOut))
|
||||
.append(' ')
|
||||
.append(costPerMonthIcon.isNull()
|
||||
? info.costPerMonth
|
||||
: removedStar(info.costPerMonth)));
|
||||
std::move(leftText));
|
||||
const auto rightText = info.total.isEmpty()
|
||||
? info.costPerYear
|
||||
: info.total;
|
||||
|
||||
const auto costPerYearEntry = [&] {
|
||||
if (!info.costPerYear.startsWith(kStar)) {
|
||||
if (!rightText.startsWith(kStar)) {
|
||||
return QImage();
|
||||
}
|
||||
const auto text = removedStar(info.costPerYear);
|
||||
const auto text = removedStar(rightText);
|
||||
const auto icon = GenerateStars(costPerYearFont->height, 1);
|
||||
auto result = QImage(
|
||||
QSize(costPerYearFont->spacew + costPerYearFont->width(text), 0)
|
||||
@@ -969,7 +975,6 @@ void AddGiftOptions(
|
||||
p.drawImage(0, 0, icon);
|
||||
p.setPen(st::windowSubTextFg);
|
||||
p.setFont(costPerYearFont);
|
||||
auto copy = info.costPerYear;
|
||||
p.drawText(
|
||||
Rect(result.size() / style::DevicePixelRatio()),
|
||||
text,
|
||||
@@ -1078,7 +1083,7 @@ void AddGiftOptions(
|
||||
+ costPerMonthIcon.width()
|
||||
/ style::DevicePixelRatio());
|
||||
const auto costPerYearWidth = costPerYearFont->width(
|
||||
info.costPerYear);
|
||||
rightText);
|
||||
const auto pos = perRect.translated(left, 0).topLeft();
|
||||
const auto availableWidth = row->width()
|
||||
- pos.x()
|
||||
@@ -1096,7 +1101,7 @@ void AddGiftOptions(
|
||||
- QMargins(0, 0, st.rowMargins.right(), 0);
|
||||
if (costPerYearEntry.isNull()) {
|
||||
p.setFont(costPerYearFont);
|
||||
p.drawText(totalRect, info.costPerYear, style::al_right);
|
||||
p.drawText(totalRect, rightText, style::al_right);
|
||||
} else {
|
||||
const auto size = costPerYearEntry.size()
|
||||
/ style::DevicePixelRatio();
|
||||
|
||||
Reference in New Issue
Block a user