Autosave bio in settings edit section.

This commit is contained in:
John Preston 2018-09-18 19:32:07 +03:00
parent 377689ae86
commit 3ba2a7931e
5 changed files with 54 additions and 39 deletions

View File

@ -395,8 +395,6 @@ infoBlockHeaderLabel: FlatLabel(infoProfileStatusLabel) {
infoBlockHeaderPosition: point(79px, 22px); infoBlockHeaderPosition: point(79px, 22px);
infoProfileToggle: Toggle(defaultToggle) { infoProfileToggle: Toggle(defaultToggle) {
diameter: 16px;
width: 14px;
untoggledFg: menuIconFg; untoggledFg: menuIconFg;
} }
infoProfileToggleOver: Toggle(infoProfileToggle) { infoProfileToggleOver: Toggle(infoProfileToggle) {

View File

@ -467,25 +467,18 @@ void SetupLocalStorage(not_null<Ui::VerticalLayout*> container) {
} }
void SetupDataStorage(not_null<Ui::VerticalLayout*> container) { void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
using namespace rpl::mappers;
AddDivider(container); AddDivider(container);
AddSkip(container, st::settingsSectionSkip); AddSkip(container, st::settingsSectionSkip);
AddSubsectionTitle(container, lng_settings_data_storage); AddSubsectionTitle(container, lng_settings_data_storage);
auto wrap = object_ptr<Ui::VerticalLayout>(container); const auto ask = AddButton(
const auto inner = wrap.data();
container->add(object_ptr<Ui::OverrideMargins>(
container, container,
std::move(wrap), lng_download_path_ask,
QMargins(0, 0, 0, st::settingsCheckbox.margin.bottom()))); st::settingsButton
)->toggleOn(rpl::single(Global::AskDownloadPath()));
const auto ask = inner->add(
object_ptr<Ui::Checkbox>(
inner,
lang(lng_download_path_ask),
Global::AskDownloadPath(),
st::settingsCheckbox),
st::settingsCheckboxPadding);
#ifndef OS_WIN_STORE #ifndef OS_WIN_STORE
const auto showpath = Ui::AttachAsChild( const auto showpath = Ui::AttachAsChild(
@ -513,13 +506,13 @@ void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
path->entity()->addClickHandler([] { path->entity()->addClickHandler([] {
Ui::show(Box<DownloadPathBox>()); Ui::show(Box<DownloadPathBox>());
}); });
path->toggleOn( path->toggleOn(ask->toggledValue() | rpl::map(!_1));
showpath->events_starting_with_copy(!Global::AskDownloadPath()));
#endif // OS_WIN_STORE #endif // OS_WIN_STORE
base::ObservableViewer( ask->toggledValue(
ask->checkedChanged ) | rpl::filter([](bool checked) {
) | rpl::start_with_next([=](bool checked) { return (checked != Global::AskDownloadPath());
}) | rpl::start_with_next([=](bool checked) {
Global::SetAskDownloadPath(checked); Global::SetAskDownloadPath(checked);
Local::writeUserSettings(); Local::writeUserSettings();
@ -527,7 +520,7 @@ void SetupDataStorage(not_null<Ui::VerticalLayout*> container) {
showpath->fire_copy(!checked); showpath->fire_copy(!checked);
#endif // OS_WIN_STORE #endif // OS_WIN_STORE
}, inner->lifetime()); }, ask->lifetime());
AddButton( AddButton(
container, container,
@ -696,8 +689,8 @@ void Chat::setupContent() {
SetupStickersEmoji(content); SetupStickersEmoji(content);
SetupMessages(content); SetupMessages(content);
SetupChatBackground(content); SetupChatBackground(content);
SetupThemeOptions(content);
SetupDataStorage(content); SetupDataStorage(content);
SetupThemeOptions(content);
Ui::ResizeFitChild(this, content); Ui::ResizeFitChild(this, content);
} }

View File

@ -32,6 +32,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Settings { namespace Settings {
namespace { namespace {
constexpr auto kSaveBioTimeout = 1000;
void SetupPhoto( void SetupPhoto(
not_null<Ui::VerticalLayout*> container, not_null<Ui::VerticalLayout*> container,
not_null<Window::Controller*> controller, not_null<Window::Controller*> controller,
@ -348,6 +350,30 @@ BioManager SetupBio(
} }
}, bio->lifetime()); }, 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->setMaxLength(kMaxBioLength);
bio->setSubmitSettings(Ui::InputField::SubmitSettings::Both); bio->setSubmitSettings(Ui::InputField::SubmitSettings::Both);
auto cursor = bio->textCursor(); auto cursor = bio->textCursor();
@ -387,22 +413,23 @@ Information::Information(
setupContent(controller); setupContent(controller);
} }
rpl::producer<bool> Information::sectionCanSaveChanges() { //rpl::producer<bool> Information::sectionCanSaveChanges() {
return _canSaveChanges.value(); // return _canSaveChanges.value();
} //}
//
void Information::sectionSaveChanges(FnMut<void()> done) { //void Information::sectionSaveChanges(FnMut<void()> done) {
_save(std::move(done)); // _save(std::move(done));
} //}
void Information::setupContent(not_null<Window::Controller*> controller) { void Information::setupContent(not_null<Window::Controller*> controller) {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this); const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
SetupPhoto(content, controller, _self); SetupPhoto(content, controller, _self);
SetupRows(content, _self); SetupRows(content, _self);
auto manager = SetupBio(content, _self); SetupBio(content, _self);
_canSaveChanges = std::move(manager.canSave); //auto manager = SetupBio(content, _self);
_save = std::move(manager.save); //_canSaveChanges = std::move(manager.canSave);
//_save = std::move(manager.save);
Ui::ResizeFitChild(this, content); Ui::ResizeFitChild(this, content);
} }

View File

@ -18,15 +18,12 @@ public:
not_null<Window::Controller*> controller, not_null<Window::Controller*> controller,
not_null<UserData*> self); not_null<UserData*> self);
rpl::producer<bool> sectionCanSaveChanges() override;
void sectionSaveChanges(FnMut<void()> done) override;
private: private:
void setupContent(not_null<Window::Controller*> controller); void setupContent(not_null<Window::Controller*> controller);
not_null<UserData*> _self; not_null<UserData*> _self;
rpl::variable<bool> _canSaveChanges; //rpl::variable<bool> _canSaveChanges;
Fn<void(FnMut<void()> done)> _save; //Fn<void(FnMut<void()> done)> _save;
}; };

View File

@ -754,8 +754,8 @@ defaultToggle: Toggle {
duration: 120; duration: 120;
border: 2px; border: 2px;
shift: 1px; shift: 1px;
diameter: 20px; diameter: 16px;
width: 16px; width: 14px;
xsize: 0px; xsize: 0px;
vsize: 0px; vsize: 0px;
vshift: 0px; vshift: 0px;