fix: refactor a bit

This commit is contained in:
ZavaruKitsu 2023-11-03 22:21:48 +03:00
parent c3251aaf7b
commit 4ad0804d55

View file

@ -62,23 +62,17 @@ base::options::toggle StreamerMode(
} }
); );
not_null<Ui::RpWidget *> AddInnerToggle( not_null<Ui::RpWidget *> AddInnerToggle(not_null<Ui::VerticalLayout *> container,
not_null<Ui::VerticalLayout *> container, const style::SettingsButton &st,
const style::SettingsButton &st, std::vector<not_null<Ui::AbstractCheckView *>> innerCheckViews,
std::vector<not_null<Ui::AbstractCheckView *>> innerCheckViews, not_null<Ui::SlideWrap<> *> wrap,
not_null<Ui::SlideWrap<> *> wrap, rpl::producer<QString> buttonLabel,
rpl::producer<QString> buttonLabel, bool toggledWhenAll)
std::optional<QString> locked,
bool toggledWhenAll,
Settings::IconDescriptor &&icon)
{ {
const auto button = container->add(object_ptr<Ui::SettingsButton>( const auto button = container->add(object_ptr<Ui::SettingsButton>(
container, container,
nullptr, nullptr,
st)); st::settingsButtonNoIcon));
if (icon) {
AddButtonIcon(button, st, std::move(icon));
}
const auto toggleButton = Ui::CreateChild<Ui::SettingsButton>( const auto toggleButton = Ui::CreateChild<Ui::SettingsButton>(
container.get(), container.get(),
@ -175,7 +169,7 @@ not_null<Ui::RpWidget *> AddInnerToggle(
anim::type::normal); anim::type::normal);
} }
}, toggleButton->lifetime()); }, toggleButton->lifetime());
checkView->setLocked(locked.has_value()); checkView->setLocked(false);
checkView->finishAnimating(); checkView->finishAnimating();
const auto label = Ui::CreateChild<Ui::FlatLabel>( const auto label = Ui::CreateChild<Ui::FlatLabel>(
@ -244,31 +238,18 @@ not_null<Ui::RpWidget *> AddInnerToggle(
st::slideWrapDuration); st::slideWrapDuration);
}, button->lifetime()); }, button->lifetime());
const auto handleLocked = [=]
{
if (locked.has_value()) {
Ui::Toast::Show(container, *locked);
return true;
}
return false;
};
button->clicks( button->clicks(
) | start_with_next([=] ) | start_with_next([=]
{ {
if (!handleLocked()) { wrap->toggle(!wrap->toggled(), anim::type::normal);
wrap->toggle(!wrap->toggled(), anim::type::normal);
}
}, button->lifetime()); }, button->lifetime());
toggleButton->clicks( toggleButton->clicks(
) | start_with_next([=] ) | start_with_next([=]
{ {
if (!handleLocked()) { const auto checked = !checkView->checked();
const auto checked = !checkView->checked(); for (const auto &innerCheck : state->innerChecks) {
for (const auto &innerCheck : state->innerChecks) { innerCheck->setChecked(checked, anim::type::normal);
innerCheck->setChecked(checked, anim::type::normal);
}
} }
}, toggleButton->lifetime()); }, toggleButton->lifetime());
@ -476,9 +457,7 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
innerChecks, innerChecks,
raw, raw,
tr::ayu_GhostModeToggle(), tr::ayu_GhostModeToggle(),
std::nullopt, true);
true,
{});
container->add(std::move(wrap)); container->add(std::move(wrap));
container->widthValue( container->widthValue(
) | start_with_next([=](int w) ) | start_with_next([=](int w)
@ -598,9 +577,7 @@ void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
innerChecks, innerChecks,
raw, raw,
tr::ayu_MarkReadAfterAction(), tr::ayu_MarkReadAfterAction(),
std::nullopt, false);
false,
{});
container->add(std::move(wrap)); container->add(std::move(wrap));
container->widthValue( container->widthValue(
) | start_with_next([=](int w) ) | start_with_next([=](int w)