Added first shown tooltip to ttl button from voice record bar.

This commit is contained in:
23rd 2024-01-14 18:50:15 +03:00 committed by John Preston
parent 8895e49466
commit cb4781360a
4 changed files with 55 additions and 9 deletions

View file

@ -2492,6 +2492,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_record_listen_cancel_sure" = "Are you sure you want to discard your recorded voice message?"; "lng_record_listen_cancel_sure" = "Are you sure you want to discard your recorded voice message?";
"lng_record_lock_discard" = "Discard"; "lng_record_lock_discard" = "Discard";
"lng_record_hold_tip" = "Please hold the mouse button pressed to record a voice message."; "lng_record_hold_tip" = "Please hold the mouse button pressed to record a voice message.";
"lng_record_once_first_tooltip" = "Tap to set this message to **Play Once**.";
"lng_record_once_active_tooltip" = "The recipients will be able to listen to it only once."; "lng_record_once_active_tooltip" = "The recipients will be able to listen to it only once.";
"lng_will_be_notified" = "Members will be notified when you post"; "lng_will_be_notified" = "Members will be notified when you post";
"lng_wont_be_notified" = "Members will not be notified when you post"; "lng_wont_be_notified" = "Members will not be notified when you post";

View file

@ -339,7 +339,8 @@ QByteArray Settings::serialize() const {
<< qint32(_ignoreBatterySaving.current() ? 1 : 0) << qint32(_ignoreBatterySaving.current() ? 1 : 0)
<< quint64(_macRoundIconDigest.value_or(0)) << quint64(_macRoundIconDigest.value_or(0))
<< qint32(_storiesClickTooltipHidden.current() ? 1 : 0) << qint32(_storiesClickTooltipHidden.current() ? 1 : 0)
<< qint32(_recentEmojiSkip.size()); << qint32(_recentEmojiSkip.size())
<< qint32(_ttlVoiceClickTooltipHidden.current() ? 1 : 0);
for (const auto &id : _recentEmojiSkip) { for (const auto &id : _recentEmojiSkip) {
stream << id; stream << id;
} }
@ -453,6 +454,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
qint32 storiesClickTooltipHidden = _storiesClickTooltipHidden.current() ? 1 : 0; qint32 storiesClickTooltipHidden = _storiesClickTooltipHidden.current() ? 1 : 0;
base::flat_set<QString> recentEmojiSkip; base::flat_set<QString> recentEmojiSkip;
qint32 trayIconMonochrome = (_trayIconMonochrome.current() ? 1 : 0); qint32 trayIconMonochrome = (_trayIconMonochrome.current() ? 1 : 0);
qint32 ttlVoiceClickTooltipHidden = _ttlVoiceClickTooltipHidden.current() ? 1 : 0;
stream >> themesAccentColors; stream >> themesAccentColors;
if (!stream.atEnd()) { if (!stream.atEnd()) {
@ -709,6 +711,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
// Let existing clients use the old value. // Let existing clients use the old value.
trayIconMonochrome = 0; trayIconMonochrome = 0;
} }
if (!stream.atEnd()) {
stream >> ttlVoiceClickTooltipHidden;
}
if (stream.status() != QDataStream::Ok) { if (stream.status() != QDataStream::Ok) {
LOG(("App Error: " LOG(("App Error: "
"Bad data for Core::Settings::constructFromSerialized()")); "Bad data for Core::Settings::constructFromSerialized()"));
@ -903,6 +908,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) {
_storiesClickTooltipHidden = (storiesClickTooltipHidden == 1); _storiesClickTooltipHidden = (storiesClickTooltipHidden == 1);
_recentEmojiSkip = std::move(recentEmojiSkip); _recentEmojiSkip = std::move(recentEmojiSkip);
_trayIconMonochrome = (trayIconMonochrome == 1); _trayIconMonochrome = (trayIconMonochrome == 1);
_ttlVoiceClickTooltipHidden = (ttlVoiceClickTooltipHidden == 1);
} }
QString Settings::getSoundPath(const QString &key) const { QString Settings::getSoundPath(const QString &key) const {
@ -1259,6 +1265,7 @@ void Settings::resetOnLastLogout() {
_systemDarkModeEnabled = false; _systemDarkModeEnabled = false;
_hiddenGroupCallTooltips = 0; _hiddenGroupCallTooltips = 0;
_storiesClickTooltipHidden = false; _storiesClickTooltipHidden = false;
_ttlVoiceClickTooltipHidden = false;
_recentEmojiPreload.clear(); _recentEmojiPreload.clear();
_recentEmoji.clear(); _recentEmoji.clear();

View file

@ -820,6 +820,15 @@ public:
void setStoriesClickTooltipHidden(bool value) { void setStoriesClickTooltipHidden(bool value) {
_storiesClickTooltipHidden = value; _storiesClickTooltipHidden = value;
} }
[[nodiscard]] bool ttlVoiceClickTooltipHidden() const {
return _ttlVoiceClickTooltipHidden.current();
}
[[nodiscard]] rpl::producer<bool> ttlVoiceClickTooltipHiddenValue() const {
return _ttlVoiceClickTooltipHidden.value();
}
void setTtlVoiceClickTooltipHidden(bool value) {
_ttlVoiceClickTooltipHidden = value;
}
[[nodiscard]] static bool ThirdColumnByDefault(); [[nodiscard]] static bool ThirdColumnByDefault();
[[nodiscard]] static float64 DefaultDialogsWidthRatio(); [[nodiscard]] static float64 DefaultDialogsWidthRatio();
@ -945,6 +954,7 @@ private:
rpl::variable<bool> _ignoreBatterySaving = false; rpl::variable<bool> _ignoreBatterySaving = false;
std::optional<uint64> _macRoundIconDigest; std::optional<uint64> _macRoundIconDigest;
rpl::variable<bool> _storiesClickTooltipHidden = false; rpl::variable<bool> _storiesClickTooltipHidden = false;
rpl::variable<bool> _ttlVoiceClickTooltipHidden = false;
bool _tabbedReplacedWithInfo = false; // per-window bool _tabbedReplacedWithInfo = false; // per-window
rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window rpl::event_stream<bool> _tabbedReplacedWithInfoValue; // per-window

View file

@ -280,7 +280,6 @@ protected:
private: private:
const style::RecordBar &_st; const style::RecordBar &_st;
const QRect _rippleRect; const QRect _rippleRect;
const QString _text;
Ui::Animations::Simple _activeAnimation; Ui::Animations::Simple _activeAnimation;
@ -292,8 +291,7 @@ TTLButton::TTLButton(
: RippleButton(parent, st.lock.ripple) : RippleButton(parent, st.lock.ripple)
, _st(st) , _st(st)
, _rippleRect(Rect(Size(st::historyRecordLockTopShadow.width())) , _rippleRect(Rect(Size(st::historyRecordLockTopShadow.width()))
- (st::historyRecordLockRippleMargin)) - (st::historyRecordLockRippleMargin)) {
, _text(u"1"_q) {
resize(Size(st::historyRecordLockTopShadow.width())); resize(Size(st::historyRecordLockTopShadow.width()));
setClickedCallback([=] { setClickedCallback([=] {
@ -306,20 +304,27 @@ TTLButton::TTLButton(
st::historyRecordVoiceShowDuration); st::historyRecordVoiceShowDuration);
}); });
{ Ui::RpWidget::shownValue() | rpl::filter(
rpl::mappers::_1
) | rpl::skip(1) | rpl::take(1) | rpl::start_with_next([=] {
auto text = rpl::conditional(
Core::App().settings().ttlVoiceClickTooltipHiddenValue(),
tr::lng_record_once_active_tooltip(
Ui::Text::RichLangValue),
tr::lng_record_once_first_tooltip(
Ui::Text::RichLangValue));
const auto tooltip = Ui::CreateChild<Ui::ImportantTooltip>( const auto tooltip = Ui::CreateChild<Ui::ImportantTooltip>(
parent.get(), parent.get(),
object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>( object_ptr<Ui::PaddingWrap<Ui::FlatLabel>>(
parent.get(), parent.get(),
Ui::MakeNiceTooltipLabel( Ui::MakeNiceTooltipLabel(
parent, parent,
tr::lng_record_once_active_tooltip( std::move(text),
Ui::Text::RichLangValue),
st::historyMessagesTTLLabel.minWidth, st::historyMessagesTTLLabel.minWidth,
st::ttlMediaImportantTooltipLabel), st::ttlMediaImportantTooltipLabel),
st::defaultImportantTooltip.padding), st::defaultImportantTooltip.padding),
st::historyRecordTooltip); st::historyRecordTooltip);
geometryValue( Ui::RpWidget::geometryValue(
) | rpl::start_with_next([=](const QRect &r) { ) | rpl::start_with_next([=](const QRect &r) {
if (r.isEmpty()) { if (r.isEmpty()) {
return; return;
@ -336,6 +341,15 @@ TTLButton::TTLButton(
}); });
}, tooltip->lifetime()); }, tooltip->lifetime());
tooltip->show(); tooltip->show();
if (!Core::App().settings().ttlVoiceClickTooltipHidden()) {
clicks(
) | rpl::take(1) | rpl::start_with_next([=] {
Core::App().settings().setTtlVoiceClickTooltipHidden(true);
}, tooltip->lifetime());
tooltip->toggleAnimated(true);
} else {
tooltip->toggleFast(false);
}
clicks( clicks(
) | rpl::start_with_next([=] { ) | rpl::start_with_next([=] {
@ -347,7 +361,19 @@ TTLButton::TTLButton(
tooltip->hideAfter(kTimeout); tooltip->hideAfter(kTimeout);
} }
}, tooltip->lifetime()); }, tooltip->lifetime());
}
Ui::RpWidget::geometryValue(
) | rpl::map([=](const QRect &r) {
return (r.left() + r.width() > parentWidget()->width());
}) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](bool toHide) {
const auto isFirstTooltip =
!Core::App().settings().ttlVoiceClickTooltipHidden();
if (isFirstTooltip || (!isFirstTooltip && toHide)) {
tooltip->toggleAnimated(!toHide);
}
}, tooltip->lifetime());
}, lifetime());
paintRequest( paintRequest(
) | rpl::start_with_next([=](const QRect &clip) { ) | rpl::start_with_next([=](const QRect &clip) {
@ -1633,6 +1659,8 @@ void VoiceRecordBar::finish() {
_listen = nullptr; _listen = nullptr;
[[maybe_unused]] const auto s = takeTTLState();
_sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 }); _sendActionUpdates.fire({ Api::SendProgressType::RecordVoice, -1 });
} }