M changelog.md => changelog.md +1 -0
@@ 6,6 6,7 @@
* `[desktop]` info on how to unlock
* `[settings]` pin change option in settings main window
+* `[phonebook]` Make SAVE button appear when at least one field is fulfilled.
### Fixed
M module-apps/application-phonebook/models/NewContactModel.cpp => module-apps/application-phonebook/models/NewContactModel.cpp +25 -5
@@ 40,31 40,36 @@ void NewContactModel::createData()
phonebookInternals::ListItemName::FirstName,
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
- [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
+ [app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ [this]() { this->ContactDataChanged(); }));
internalData.push_back(new gui::InputLinesWithLabelIWidget(
phonebookInternals::ListItemName::SecondName,
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
- [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
+ [app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ [this]() { this->ContactDataChanged(); }));
internalData.push_back(new gui::InputLinesWithLabelIWidget(
phonebookInternals::ListItemName::Number,
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
- [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
+ [app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ [this]() { this->ContactDataChanged(); }));
internalData.push_back(new gui::InputLinesWithLabelIWidget(
phonebookInternals::ListItemName::SecondNumber,
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
- [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
+ [app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ [this]() { this->ContactDataChanged(); }));
internalData.push_back(new gui::InputLinesWithLabelIWidget(
phonebookInternals::ListItemName::Email,
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
- [app]() { app->getCurrentWindow()->selectSpecialCharacter(); }));
+ [app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ [this]() { this->ContactDataChanged(); }));
internalData.push_back(new gui::InputBoxWithLabelAndIconWidget(phonebookInternals::ListItemName::SpeedDialKey));
@@ 83,6 88,7 @@ void NewContactModel::createData()
[app](const UTF8 &text) { app->getCurrentWindow()->bottomBarTemporaryMode(text, false); },
[app]() { app->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
[app]() { app->getCurrentWindow()->selectSpecialCharacter(); },
+ nullptr,
2));
internalData.push_back(new gui::InputLinesWithLabelIWidget(
@@ 124,3 130,17 @@ void NewContactModel::loadData(std::shared_ptr<ContactRecord> contactRecord)
}
}
}
+
+void NewContactModel::ContactDataChanged()
+{
+ for (auto item : internalData) {
+ if (item->onEmptyCallback) {
+ if (!item->onEmptyCallback()) {
+ application->getCurrentWindow()->setBottomBarActive(gui::BottomBar::Side::CENTER, true); // SAVE button
+ return;
+ }
+ }
+ }
+ application->getCurrentWindow()->setBottomBarActive(gui::BottomBar::Side::CENTER, false); // SAVE button
+ return;
+}
M module-apps/application-phonebook/models/NewContactModel.hpp => module-apps/application-phonebook/models/NewContactModel.hpp +1 -0
@@ 26,4 26,5 @@ class NewContactModel : public app::InternalModel<gui::ContactListItem *>, publi
auto getItem(gui::Order order) -> gui::ListItem * override;
void requestRecords(const uint32_t offset, const uint32_t limit) override;
+ void ContactDataChanged();
};
M module-apps/application-phonebook/widgets/ContactListItem.hpp => module-apps/application-phonebook/widgets/ContactListItem.hpp +1 -0
@@ 9,6 9,7 @@ namespace gui
public:
std::function<void(std::shared_ptr<ContactRecord> contact)> onSaveCallback = nullptr;
std::function<void(std::shared_ptr<ContactRecord> contact)> onLoadCallback = nullptr;
+ std::function<bool()> onEmptyCallback = nullptr;
};
} /* namespace gui */
M module-apps/application-phonebook/widgets/InputLinesWithLabelIWidget.cpp => module-apps/application-phonebook/widgets/InputLinesWithLabelIWidget.cpp +13 -2
@@ 5,6 5,7 @@
#include <ContactRecord.hpp>
#include <module-utils/i18/i18.hpp>
+#include <utility>
namespace gui
{
@@ 12,8 13,9 @@ namespace gui
std::function<void(const UTF8 &)> bottomBarTemporaryMode,
std::function<void()> bottomBarRestoreFromTemporaryMode,
std::function<void()> selectSpecialCharacter,
+ std::function<void()> contentChanged,
unsigned int lines)
- : listItemName(listItemName)
+ : listItemName(listItemName), checkTextContent(std::move(contentChanged))
{
setMinimumSize(phonebookStyle::inputLinesWithLabelWidget::w,
phonebookStyle::inputLinesWithLabelWidget::title_label_h +
@@ 68,7 70,11 @@ namespace gui
return true;
};
- inputCallback = [&](Item &item, const InputEvent &event) { return inputText->onInput(event); };
+ inputCallback = [&](Item &item, const InputEvent &event) {
+ auto result = inputText->onInput(event);
+ checkTextContent();
+ return result;
+ };
setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_NO_EDGES);
}
@@ 123,6 129,7 @@ namespace gui
onSaveCallback = [&](std::shared_ptr<ContactRecord> contact) { contact->primaryName = inputText->getText(); };
onLoadCallback = [&](std::shared_ptr<ContactRecord> contact) { inputText->setText(contact->primaryName); };
+ onEmptyCallback = [&]() { return inputText->isEmpty(); };
}
void InputLinesWithLabelIWidget::secondNameHandler()
{
@@ 133,6 140,7 @@ namespace gui
contact->alternativeName = inputText->getText();
};
onLoadCallback = [&](std::shared_ptr<ContactRecord> contact) { inputText->setText(contact->alternativeName); };
+ onEmptyCallback = [&]() { return inputText->isEmpty(); };
}
void InputLinesWithLabelIWidget::numberHandler()
{
@@ 151,6 159,7 @@ namespace gui
inputText->setText(contact->numbers[0].number.getEntered());
}
};
+ onEmptyCallback = [&]() { return inputText->isEmpty(); };
}
void InputLinesWithLabelIWidget::secondNumberHandler()
{
@@ 169,6 178,7 @@ namespace gui
inputText->setText(contact->numbers[1].number.getEntered());
}
};
+ onEmptyCallback = [&]() { return inputText->isEmpty(); };
}
void InputLinesWithLabelIWidget::emailHandler()
{
@@ 177,6 187,7 @@ namespace gui
onSaveCallback = [&](std::shared_ptr<ContactRecord> contact) { contact->mail = inputText->getText(); };
onLoadCallback = [&](std::shared_ptr<ContactRecord> contact) { inputText->setText(contact->mail); };
+ onEmptyCallback = [&]() { return inputText->isEmpty(); };
}
void InputLinesWithLabelIWidget::addressHandler()
{
M module-apps/application-phonebook/widgets/InputLinesWithLabelIWidget.hpp => module-apps/application-phonebook/widgets/InputLinesWithLabelIWidget.hpp +2 -0
@@ 19,6 19,7 @@ namespace gui
std::function<void(const UTF8 &text)> bottomBarTemporaryMode = nullptr,
std::function<void()> bottomBarRestoreFromTemporaryMode = nullptr,
std::function<void()> selectSpecialCharacter = nullptr,
+ std::function<void()> contentChanged = nullptr,
unsigned int lines = 1);
~InputLinesWithLabelIWidget() override = default;
@@ 28,6 29,7 @@ namespace gui
TextFixedSize *inputText = nullptr;
private:
+ std::function<void()> checkTextContent = nullptr;
void applyItemNameSpecificSettings();
void firstNameHandler();
M module-apps/application-phonebook/windows/PhonebookNewContact.cpp => module-apps/application-phonebook/windows/PhonebookNewContact.cpp +8 -0
@@ 84,22 84,30 @@ namespace gui
if (contact == nullptr) {
contactAction = ContactAction::Add;
contact = std::make_shared<ContactRecord>();
+ setSaveButtonVisible(false);
return true;
}
if (contact->ID == DB_ID_NONE) {
contactAction = ContactAction::Add;
+ setSaveButtonVisible(false);
}
else if (contact->contactType == ContactType::TEMPORARY) {
contactAction = ContactAction::EditTemporary;
}
else {
contactAction = ContactAction::Edit;
+ setSaveButtonVisible(true);
}
return true;
}
+ void PhonebookNewContact::setSaveButtonVisible(bool visible)
+ {
+ bottomBar->setActive(BottomBar::Side::CENTER, visible);
+ }
+
auto PhonebookNewContact::onInput(const InputEvent &inputEvent) -> bool
{
if (AppWindow::onInput(inputEvent)) {
M module-apps/application-phonebook/windows/PhonebookNewContact.hpp => module-apps/application-phonebook/windows/PhonebookNewContact.hpp +1 -0
@@ 32,6 32,7 @@ namespace gui
auto verifyAndSave() -> bool;
void showDialogDuplicatedNumber(const utils::PhoneNumber::View &duplicatedNumber);
void showDialogDuplicatedSpeedDialNumber();
+ void setSaveButtonVisible(bool visible);
std::shared_ptr<ContactRecord> contact = nullptr;
std::shared_ptr<NewContactModel> newContactModel = nullptr;
M module-apps/windows/AppWindow.cpp => module-apps/windows/AppWindow.cpp +5 -0
@@ 222,4 222,9 @@ namespace gui
this->getHeight() - this->title->offset_h() - bottomBar->getHeight()};
}
+ void AppWindow::setBottomBarActive(BottomBar::Side side, bool value)
+ {
+ bottomBar->setActive(side, value);
+ }
+
} /* namespace gui */
M module-apps/windows/AppWindow.hpp => module-apps/windows/AppWindow.hpp +2 -0
@@ 83,6 83,8 @@ namespace gui
void setBottomBarText(const UTF8 &text, BottomBar::Side side);
void clearBottomBarText(BottomBar::Side side);
bool selectSpecialCharacter();
+ void setBottomBarActive(BottomBar::Side side, bool value);
+
/// get BoundingBox size of Window "body" area
/// @note it would be much better to just have "body item" instead
/// but it would mean not insignificant refactor