Moved out music button creation to single place.

This commit is contained in:
23rd
2025-10-30 21:15:55 +03:00
parent 7cdb651538
commit af874bebfd
4 changed files with 106 additions and 46 deletions
+1
View File
@@ -1072,6 +1072,7 @@ PRIVATE
info/reactions_list/info_reactions_list_widget.h
info/requests_list/info_requests_list_widget.cpp
info/requests_list/info_requests_list_widget.h
info/saved/info_saved_music_common.cpp
info/saved/info_saved_music_common.h
info/saved/info_saved_music_provider.cpp
info/saved/info_saved_music_provider.h
@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h"
#include "data/data_saved_music.h"
#include "data/data_saved_sublist.h"
#include "info/saved/info_saved_music_common.h"
#include "info_profile_actions.h"
#include "main/main_session.h"
#include "apiwrap.h"
@@ -49,11 +50,6 @@ namespace Profile {
namespace {
[[nodiscard]] MusicButtonData DocumentMusicButtonData(
not_null<DocumentData*> document) {
return { Ui::Text::FormatSongNameFor(document) };
}
void AddAboutVerification(
not_null<Ui::VerticalLayout*> layout,
not_null<PeerData*> peer) {
@@ -182,47 +178,11 @@ void InnerWidget::setupMembers(not_null<Ui::VerticalLayout*> container) {
}
void InnerWidget::setupSavedMusic(not_null<Ui::VerticalLayout*> container) {
auto musicValue = Data::SavedMusic::Supported(_peer->id)
? Data::SavedMusicList(
_peer,
nullptr,
1
) | rpl::map([=](const Data::SavedMusicSlice &data) {
return data.size() ? data[0].get() : nullptr;
}) | rpl::type_erased()
: rpl::single<HistoryItem*>((HistoryItem*)(nullptr));
const auto divider = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
rpl::combine(
std::move(musicValue),
_topBarColor.value()
) | rpl::start_with_next([=](
HistoryItem *item,
std::optional<QColor> color) {
while (divider->entity()->count()) {
delete divider->entity()->widgetAt(0);
}
if (item) {
if (const auto document = item->media()
? item->media()->document()
: nullptr) {
const auto music = divider->entity()->add(
object_ptr<MusicButton>(
divider->entity(),
DocumentMusicButtonData(document),
[window = _controller, peer = _peer] {
window->showSection(Info::Saved::MakeMusic(peer));
}));
music->setOverrideBg(color);
}
divider->toggle(true, anim::type::normal);
}
}, lifetime());
divider->finishAnimating();
Info::Saved::SetupSavedMusic(
container,
_controller,
_peer,
_topBarColor.value());
}
void InnerWidget::addAboutVerificationOrDivider(
@@ -0,0 +1,83 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "info/saved/info_saved_music_common.h"
#include "data/data_peer.h"
#include "data/data_saved_music.h"
#include "data/data_saved_sublist.h"
#include "history/history_item.h"
#include "info/info_controller.h"
#include "info/info_memento.h"
#include "info/profile/info_profile_music_button.h"
#include "info/saved/info_saved_music_widget.h"
#include "ui/text/format_song_document_name.h"
#include "ui/widgets/buttons.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "ui/vertical_list.h"
namespace Info::Saved {
namespace {
[[nodiscard]] Profile::MusicButtonData DocumentMusicButtonData(
not_null<DocumentData*> document) {
return { Ui::Text::FormatSongNameFor(document) };
}
} // namespace
void SetupSavedMusic(
not_null<Ui::VerticalLayout*> container,
not_null<Info::Controller*> controller,
not_null<PeerData*> peer,
rpl::producer<std::optional<QColor>> topBarColor) {
auto musicValue = Data::SavedMusic::Supported(peer->id)
? Data::SavedMusicList(
peer,
nullptr,
1
) | rpl::map([=](const Data::SavedMusicSlice &data) {
return data.size() ? data[0].get() : nullptr;
}) | rpl::type_erased()
: rpl::single<HistoryItem*>((HistoryItem*)(nullptr));
const auto divider = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
rpl::combine(
std::move(musicValue),
std::move(topBarColor)
) | rpl::start_with_next([=](
HistoryItem *item,
std::optional<QColor> color) {
while (divider->entity()->count()) {
delete divider->entity()->widgetAt(0);
}
if (item) {
if (const auto document = item->media()
? item->media()->document()
: nullptr) {
const auto music = divider->entity()->add(
object_ptr<Profile::MusicButton>(
divider->entity(),
DocumentMusicButtonData(document),
[window = controller, peer] {
window->showSection(Info::Saved::MakeMusic(peer));
}));
music->setOverrideBg(color);
}
divider->toggle(true, anim::type::normal);
}
}, container->lifetime());
divider->finishAnimating();
}
} // namespace Info::Saved
@@ -7,6 +7,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
class PeerData;
namespace Ui {
class VerticalLayout;
} // namespace Ui
namespace Info {
class Controller;
} // namespace Info
namespace Info::Saved {
struct MusicTag {
@@ -17,4 +27,10 @@ struct MusicTag {
not_null<PeerData*> peer;
};
void SetupSavedMusic(
not_null<Ui::VerticalLayout*> container,
not_null<Info::Controller*> controller,
not_null<PeerData*> peer,
rpl::producer<std::optional<QColor>> topBarColor);
} // namespace Info::Saved