mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-09-07 20:43:12 +02:00
Show USD estimate in suggest posts.
This commit is contained in:
parent
9b989329d4
commit
a665d7cc3c
3 changed files with 43 additions and 3 deletions
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "history/view/controls/history_view_suggest_options.h"
|
#include "history/view/controls/history_view_suggest_options.h"
|
||||||
|
|
||||||
|
#include "base/event_filter.h"
|
||||||
#include "base/unixtime.h"
|
#include "base/unixtime.h"
|
||||||
#include "chat_helpers/compose/compose_show.h"
|
#include "chat_helpers/compose/compose_show.h"
|
||||||
#include "core/ui_integration.h"
|
#include "core/ui_integration.h"
|
||||||
|
@ -80,6 +81,37 @@ void ChooseSuggestTimeBox(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddApproximateUsd(
|
||||||
|
not_null<QWidget*> field,
|
||||||
|
not_null<Main::Session*> session,
|
||||||
|
rpl::producer<CreditsAmount> price) {
|
||||||
|
auto value = std::move(price) | rpl::map([=](CreditsAmount amount) {
|
||||||
|
if (!amount) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
const auto appConfig = &session->appConfig();
|
||||||
|
const auto rate = amount.ton()
|
||||||
|
? appConfig->currencyWithdrawRate()
|
||||||
|
: (appConfig->starsWithdrawRate() / 100.);
|
||||||
|
const auto precise = amount.value() * rate;
|
||||||
|
return u"~$"_q + QString::number(precise, 'f', 2);
|
||||||
|
});
|
||||||
|
const auto usd = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
|
field,
|
||||||
|
std::move(value),
|
||||||
|
st::suggestPriceEstimate);
|
||||||
|
const auto move = [=] {
|
||||||
|
usd->moveToRight(0, st::suggestPriceEstimateTop);
|
||||||
|
};
|
||||||
|
base::install_event_filter(field, [=](not_null<QEvent*> e) {
|
||||||
|
if (e->type() == QEvent::Resize) {
|
||||||
|
move();
|
||||||
|
}
|
||||||
|
return base::EventFilterResult::Continue;
|
||||||
|
});
|
||||||
|
usd->widthValue() | rpl::start_with_next(move, usd->lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
void ChooseSuggestPriceBox(
|
void ChooseSuggestPriceBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
SuggestPriceBoxArgs &&args) {
|
SuggestPriceBoxArgs &&args) {
|
||||||
|
@ -316,6 +348,8 @@ void ChooseSuggestPriceBox(
|
||||||
starsFieldWrap->resize(width, starsField->height());
|
starsFieldWrap->resize(width, starsField->height());
|
||||||
}, starsFieldWrap->lifetime());
|
}, starsFieldWrap->lifetime());
|
||||||
|
|
||||||
|
AddApproximateUsd(starsField, session, starsPrice());
|
||||||
|
|
||||||
Ui::AddSkip(starsInner);
|
Ui::AddSkip(starsInner);
|
||||||
Ui::AddSkip(starsInner);
|
Ui::AddSkip(starsInner);
|
||||||
const auto formatPrice = [peer = args.peer](CreditsAmount amount) {
|
const auto formatPrice = [peer = args.peer](CreditsAmount amount) {
|
||||||
|
@ -380,6 +414,8 @@ void ChooseSuggestPriceBox(
|
||||||
tonFieldWrap->resize(width, tonField->height());
|
tonFieldWrap->resize(width, tonField->height());
|
||||||
}, tonFieldWrap->lifetime());
|
}, tonFieldWrap->lifetime());
|
||||||
|
|
||||||
|
AddApproximateUsd(tonField, session, tonPrice());
|
||||||
|
|
||||||
Ui::AddSkip(tonInner);
|
Ui::AddSkip(tonInner);
|
||||||
Ui::AddSkip(tonInner);
|
Ui::AddSkip(tonInner);
|
||||||
Ui::AddDividerText(
|
Ui::AddDividerText(
|
||||||
|
|
|
@ -271,9 +271,9 @@ void TodoList::updateTexts() {
|
||||||
_flags = _todolist->flags();
|
_flags = _todolist->flags();
|
||||||
_subtitle.setText(
|
_subtitle.setText(
|
||||||
st::msgDateTextStyle,
|
st::msgDateTextStyle,
|
||||||
(parent()->history()->peer->isUser()
|
(_todolist->othersCanComplete()
|
||||||
? tr::lng_todo_title(tr::now)
|
? tr::lng_todo_title_group(tr::now)
|
||||||
: tr::lng_todo_title_group(tr::now)));
|
: tr::lng_todo_title(tr::now)));
|
||||||
}
|
}
|
||||||
updateTasks(skipAnimations);
|
updateTasks(skipAnimations);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1379,6 +1379,10 @@ suggestPriceBox: Box(defaultBox) {
|
||||||
}
|
}
|
||||||
shadowIgnoreTopSkip: true;
|
shadowIgnoreTopSkip: true;
|
||||||
}
|
}
|
||||||
|
suggestPriceEstimate: FlatLabel(defaultFlatLabel) {
|
||||||
|
textFg: windowSubTextFg;
|
||||||
|
}
|
||||||
|
suggestPriceEstimateTop: 12px;
|
||||||
tonInput: InputField(defaultInputField) {
|
tonInput: InputField(defaultInputField) {
|
||||||
textBg: transparent;
|
textBg: transparent;
|
||||||
textMargins: margins(0px, 7px, 0px, 7px);
|
textMargins: margins(0px, 7px, 0px, 7px);
|
||||||
|
|
Loading…
Add table
Reference in a new issue