mirror of https://github.com/procxx/kepka.git
Autosave bio in settings edit section.
This commit is contained in:
parent
377689ae86
commit
3ba2a7931e
|
@ -395,8 +395,6 @@ infoBlockHeaderLabel: FlatLabel(infoProfileStatusLabel) {
|
|||
infoBlockHeaderPosition: point(79px, 22px);
|
||||
|
||||
infoProfileToggle: Toggle(defaultToggle) {
|
||||
diameter: 16px;
|
||||
width: 14px;
|
||||
untoggledFg: menuIconFg;
|
||||
}
|
||||
infoProfileToggleOver: Toggle(infoProfileToggle) {
|
||||
|
|
|
@ -467,25 +467,18 @@ void SetupLocalStorage(not_null<Ui::VerticalLayout*> container) {
|
|||
}
|
||||
|
||||
void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
|
||||
using namespace rpl::mappers;
|
||||
|
||||
AddDivider(container);
|
||||
AddSkip(container, st::settingsSectionSkip);
|
||||
|
||||
AddSubsectionTitle(container, lng_settings_data_storage);
|
||||
|
||||
auto wrap = object_ptr<Ui::VerticalLayout>(container);
|
||||
const auto inner = wrap.data();
|
||||
container->add(object_ptr<Ui::OverrideMargins>(
|
||||
const auto ask = AddButton(
|
||||
container,
|
||||
std::move(wrap),
|
||||
QMargins(0, 0, 0, st::settingsCheckbox.margin.bottom())));
|
||||
|
||||
const auto ask = inner->add(
|
||||
object_ptr<Ui::Checkbox>(
|
||||
inner,
|
||||
lang(lng_download_path_ask),
|
||||
Global::AskDownloadPath(),
|
||||
st::settingsCheckbox),
|
||||
st::settingsCheckboxPadding);
|
||||
lng_download_path_ask,
|
||||
st::settingsButton
|
||||
)->toggleOn(rpl::single(Global::AskDownloadPath()));
|
||||
|
||||
#ifndef OS_WIN_STORE
|
||||
const auto showpath = Ui::AttachAsChild(
|
||||
|
@ -513,13 +506,13 @@ void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
|
|||
path->entity()->addClickHandler([] {
|
||||
Ui::show(Box<DownloadPathBox>());
|
||||
});
|
||||
path->toggleOn(
|
||||
showpath->events_starting_with_copy(!Global::AskDownloadPath()));
|
||||
path->toggleOn(ask->toggledValue() | rpl::map(!_1));
|
||||
#endif // OS_WIN_STORE
|
||||
|
||||
base::ObservableViewer(
|
||||
ask->checkedChanged
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
ask->toggledValue(
|
||||
) | rpl::filter([](bool checked) {
|
||||
return (checked != Global::AskDownloadPath());
|
||||
}) | rpl::start_with_next([=](bool checked) {
|
||||
Global::SetAskDownloadPath(checked);
|
||||
Local::writeUserSettings();
|
||||
|
||||
|
@ -527,7 +520,7 @@ void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
|
|||
showpath->fire_copy(!checked);
|
||||
#endif // OS_WIN_STORE
|
||||
|
||||
}, inner->lifetime());
|
||||
}, ask->lifetime());
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
|
@ -696,8 +689,8 @@ void Chat::setupContent() {
|
|||
SetupStickersEmoji(content);
|
||||
SetupMessages(content);
|
||||
SetupChatBackground(content);
|
||||
SetupThemeOptions(content);
|
||||
SetupDataStorage(content);
|
||||
SetupThemeOptions(content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
namespace Settings {
|
||||
namespace {
|
||||
|
||||
constexpr auto kSaveBioTimeout = 1000;
|
||||
|
||||
void SetupPhoto(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::Controller*> controller,
|
||||
|
@ -348,6 +350,30 @@ BioManager SetupBio(
|
|||
}
|
||||
}, bio->lifetime());
|
||||
|
||||
const auto generation = Ui::AttachAsChild(bio, 0);
|
||||
changed->events(
|
||||
) | rpl::start_with_next([=](bool changed) {
|
||||
if (changed) {
|
||||
const auto saved = *generation = std::abs(*generation) + 1;
|
||||
App::CallDelayed(kSaveBioTimeout, bio, [=] {
|
||||
if (*generation == saved) {
|
||||
save(nullptr);
|
||||
*generation = 0;
|
||||
}
|
||||
});
|
||||
} else if (*generation > 0) {
|
||||
*generation = -*generation;
|
||||
}
|
||||
}, bio->lifetime());
|
||||
|
||||
// We need 'bio' to still exist here as InputField, so we add this
|
||||
// to 'container' lifetime, not to the 'bio' lifetime.
|
||||
container->lifetime().add([=] {
|
||||
if (*generation > 0) {
|
||||
save(nullptr);
|
||||
}
|
||||
});
|
||||
|
||||
bio->setMaxLength(kMaxBioLength);
|
||||
bio->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
|
||||
auto cursor = bio->textCursor();
|
||||
|
@ -387,22 +413,23 @@ Information::Information(
|
|||
setupContent(controller);
|
||||
}
|
||||
|
||||
rpl::producer<bool> Information::sectionCanSaveChanges() {
|
||||
return _canSaveChanges.value();
|
||||
}
|
||||
|
||||
void Information::sectionSaveChanges(FnMut<void()> done) {
|
||||
_save(std::move(done));
|
||||
}
|
||||
//rpl::producer<bool> Information::sectionCanSaveChanges() {
|
||||
// return _canSaveChanges.value();
|
||||
//}
|
||||
//
|
||||
//void Information::sectionSaveChanges(FnMut<void()> done) {
|
||||
// _save(std::move(done));
|
||||
//}
|
||||
|
||||
void Information::setupContent(not_null<Window::Controller*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
SetupPhoto(content, controller, _self);
|
||||
SetupRows(content, _self);
|
||||
auto manager = SetupBio(content, _self);
|
||||
_canSaveChanges = std::move(manager.canSave);
|
||||
_save = std::move(manager.save);
|
||||
SetupBio(content, _self);
|
||||
//auto manager = SetupBio(content, _self);
|
||||
//_canSaveChanges = std::move(manager.canSave);
|
||||
//_save = std::move(manager.save);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
|
|
@ -18,15 +18,12 @@ public:
|
|||
not_null<Window::Controller*> controller,
|
||||
not_null<UserData*> self);
|
||||
|
||||
rpl::producer<bool> sectionCanSaveChanges() override;
|
||||
void sectionSaveChanges(FnMut<void()> done) override;
|
||||
|
||||
private:
|
||||
void setupContent(not_null<Window::Controller*> controller);
|
||||
|
||||
not_null<UserData*> _self;
|
||||
rpl::variable<bool> _canSaveChanges;
|
||||
Fn<void(FnMut<void()> done)> _save;
|
||||
//rpl::variable<bool> _canSaveChanges;
|
||||
//Fn<void(FnMut<void()> done)> _save;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -754,8 +754,8 @@ defaultToggle: Toggle {
|
|||
duration: 120;
|
||||
border: 2px;
|
||||
shift: 1px;
|
||||
diameter: 20px;
|
||||
width: 16px;
|
||||
diameter: 16px;
|
||||
width: 14px;
|
||||
xsize: 0px;
|
||||
vsize: 0px;
|
||||
vshift: 0px;
|
||||
|
|
Loading…
Reference in New Issue